Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ionq_core/api/** linguist-generated=true
ionq_core/models/** linguist-generated=true

# Vendored upstream OpenAPI spec.
openapi.json linguist-vendored=true
openapi.json linguist-vendored=true linguist-generated=true

# Lockfile.
uv.lock linguist-generated=true
24 changes: 18 additions & 6 deletions .github/workflows/spec-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,34 @@ jobs:
with:
persist-credentials: false
- name: Fetch latest spec
run: curl -sf https://api.ionq.co/v0.4/api-docs -o /tmp/latest-spec.json
run: |
BASE_URL=$(jq -r '.servers[0].url' openapi.json)
echo "BASE_URL=${BASE_URL}" >> "$GITHUB_ENV"
curl -sf "${BASE_URL}/api-docs" -o /tmp/latest-spec.json
- name: Check for drift
id: drift
run: |
if ! diff -q <(python3 -m json.tool openapi.json) <(python3 -m json.tool /tmp/latest-spec.json) > /dev/null 2>&1; then
if ! diff -u --label vendored --label upstream <(python3 -m json.tool --sort-keys openapi.json) <(python3 -m json.tool --sort-keys /tmp/latest-spec.json) > /tmp/spec.diff; then
echo "drifted=true" >> "$GITHUB_OUTPUT"
fi
- name: Open issue
- name: Open or update issue
if: steps.drift.outputs.drifted == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
existing=$(gh issue list --label spec-drift --state open --json number --jq length)
if [[ "$existing" == "0" ]]; then
{
echo "The spec at ${BASE_URL}/api-docs has diverged from the vendored openapi.json. Fetch the new spec and regenerate the client."
printf '\n<details><summary>Diff (sorted, pretty-printed JSON)</summary>\n\n```diff\n'
head -c 60000 /tmp/spec.diff
[[ $(wc -c < /tmp/spec.diff) -gt 60000 ]] && printf '\n... (truncated)\n'
printf '```\n</details>\n'
} > /tmp/body.md
existing=$(gh issue list --label spec-drift --state open --json number --jq '.[0].number // empty')
if [[ -z "$existing" ]]; then
gh issue create \
--title "OpenAPI spec has changed upstream" \
--body "The spec at api.ionq.co/v0.4/api-docs has diverged from the vendored openapi.json. Fetch the new spec and regenerate the client." \
--body-file /tmp/body.md \
--label spec-drift
else
gh issue edit "$existing" --body-file /tmp/body.md
fi
2 changes: 1 addition & 1 deletion openapi.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions tests/test_docs_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,16 @@ def test_oas_patch_versions_match():


def test_spec_path_matches_default_base_url():
# Without this, a DEFAULT_BASE_URL bump leaves spec-drift.yml curling the stale endpoint.
# Without this, a DEFAULT_BASE_URL bump leaves CONTRIBUTING.md pointing at a stale endpoint.
spec_path = f"{urlparse(DEFAULT_BASE_URL).path}/api-docs"
assert spec_path in CONTRIB
assert spec_path in SPEC_DRIFT_WF


def test_spec_servers_path_in_docs():
# Catches a stale openapi.json: code/docs bumped without regen, or fetched from the wrong version.
spec = json.loads((ROOT / "openapi.json").read_text())
spec_path = urlparse(spec["servers"][0]["url"]).path
assert f"{spec_path}/api-docs" in CONTRIB
assert f"{spec_path}/api-docs" in SPEC_DRIFT_WF


def test_single_spdx_year_across_package():
Expand Down