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
20 changes: 13 additions & 7 deletions .github/workflows/api-spec-sync.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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. |
16 changes: 7 additions & 9 deletions scripts/sync_openapi.py
Original file line number Diff line number Diff line change
@@ -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 <new-openapi.yaml> <api-commit-sha>
Usage: sync_openapi.py <new-openapi.yaml> <source-url>
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.
Expand All @@ -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):
Expand All @@ -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())

Expand All @@ -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'
)

Expand All @@ -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")
Expand Down