-
Notifications
You must be signed in to change notification settings - Fork 17
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
1
commit 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,85 @@ | ||
| 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 | ||
|
|
||
| jobs: | ||
| check: | ||
| regen: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | ||
| with: | ||
| persist-credentials: false | ||
| # persist-credentials required to push the regen branch | ||
| - uses: ./.github/actions/setup-uv | ||
| - run: uv sync --group regen | ||
| - name: Fetch latest spec | ||
| run: | | ||
| set -euo pipefail | ||
|
Contributor
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. Why was this needed? |
||
| 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 | ||
| 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 | ||
| if: steps.drift.outputs.drifted == 'true' | ||
| run: | | ||
| set -euo pipefail | ||
| 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: Open or update PR | ||
| if: steps.drift.outputs.drifted == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| set -euo pipefail | ||
| BRANCH="spec-drift/auto-regen" | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git checkout -B "$BRANCH" | ||
| git add openapi.json ionq_core/ | ||
| git commit -m "Regenerate client for updated OpenAPI spec" | ||
| git push origin "$BRANCH" --force | ||
|
|
||
| { | ||
| 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') | ||
|
|
||
| existing=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number // empty') | ||
| if [[ -z "$existing" ]]; then | ||
| gh issue create \ | ||
| --title "OpenAPI spec has changed upstream" \ | ||
| gh pr create \ | ||
| --title "Regenerate client for updated OpenAPI spec" \ | ||
| --body-file /tmp/body.md \ | ||
| --head "$BRANCH" \ | ||
| --base main \ | ||
| --reviewer ionq/developer-tools \ | ||
| --label spec-drift | ||
| else | ||
| gh issue edit "$existing" --body-file /tmp/body.md | ||
| gh pr edit "$existing" --body-file /tmp/body.md | ||
| fi | ||
Oops, something went wrong.
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.
This change seems to make one of the CIs fail: https://github.com/ionq/ionq-core-python/actions/runs/26799220747/job/79002107172?pr=55