diff --git a/.github/auto-publish-template.yml b/.github/auto-publish-template.yml new file mode 100644 index 00000000000..2f31ebe060a --- /dev/null +++ b/.github/auto-publish-template.yml @@ -0,0 +1,36 @@ +###################################################################### +# This is the template used to generate auto-publication workflows for +# the different documents in the repository. Check generate script for +# details. Edit this file and run the script again to update the +# workflows. +###################################################################### + +name: Publish {{shortname}} on /TR + +on: + pull_request: + paths: + - "{{shortname}}/**" + push: + branches: [main] + paths: + - "{{shortname}}/**" + workflow_dispatch: + +jobs: + publish-TR-{{shortname}}: + name: Publish {{shortname}} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: w3c/spec-prod@v2 + with: + TOOLCHAIN: bikeshed + SOURCE: {{shortname}}/Overview.bs + DESTINATION: {{shortname}}/index.html + BUILD_FAIL_ON: warning + VALIDATE_MARKUP: false + W3C_ECHIDNA_TOKEN: ${{ secrets.{{tokenName}} }} + W3C_WG_DECISION_URL: https://www.w3.org/2025/08/21-css-minutes.html#fc30 + W3C_BUILD_OVERRIDE: | + status: {{publicationStatus}} diff --git a/.github/generate-auto-publish-workflows.py b/.github/generate-auto-publish-workflows.py new file mode 100644 index 00000000000..f02072760df --- /dev/null +++ b/.github/generate-auto-publish-workflows.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 +""" +Script to generate auto publication workflows for given specs +""" + +import re +from pathlib import Path + +# ----------------------------------------------------------------------------- +# List of properties that can appear to describe a spec. +# ----------------------------------------------------------------------------- + +PROPERTIES = [ + "shortname", + "publicationStatus", + "tokenName", +] + +# ----------------------------------------------------------------------------- +# List of specs for which an auto-publish script needs to be created. +# ----------------------------------------------------------------------------- + +SPECS = [ + { + "shortname": "css-color-4", + "publicationStatus": "CRD", + }, + { + "shortname": "css-color-5", + "publicationStatus": "WD", + }, + { + "shortname": "css-fonts-5", + "publicationStatus": "WD", + }, +] + +# ----------------------------------------------------------------------------- +# Main +# ----------------------------------------------------------------------------- + +def main(): + script_path = Path(__file__).parent + template_path = script_path / "auto-publish-template.yml" + workflows_dir = script_path / "workflows" + + workflows_dir.mkdir(parents=True, exist_ok=True) + + template = template_path.read_text(encoding="utf-8") + + # Replace the large comment header block (#####...#####) + template = re.sub( + r"#{5,}.*?#{5,}", + """###################################################################### +# IMPORTANT: Do not edit this file directly! +# +# This workflow was automatically generated through the +# generate-auto-publish-workflows.py script. To update the workflow, +# make changes to the template file and run the script again. +######################################################################""", + template, + flags=re.S, + ) + + for spec in SPECS: + spec = spec.copy() + + # Derive shortname from source if not provided + if "shortname" not in spec or not spec["shortname"]: + spec["shortname"] = spec["source"].split(".")[0].replace("_", "-") + + # Derive tokenName if not provided + if "tokenName" not in spec or not spec["tokenName"]: + token = ( + spec["shortname"] + .upper() + .replace("-", "_") + ) + spec["tokenName"] = f"TR_TOKEN_{token}" + + # Apply template substitutions + content = template + for prop in PROPERTIES: + value = spec.get(prop, "") + content = content.replace(f"{{{{{prop}}}}}", value) + + # Write workflow file + filename = workflows_dir / f"{spec['shortname']}.yml" + filename.write_text(content, encoding="utf-8") + print(f"Generated {filename}") + + +if __name__ == "__main__": + main()