This repository has been archived by the owner on Aug 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Make release script #422
Merged
Merged
Make release script #422
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#!/usr/bin/env python | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# 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/. | ||
|
||
from urllib.parse import urlencode | ||
|
||
import requests | ||
|
||
|
||
OWNER = 'mozilla-services' | ||
REPO = 'buildhub' | ||
|
||
VALID_ENVIRONMENTS = ('stage', 'prod') | ||
VALID_TASKS = ('cron', 'lambda', 'both') | ||
|
||
QA_CONTACT = '[email protected]' | ||
|
||
|
||
def main( | ||
environment, | ||
task, | ||
tag=None, | ||
dry_run=False, | ||
): | ||
api_url = f'https://api.github.com/repos/{OWNER}/{REPO}/releases' | ||
if not tag: | ||
api_url += '/latest' | ||
else: | ||
api_url += f'/tags/{tag}' | ||
response = requests.get(api_url) | ||
response.raise_for_status() | ||
release_info = response.json() | ||
|
||
# Prepare some variables for the string templates | ||
release_url = release_info['html_url'] | ||
lambda_asset_url = None | ||
for asset in release_info['assets']: | ||
lambda_asset_url = asset['browser_download_url'] | ||
env = environment.title() | ||
release_tag_name = release_info['tag_name'] | ||
|
||
if task == 'lambda': | ||
summary = f"On {env}, please deploy Buildhub Lambda function {release_tag_name}" # noqa | ||
comment = f""" | ||
Could you please update the Lambda function for Buildhub {env} with the following one? | ||
|
||
{release_url} | ||
|
||
{lambda_asset_url} | ||
|
||
Thanks! | ||
""" # noqa | ||
elif task == 'cron': | ||
summary = f"On {env}, please deploy Buildhub Cron function {release_tag_name}" # noqa | ||
comment = f""" | ||
Could you please update the Cron function for Buildhub {env} with the following one? | ||
|
||
{release_url} | ||
|
||
Thanks! | ||
""" # noqa | ||
else: | ||
summary = f"On {env}, please deploy Buildhub Cron and Lambda function {release_tag_name}" # noqa | ||
comment = f""" | ||
Could you please update the Cron *and* Lambda function for Buildhub {env} with the following one? | ||
|
||
{release_url} | ||
|
||
{lambda_asset_url} | ||
|
||
Thanks! | ||
""" # noqa | ||
|
||
comment = '\n'.join(x.strip() for x in comment.strip().splitlines()) | ||
params = { | ||
'qa_contact': QA_CONTACT, | ||
'comment': comment, | ||
'short_desc': summary, | ||
'component': 'Operations: Storage', | ||
'product': 'Cloud Services', | ||
'bug_file_loc': release_url, | ||
} | ||
URL = 'https://bugzilla.mozilla.org/enter_bug.cgi?' + urlencode(params) | ||
print('To file this bug, click (or copy) this URL:') | ||
print('👇') | ||
print(URL) | ||
print('👆') | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
import argparse | ||
|
||
def check_environment(value): | ||
value = value.strip() | ||
if value not in VALID_ENVIRONMENTS: | ||
raise argparse.ArgumentTypeError( | ||
f'{value!r} not in {VALID_ENVIRONMENTS}' | ||
) | ||
return value | ||
|
||
def check_task(value): | ||
value = value.strip() | ||
if value not in VALID_TASKS: | ||
raise argparse.ArgumentTypeError( | ||
f'{value!r} not in {VALID_TASKS}' | ||
) | ||
return value | ||
|
||
parser = argparse.ArgumentParser( | ||
description='Deploy Buildhub (by filing Bugzilla bugs)!' | ||
) | ||
parser.add_argument( | ||
'-t', '--tag', type=str, | ||
help=( | ||
f'Name of the release (e.g. "v1.2.0"). If ommitted will be looked ' | ||
f'on GitHub at https://github.com/{OWNER}/{REPO}/releases' | ||
) | ||
) | ||
|
||
parser.add_argument( | ||
'environment', help='stage or prod', type=check_environment | ||
) | ||
parser.add_argument( | ||
'task', help='cron or lambda or both', type=check_task, | ||
) | ||
parser.add_argument('-d', '--dry-run', action='store_true') | ||
args = parser.parse_args() | ||
args = vars(args) | ||
main(args.pop('environment'), args.pop('task'), **args) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍