grasp/build

75 lines
2.1 KiB
Python
Executable file

#!/usr/bin/env python3
import argparse
import os
from subprocess import check_call
from pathlib import Path
# TODO FIXME copypaste from promnesia
# TODO FIXME use it in ci script
TARGETS = ['chrome', 'firefox']
def main():
p = argparse.ArgumentParser()
p.add_argument('--release', action='store_true')
p.add_argument('--sign', action='store_true')
p.add_argument('--lint', action='store_true')
tg = p.add_mutually_exclusive_group(required=True)
tg.add_argument('--target', type=str, choices=TARGETS)
for b in TARGETS:
tg.add_argument('--' + b, action='store_const', const=b, dest='target')
args = p.parse_args()
target = args.target
assert target is not None
dist_dir = Path(__file__).absolute().parent / 'dist'
def webext(*args, **kwargs):
src_dir = dist_dir # / target
src_dir = src_dir.resolve() # TODO ugh. webext can't into symlinks???
check_call([
'web-ext',
'--source-dir', str(src_dir),
*args,
], **kwargs)
env = {
'TARGET': target,
'RELEASE': 'YES' if args.release else 'NO',
**os.environ,
}
check_call([
'npm', 'run', 'build',
], env=env, cwd=str(Path(__file__).absolute().parent))
if args.lint:
# TODO --self-hosted
# TODO warnings as errors??
webext('lint')
if args.release:
assert args.lint # TODO not sure..
if args.sign:
assert args.release
if target not in ['firefox', 'firefox-mobile']:
raise RuntimeError("{target} is not supported for signing yet".format(target=target))
dist_dir = Path(__file__).absolute().parent / 'dist'
src_dir = dist_dir / target
from firefox_dev_secrets import API_KEY, API_SECRET
webext(
'--source-dir' , str(src_dir),
'--artifacts-dir', str(dist_dir),
'--api-key' , API_KEY,
'--api-secret', API_SECRET,
'sign',
)
if __name__ == '__main__':
main()
# TODO use UUID? https://addons.mozilla.org/en-GB/developers/addon/grasp/edit
# TODO right, wouldn't work because it's listed..