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.

61 lines
2.2 KiB

  1. #!/usr/bin/env python
  2. # Create a draft release on GitHub. By default in the tendermint/tendermint repo.
  3. # Optimized for CircleCI
  4. import argparse
  5. import httplib
  6. import json
  7. import os
  8. from base64 import b64encode
  9. def request(org, repo, 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'.format(org,repo), data, headers)
  18. response = conn.getresponse()
  19. if response.status < 200 or response.status > 299:
  20. print("{0}: {1}".format(response.status, response.reason))
  21. conn.close()
  22. raise IOError(response.reason)
  23. responsedata = response.read()
  24. conn.close()
  25. return json.loads(responsedata)
  26. def create_draft(org,repo,branch,version):
  27. draft = {
  28. 'tag_name': version,
  29. 'target_commitish': '{0}'.format(branch),
  30. 'name': '{0} (WARNING: ALPHA SOFTWARE)'.format(version),
  31. 'body': '<a href=https://github.com/{0}/{1}/blob/{2}/CHANGELOG.md#{3}>https://github.com/{0}/{1}/blob/{2}/CHANGELOG.md#{3}</a>'.format(org,repo,branch,version.replace('.','')),
  32. 'draft': True,
  33. 'prerelease': False
  34. }
  35. data=json.dumps(draft)
  36. return request(org, repo, data)
  37. if __name__ == "__main__":
  38. parser = argparse.ArgumentParser()
  39. parser.add_argument("--org", default="tendermint", help="GitHub organization")
  40. parser.add_argument("--repo", default="tendermint", help="GitHub repository")
  41. parser.add_argument("--branch", default=os.environ.get('CIRCLE_BRANCH'), help="Branch to build from, e.g.: v1.0")
  42. parser.add_argument("--version", default=os.environ.get('CIRCLE_TAG'), help="Version number for binary, e.g.: v1.0.0")
  43. args = parser.parse_args()
  44. if not os.environ.has_key('GITHUB_USERNAME'):
  45. raise parser.error('environment variable GITHUB_USERNAME is required')
  46. if not os.environ.has_key('GITHUB_TOKEN'):
  47. raise parser.error('environment variable GITHUB_TOKEN is required')
  48. release = create_draft(args.org,args.repo,args.branch,args.version)
  49. print(release["id"])