-
Notifications
You must be signed in to change notification settings - Fork 16
Automate spec drift response: open regen PR instead of issue #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
natestemen
wants to merge
5
commits into
main
Choose a base branch
from
automate-spec-drift-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
85f2f03
Automate spec drift response: open regen PR instead of issue
natestemen c9a9df5
Trigger required checks on auto-regen PRs without extra credentials
natestemen 417b6f3
Merge remote-tracking branch 'origin/main' into automate-spec-drift-pr
natestemen dbad1e0
Drop redundant set -euo pipefail from spec-drift steps
natestemen e86e9ff
Merge branch 'main' into automate-spec-drift-pr
antalszava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,25 @@ | ||
| name: Spec drift check | ||
| name: Spec drift — auto regen PR | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 9 * * 1" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
| contents: write | ||
| pull-requests: write | ||
| actions: write | ||
|
|
||
| jobs: | ||
| check: | ||
| regen: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: ./.github/actions/setup-uv | ||
| - run: uv sync --group regen | ||
| - name: Fetch latest spec | ||
| run: | | ||
| BASE_URL=$(jq -r '.servers[0].url' openapi.json) | ||
|
|
@@ -26,27 +29,60 @@ jobs: | |
| 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 | ||
| 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 | ||
| - name: Regenerate client | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After #100 the fetch + regen steps collapse into |
||
| if: steps.drift.outputs.drifted == 'true' | ||
| run: | | ||
| cp /tmp/latest-spec.json openapi.json | ||
| if [[ -f openapi-overlay.yaml ]]; then | ||
| uv run oas-patch overlay openapi.json openapi-overlay.yaml -o /tmp/patched-spec.json | ||
| else | ||
| cp openapi.json /tmp/patched-spec.json | ||
| fi | ||
| uv run openapi-python-client generate \ | ||
| --path /tmp/patched-spec.json \ | ||
| --meta none \ | ||
| --config openapi-python-client-config.yaml \ | ||
| --custom-template-path custom-templates \ | ||
| --output-path ionq_core \ | ||
| --overwrite | ||
| - name: Compose PR body | ||
| 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' | ||
| echo "The spec at \`${BASE_URL}/api-docs\` has diverged from the vendored \`openapi.json\`. This PR fetches the new spec and regenerates the client." | ||
| printf '\n<details><summary>Spec 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 | ||
| # Pushes and PR creation made with GITHUB_TOKEN never fire pull_request | ||
| # events, so the required checks are dispatched explicitly below — | ||
| # workflow_dispatch is exempt from that suppression. Team review comes | ||
| # from CODEOWNERS (GITHUB_TOKEN cannot request team reviewers itself). | ||
| - name: Open or update PR | ||
| if: steps.drift.outputs.drifted == 'true' | ||
| id: pr | ||
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 | ||
| with: | ||
| branch: spec-drift/auto-regen | ||
| base: main | ||
| add-paths: | | ||
| openapi.json | ||
| ionq_core/ | ||
| commit-message: Regenerate client for updated OpenAPI spec | ||
| title: Regenerate client for updated OpenAPI spec | ||
| body-path: /tmp/body.md | ||
| labels: spec-drift | ||
| - name: Trigger required checks | ||
| if: steps.pr.outputs.pull-request-operation == 'created' || steps.pr.outputs.pull-request-operation == 'updated' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| # CodeQL runs via GitHub's default setup and has no dispatchable | ||
| # workflow file — confirm it reports on regen PRs. | ||
| gh workflow run ci.yml --ref spec-drift/auto-regen | ||
| gh workflow run generated.yml --ref spec-drift/auto-regen | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#96 pins this as
SPEC_URLinstead of deriving it (an upstreamservers[0]change would silently repoint the check) - worth matching.