From 25381fe59d261296d6ebf4f2728641cd86b7a79e Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 8 Sep 2021 08:41:08 +0200 Subject: [PATCH] Handle Web IDL This also makes factory.py more useful for a single standard. See https://github.com/heycam/webidl/pull/1018 for context. --- .github/workflows/build.yml.template | 2 +- factory.json | 5 ++ factory.py | 87 +++++++++++++++++++++------- 3 files changed, 72 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml.template b/.github/workflows/build.yml.template index 29d0c65..260c59a 100644 --- a/.github/workflows/build.yml.template +++ b/.github/workflows/build.yml.template @@ -17,7 +17,7 @@ jobs: # Note: `python` will also be this version, which various scripts depend on. - uses: actions/setup-python@v2 with: - python-version: 3.8 + python-version: 3.8@@build_with_node@@ # Note: `make deploy` will do a deploy dry run on PRs. - run: make deploy env: diff --git a/factory.json b/factory.json index 6a64f8b..ff521f5 100644 --- a/factory.json +++ b/factory.json @@ -21,5 +21,10 @@ "streams": { "extra_files": "demos/* demos/**/*", "not_these_templates": [".editorconfig"] + }, + "webidl": { + ".gitignore": ["/node_modules/"], + "build_with_node": true, + "post_build_step": "node ./check-grammar.js \"$$DIR/index.html\" && npm run pp-webidl -- --input \"$$DIR/index.html\"" } } diff --git a/factory.py b/factory.py index f806d66..1d33dbe 100755 --- a/factory.py +++ b/factory.py @@ -1,8 +1,11 @@ #!/usr/bin/env python -import os, subprocess, uuid, json, requests +import argparse, os, subprocess, uuid, json, requests OBSOLETE_FILES = [".travis.yml", "deploy_key.enc"] +TEMPLATES = {} +DB = json.loads(requests.get("https://github.com/whatwg/sg/raw/main/db.json").text) +FACTORY_DB = {} def read_file(file): return open(file, "r", encoding="utf-8").read() @@ -48,6 +51,15 @@ def fill_template(contents, variables): continue elif variable == "extra_files" and data != "": data = "\n\tEXTRA_FILES=\"{}\" \\".format(data) + elif variable == "build_with_node": + output = "" + if data: + output = """ + - uses: actions/setup-node@v2 + with: + node-version: 14 + - run: npm install""" + data = output elif variable == "post_build_step" and data != "": data = "\n\tPOST_BUILD_STEP='{}' \\".format(data) elif variable == ".gitignore": @@ -59,8 +71,21 @@ def fill_template(contents, variables): return contents -def update(templates, variables): - os.chdir("../{}".format(variables["shortname"])) +def update_files(shortname, name): + os.chdir("../{}".format(shortname)) + + variables = { + "shortname": shortname, + "h1": name, + "extra_files": "", + "post_build_step": "", + ".gitignore": [], + "only_these_templates": None, + "not_these_templates": None + } + if shortname in FACTORY_DB: + variables.update(FACTORY_DB[shortname]) + # HTML does not use Bikeshed (yet). We do want some output for comparison purposes if variables["shortname"] != "html": @@ -68,7 +93,7 @@ def update(templates, variables): bs = bs_file[:-len(".bs")] variables["bs"] = bs - files = fill_templates(templates, variables) + files = fill_templates(TEMPLATES, variables) subprocess.run(["git", "checkout", "main"], capture_output=True) subprocess.run(["git", "pull"], capture_output=True) @@ -82,6 +107,12 @@ def update(templates, variables): if os.path.isfile(file): os.remove(file) + os.chdir(".") + + +def create_pr(shortname): + os.chdir("../{}".format(shortname)) + subprocess.run(["git", "add", "-A"], capture_output=True) if b"Changes to be committed" in subprocess.run(["git", "status"], capture_output=True).stdout: branch = "meta-template/{}".format(uuid.uuid1()) @@ -89,27 +120,41 @@ def update(templates, variables): subprocess.run(["git", "commit", "-m", "Meta: update repository files\n\nSee https://github.com/whatwg/spec-factory for details."], capture_output=True) subprocess.run(["git", "push", "-u", "origin", branch], capture_output=True) subprocess.run(["gh", "pr", "create", "-f"]) + os.chdir(".") -def main(): - templates = gather_templates() - db = json.loads(requests.get("https://github.com/whatwg/sg/raw/main/db.json").text) - local_db = json.loads(read_file("factory.json")) - for workstream in db["workstreams"]: +def update_all_standards(create_pr = False): + for workstream in DB["workstreams"]: for standard in workstream["standards"]: shortname = href_to_shortname(standard["href"]) - variables = { - "shortname": shortname, - "h1": standard["name"], - "extra_files": "", - "post_build_step": "", - ".gitignore": [], - "only_these_templates": None, - "not_these_templates": None - } - if shortname in local_db: - variables.update(local_db[shortname]) - update(templates, variables) + + update_files(shortname, standard["name"]) + + if create_pr: + create_pr(shortname) + + +def main(): + global TEMPLATES, FACTORY_DB + + TEMPLATES = gather_templates() + FACTORY_DB = json.loads(read_file("factory.json")) + + parser = argparse.ArgumentParser() + parser.add_argument("--single", nargs=2, type=str) + parser.add_argument("--all", action="store_true") + parser.add_argument("--create-prs", action="store_true") + args = parser.parse_args() + + if args.single: + update_files(args.single[0], args.single[1]) + elif args.all: + update_all_standards(args.create_prs) + else: + print("Please invoke as one of:\n\n" + \ + "./factory.py --single \n" + \ + "./factory.py --all" + \ + "./factory.py --all --create-prs") main()