Spec drift check #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Spec drift check | |
| on: | |
| schedule: | |
| - cron: "0 9 * * 1" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 | |
| with: | |
| persist-credentials: false | |
| - name: Fetch latest spec | |
| 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: | | |
| norm() { jq -S 'del(.info.description)' "$1"; } | |
| if ! diff -u --label vendored --label upstream <(norm openapi.json) <(norm /tmp/latest-spec.json) > /tmp/spec.diff; then | |
| echo "drifted=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Open or update issue | |
| if: steps.drift.outputs.drifted == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| { | |
| 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-file /tmp/body.md \ | |
| --label spec-drift | |
| else | |
| gh issue edit "$existing" --body-file /tmp/body.md | |
| fi |