diff --git a/.github/workflows/update-quick-start-module.yml b/.github/workflows/update-quick-start-module.yml index 08d14037f465..0271b839f730 100644 --- a/.github/workflows/update-quick-start-module.yml +++ b/.github/workflows/update-quick-start-module.yml @@ -119,14 +119,32 @@ jobs: environment: pytorchbot-env steps: - name: Checkout pytorch.github.io - uses: actions/checkout@v2 + uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 with: python-version: 3.9 architecture: x64 - - name: Generate quick-start-additional-platforms.js + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install markdown pygments + - name: Generate additional-platforms assets shell: bash run: | set -ex python3 ./scripts/gen_additional_platforms.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7 + with: + token: ${{ secrets.PYTORCHBOT_TOKEN }} + commit-message: Regenerate additional-platforms assets + title: '[Additional Platforms] Regenerate quick-start-additional-platforms.js and additional-platforms.json' + body: > + This PR is auto-generated. It regenerates the third-party vendor + accelerator picker assets after a change to _additional_platforms/*.json + or _get_started/additional_platforms/*.md. + labels: automated pr + add-paths: | + assets/quick-start-additional-platforms.js + assets/additional-platforms.json diff --git a/scripts/gen_additional_platforms.py b/scripts/gen_additional_platforms.py index 8fffa1980674..9c0dc4cb4635 100644 --- a/scripts/gen_additional_platforms.py +++ b/scripts/gen_additional_platforms.py @@ -19,12 +19,15 @@ 5. Output the result to assets/quick-start-additional-platforms.js """ +import datetime import json +import os +import re from pathlib import Path from typing import Dict, Any, Set, List + import markdown from markdown.extensions.codehilite import CodeHiliteExtension -import re BASE_DIR = Path(__file__).parent.parent ADDITIONAL_PLATFORM_DIR = BASE_DIR / "_additional_platforms" @@ -32,6 +35,12 @@ INCLUDES_DIR = BASE_DIR / "_includes" ASSETS_DIR = BASE_DIR / "assets" +# External consumer JSON bundle +# Bump SCHEMA_VERSION on any breaking change +# to the `platforms` / `html` shape. +SCHEMA_VERSION = 1 +JSON_OUT_PATH = "additional-platforms.json" + # Schema definitions derived from additional_platforms.md REQUIRED_TOP_LEVEL_FIELDS: Set[str] = {"name", "support_channel", "stable"} ALLOWED_TOP_LEVEL_FIELDS: Set[str] = {"name", "support_channel", "stable", "preview"} @@ -231,6 +240,22 @@ def write_output(content: str) -> None: print(f"Generated: {output_path}") +def write_platforms_json(platforms: dict, html: dict, out_path: str) -> None: + """ + Write JSON bundle for external consumers. + """ + payload = { + "schema_version": SCHEMA_VERSION, + "generated_at": datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds"), + "generator_commit": os.environ.get("GITHUB_SHA", "")[:7], + "platforms": platforms, + "html": html, + } + with open(out_path, "w", encoding="utf-8") as f: + json.dump(payload, f, indent=2, ensure_ascii=False, sort_keys=False) + print(f"Wrote {out_path}") + + def main(): """Main entry point.""" @@ -254,6 +279,9 @@ def main(): # Write to assets directory write_output(js_content) + # Also write the JSON file for the external consumer + write_platforms_json(platform_data, markdown_content, str(BASE_DIR / JSON_OUT_PATH)) + if __name__ == "__main__": main()