From 011731958a09e0a2848045abd98160ef2034e0db Mon Sep 17 00:00:00 2001 From: Adron Hall Date: Mon, 30 Nov 2026 12:48:34 -0800 Subject: [PATCH] Fetch the API spec from its public docs site The API repository went private, so the sync's GitHub API calls with this repository's token returned 404 and every scheduled run failed. The same openapi.yaml is published at https://docs.substratalapps.com/openapi.yaml, which needs no token. SOURCE.yaml and the changelog now record that URL instead of an API commit. PyYAML is installed explicitly. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/api-spec-sync.yml | 20 +++++++++++++------- openapi/CHANGELOG.md | 2 +- scripts/sync_openapi.py | 16 +++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/api-spec-sync.yml b/.github/workflows/api-spec-sync.yml index c9f9c26..acfd986 100644 --- a/.github/workflows/api-spec-sync.yml +++ b/.github/workflows/api-spec-sync.yml @@ -1,4 +1,4 @@ -# Keeps openapi/v1/openapi.yaml in step with the Platform API. +# Keeps openapi/v1/openapi.yaml in step with the Platform API, as published on its docs site. # Runs daily, on demand, or when the API repository sends an "openapi-updated" dispatch. # If the spec changed it opens a pull request; CI on that PR runs the API coverage check, so a # removed or renamed endpoint the app uses blocks the merge until the app follows. @@ -21,21 +21,27 @@ jobs: steps: - uses: actions/checkout@v7 + - uses: actions/setup-python@v7 + with: + python-version: "3.12" + + # The API repository is private; its published docs site serves the same openapi.yaml publicly, + # so no token is needed. - name: Fetch the API's openapi.yaml id: fetch + env: + SPEC_URL: https://docs.substratalapps.com/openapi.yaml run: | - api_repo=CompositeCode/substratalapps.com - commit=$(gh api "repos/$api_repo/commits/main" --jq .sha) - gh api "repos/$api_repo/contents/docs/openapi.yaml?ref=$commit" -H "Accept: application/vnd.github.raw" > /tmp/openapi.yaml + pip install --quiet pyyaml + curl -fsSL --retry 3 "$SPEC_URL" -o /tmp/openapi.yaml if cmp -s /tmp/openapi.yaml openapi/v1/openapi.yaml; then + echo "openapi.yaml is unchanged." echo "changed=false" >> "$GITHUB_OUTPUT" exit 0 fi - python3 scripts/sync_openapi.py /tmp/openapi.yaml "$commit" > /tmp/summary.md + python3 scripts/sync_openapi.py /tmp/openapi.yaml "$SPEC_URL" > /tmp/summary.md echo "changed=true" >> "$GITHUB_OUTPUT" echo "spec_version=$(grep -m1 '^spec_version' openapi/v1/SOURCE.yaml | cut -d'"' -f2)" >> "$GITHUB_OUTPUT" - env: - GH_TOKEN: ${{ github.token }} - name: Open a pull request if: steps.fetch.outputs.changed == 'true' diff --git a/openapi/CHANGELOG.md b/openapi/CHANGELOG.md index 4fb5b1e..e70c5da 100644 --- a/openapi/CHANGELOG.md +++ b/openapi/CHANGELOG.md @@ -1,3 +1,3 @@ -| Synced | API version | Spec version | API commit | Notes | +| Synced | API version | Spec version | Source | Notes | |---|---|---|---|---| | 2026-10-23 | 1 | 1.0.0-draft.9 | [`b826f2a`](https://github.com/CompositeCode/substratalapps.com/commit/b826f2a1aaa6d58d9c16c83f4aafeb8378a29d8a) | First pin. Version moved from the URL (`/v1`) to the `Substratal-Version` header; adds `GET /users?role_id=`, `POST /users/{id}/sessions/revoke-all`, audit exports, SCIM tokens, self-service application registration, test-user expiry. 124 operations. | diff --git a/scripts/sync_openapi.py b/scripts/sync_openapi.py index 828a407..58dd71d 100755 --- a/scripts/sync_openapi.py +++ b/scripts/sync_openapi.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Updates openapi/v1/ from a freshly fetched openapi.yaml and prints a PR summary. -Usage: sync_openapi.py +Usage: sync_openapi.py Writes openapi/v1/openapi.yaml and SOURCE.yaml, and adds a row to openapi/CHANGELOG.md. If the new document serves a different API version, it stops: a new API version is a deliberate change (openapi/v2/, ApiVersioning.CURRENT, the docs nav), not an automatic one. @@ -15,7 +15,7 @@ ROOT = pathlib.Path(__file__).resolve().parents[1] TARGET = ROOT / "openapi" / "v1" -API_REPO = "CompositeCode/substratalapps.com" +API_CHANGELOG = "https://docs.substratalapps.com/changelog/" def operations(spec): @@ -33,7 +33,7 @@ def served_versions(spec): def main(): - new_path, commit = pathlib.Path(sys.argv[1]), sys.argv[2] + new_path, source_url = pathlib.Path(sys.argv[1]), sys.argv[2] old = yaml.safe_load((TARGET / "openapi.yaml").read_text()) new = yaml.safe_load(new_path.read_text()) @@ -49,9 +49,7 @@ def main(): (TARGET / "SOURCE.yaml").write_text( f'api_version: "1"\n' f'spec_version: "{new["info"]["version"]}"\n' - f"source_repo: {API_REPO}\n" - f"source_path: docs/openapi.yaml\n" - f"source_commit: {commit}\n" + f"source_url: {source_url}\n" f'synced_at: "{datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")}"\n' ) @@ -64,11 +62,11 @@ def main(): with open(ROOT / "openapi" / "CHANGELOG.md", "a") as f: f.write( f"| {today} | 1 | {new['info']['version']} | " - f"[`{commit[:7]}`](https://github.com/{API_REPO}/commit/{commit}) | {note} |\n" + f"[changelog]({API_CHANGELOG}) | {note} |\n" ) - print(f"Updates the pinned Platform API spec from `{old['info']['version']}` to `{new['info']['version']}` " - f"([{API_REPO}@{commit[:7]}](https://github.com/{API_REPO}/commit/{commit})).\n") + print(f"Updates the pinned Platform API spec from `{old['info']['version']}` to `{new['info']['version']}`, " + f"fetched from {source_url}. What changed and why: [API changelog]({API_CHANGELOG}).\n") for title, rows in (("Added", added), ("Removed", removed)): if rows: print(f"### {title}\n")