Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions .github/workflows/update-quick-start-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this new that we're opening PRs here? Why and How?

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
30 changes: 29 additions & 1 deletion scripts/gen_additional_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,28 @@
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"
MARKDOWN_DIR = BASE_DIR / "_get_started" / "additional_platforms"
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"}
Expand Down Expand Up @@ -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."""

Expand All @@ -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))
Comment thread
marco-s marked this conversation as resolved.


if __name__ == "__main__":
main()