From 820ec69916c16056c047b5b6cbc5f1954c677f1b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 30 Apr 2018 13:14:03 -0400 Subject: [PATCH] fix load/store of publishing auth secrets for reuse --- dist/chromium/publish-beta.py | 45 ++++++++++++++++------------- dist/firefox/publish-signed-beta.py | 44 +++++++++++++++------------- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/dist/chromium/publish-beta.py b/dist/chromium/publish-beta.py index 8c0ddd782..3f90c524c 100755 --- a/dist/chromium/publish-beta.py +++ b/dist/chromium/publish-beta.py @@ -22,26 +22,6 @@ from string import Template # - Upload uBlock0.chromium.zip to Chrome store # - Publish uBlock0.chromium.zip to Chrome store -# Load/save auth secrets -ubo_secrets = dict() -if 'UBO_SECRETS' in os.environ: - ubo_secrets = json.loads(os.environ['UBO_SECRETS']) - -def input_secret(prompt, token): - if token in ubo_secrets: - prompt += ' ✔' - prompt += ': ' - value = input(prompt).strip() - if len(value) == 0: - if token not in ubo_secrets: - print('Token error:', token) - exit(1) - value = ubo_secrets[token] - elif token not in ubo_secrets or value != ubo_secrets[token]: - ubo_secrets[token] = value - os.environ['UBO_SECRETS'] = json.dumps(ubo_secrets, indent=None, separators=(',',':')) - return value - # Find path to project root projdir = os.path.split(os.path.abspath(__file__))[0] while not os.path.isdir(os.path.join(projdir, '.git')): @@ -64,6 +44,31 @@ if not re.search('^\d+\.\d+\.\d+(b|rc)\d+$', version): print('Error: Invalid version string.') exit(1) +# Load/save auth secrets +# The build directory is excluded from git +ubo_secrets = dict() +ubo_secrets_filename = os.path.join(projdir, 'dist', 'build', 'ubo_secrets') +if os.path.isfile(ubo_secrets_filename): + with open(ubo_secrets_filename) as f: + ubo_secrets = json.load(f) + +def input_secret(prompt, token): + if token in ubo_secrets: + prompt += ' ✔' + prompt += ': ' + value = input(prompt).strip() + if len(value) == 0: + if token not in ubo_secrets: + print('Token error:', token) + exit(1) + value = ubo_secrets[token] + elif token not in ubo_secrets or value != ubo_secrets[token]: + ubo_secrets[token] = value + with open(ubo_secrets_filename, 'w') as f: + json.dump(ubo_secrets, f, indent=2) + return value + + # GitHub API token github_token = input_secret('Github token', 'github_token') github_auth = 'token ' + github_token diff --git a/dist/firefox/publish-signed-beta.py b/dist/firefox/publish-signed-beta.py index ce5e88b0f..301652fe9 100755 --- a/dist/firefox/publish-signed-beta.py +++ b/dist/firefox/publish-signed-beta.py @@ -16,26 +16,6 @@ import zipfile from distutils.version import LooseVersion from string import Template -# Load/save auth secrets -ubo_secrets = dict() -if 'UBO_SECRETS' in os.environ: - ubo_secrets = json.loads(os.environ['UBO_SECRETS']) - -def input_secret(prompt, token): - if token in ubo_secrets: - prompt += ' ✔' - prompt += ': ' - value = input(prompt).strip() - if len(value) == 0: - if token not in ubo_secrets: - print('Token error:', token) - exit(1) - value = ubo_secrets[token] - elif token not in ubo_secrets or value != ubo_secrets[token]: - ubo_secrets[token] = value - os.environ['UBO_SECRETS'] = json.dumps(ubo_secrets, indent=None, separators=(',',':')) - return value - # - Download target (raw) uBlock0.firefox.xpi from GitHub # - This is referred to as "raw" package # - This will fail if not a dev build @@ -82,6 +62,30 @@ if not re.search('^\d+\.\d+\.\d+(b|rc)\d+$', version): print('Error: Invalid version string.') exit(1) +# Load/save auth secrets +# The build directory is excluded from git +ubo_secrets = dict() +ubo_secrets_filename = os.path.join(projdir, 'dist', 'build', 'ubo_secrets') +if os.path.isfile(ubo_secrets_filename): + with open(ubo_secrets_filename) as f: + ubo_secrets = json.load(f) + +def input_secret(prompt, token): + if token in ubo_secrets: + prompt += ' ✔' + prompt += ': ' + value = input(prompt).strip() + if len(value) == 0: + if token not in ubo_secrets: + print('Token error:', token) + exit(1) + value = ubo_secrets[token] + elif token not in ubo_secrets or value != ubo_secrets[token]: + ubo_secrets[token] = value + with open(ubo_secrets_filename, 'w') as f: + json.dump(ubo_secrets, f, indent=2) + return value + # GitHub API token github_token = input_secret('Github token', 'github_token') github_auth = 'token ' + github_token