From 47ad8f212eedc1b2adf76da56ba1d7f4142449b8 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 7 Jul 2017 14:28:36 +0200 Subject: build_release: Fail GitHub uploads early --- scripts/dev/build_release.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py index e6a4f89e1..6a6adb5bd 100755 --- a/scripts/dev/build_release.py +++ b/scripts/dev/build_release.py @@ -292,6 +292,13 @@ def build_sdist(): return artifacts +def read_github_token(): + """Read the GitHub API token from disk.""" + token_file = os.path.join(os.path.expanduser('~'), '.gh_token') + with open(token_file, encoding='ascii') as f: + token = f.read().strip() + + def github_upload(artifacts, tag): """Upload the given artifacts to GitHub. @@ -302,9 +309,7 @@ def github_upload(artifacts, tag): import github3 utils.print_title("Uploading to github...") - token_file = os.path.join(os.path.expanduser('~'), '.gh_token') - with open(token_file, encoding='ascii') as f: - token = f.read().strip() + token = read_github_token() gh = github3.login(token=token) repo = gh.repository('qutebrowser', 'qutebrowser') @@ -341,6 +346,12 @@ def main(): upload_to_pypi = False + if args.upload is not None: + # Fail early when trying to upload without github3 installed + # or without API token + import github3 + read_github_token() + if os.name == 'nt': if sys.maxsize > 2**32: # WORKAROUND -- cgit v1.2.3-54-g00ecf