You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

  1. #!/usr/bin/env python
  2. # Publish an existing GitHub draft release. --id required.
  3. # Optimized for CircleCI
  4. import json
  5. import os
  6. import argparse
  7. import httplib
  8. from base64 import b64encode
  9. def request(org, repo, id, data):
  10. user_and_pass = b64encode(b"{0}:{1}".format(os.environ['GITHUB_USERNAME'], os.environ['GITHUB_TOKEN'])).decode("ascii")
  11. headers = {
  12. 'User-Agent': 'tenderbot',
  13. 'Accept': 'application/vnd.github.v3+json',
  14. 'Authorization': 'Basic %s' % user_and_pass
  15. }
  16. conn = httplib.HTTPSConnection('api.github.com', timeout=5)
  17. conn.request('POST', '/repos/{0}/{1}/releases/{2}'.format(org,repo,id), data, headers)
  18. response = conn.getresponse()
  19. if response.status < 200 or response.status > 299:
  20. print(response)
  21. conn.close()
  22. raise IOError(response.reason)
  23. responsedata = response.read()
  24. conn.close()
  25. return json.loads(responsedata)
  26. if __name__ == "__main__":
  27. parser = argparse.ArgumentParser()
  28. parser.add_argument("--org", default="tendermint", help="GitHub organization")
  29. parser.add_argument("--repo", default="tendermint", help="GitHub repository")
  30. parser.add_argument("--id", help="GitHub release ID", required=True, type=int)
  31. parser.add_argument("--version", default=os.environ.get('CIRCLE_TAG'), help="Version number for the release, e.g.: v1.0.0")
  32. args = parser.parse_args()
  33. if not os.environ.has_key('GITHUB_USERNAME'):
  34. raise parser.error('GITHUB_USERNAME not set.')
  35. if not os.environ.has_key('GITHUB_TOKEN'):
  36. raise parser.error('GITHUB_TOKEN not set.')
  37. try:
  38. result = request(args.org, args.repo, args.id, data=json.dumps({'draft':False,'tag_name':"{0}".format(args.version)}))
  39. except IOError as e:
  40. print(e)
  41. result = request(args.org, args.repo, args.id, data=json.dumps({'draft':False,'tag_name':"{0}-autorelease".format(args.version)}))
  42. print(result['name'])