Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update publish_release.py script for CI #1374

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions script/publish_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import argparse
import json
import logging
import os
import sys
from lib.github import GitHub
Expand All @@ -16,28 +18,25 @@
from lib.helpers import *
import requests


RELEASE_NAME = 'Dev Channel Beta'
from argparse import RawTextHelpFormatter


def main():

args = parse_args()

if args.debug:
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
logging.debug('prerelease: {}'.format(args.prerelease))

repo = GitHub(get_env_var('GITHUB_TOKEN')).repos(BRAVE_REPO)

release = get_draft(repo, get_brave_version())
commit_tag = get_commit_tag(get_raw_version())

print("[INFO] Releasing {}".format(release['tag_name']))
publish_release(repo, release['id'], get_tag(), commit_tag)
tag_name = release['tag_name']


def get_commit_tag(version):
parts = get_raw_version().split('.', 3)
if (len(parts) == 3):
parts[2] = 'x'
return '.'.join(parts)
else:
raise(UserWarning("[ERROR] Invalid version name '%s'",
get_raw_version()))
logging.info("Releasing {}".format(tag_name))
publish_release(repo, release['id'], tag_name, args.prerelease, logging)


def get_draft(repo, tag):
Expand All @@ -52,20 +51,30 @@ def get_draft(repo, tag):
return releases[0]


def publish_release(repo, release_id, tag, commit_tag):
data = dict(draft=False, prerelease=True, tag_name=tag,
target_commitish=commit_tag)
def publish_release(repo, release_id, tag, prerelease, logging):
data = dict(prerelease=prerelease, draft=False, tag_name=tag)

try:
repo.releases(release_id).patch(data=data)
except Exception as e:
if any([err.get("field") == "tag_name" for
err in json.loads(e.message)['errors']]):
print("[ERROR] Please make sure tag_name exists and is pushed "
"to github")
logging.error("[ERROR] Please make sure tag_name exists and is pushed "
"to github")
raise


def parse_args():
desc = "Publish GitHub draft release"
parser = argparse.ArgumentParser(
description=desc, formatter_class=RawTextHelpFormatter)
parser.add_argument('-d', '--debug', action='store_true',
help='Print debug statements')
parser.add_argument('-p', '--prerelease', help='Publish the release as a `prerelease` '
'(Default: False)', action='store_true')
return parser.parse_args()


if __name__ == '__main__':
import sys
sys.exit(main())