Skip to content

Commit

Permalink
Handle Web IDL
Browse files Browse the repository at this point in the history
This also makes factory.py more useful for a single standard.

See whatwg/webidl#1018 for context.
  • Loading branch information
annevk authored Sep 8, 2021
1 parent e0cc7d9 commit 25381fe
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions factory.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
}
}
87 changes: 66 additions & 21 deletions factory.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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":
Expand All @@ -59,16 +71,29 @@ 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":
[bs_file] = find_files_with_extension(".bs", recurse=False)
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)
Expand All @@ -82,34 +107,54 @@ 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())
subprocess.run(["git", "checkout", "-b", branch], capture_output=True)
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 <shortname> <name>\n" + \
"./factory.py --all" + \
"./factory.py --all --create-prs")

main()

0 comments on commit 25381fe

Please sign in to comment.