fix(ci): commit regenerated OpenAPI artifact (audit #118)#342
Conversation
Prior workflow regenerated openapi.yaml on every push but discarded the
output — spec never reached origin. This caused "invisible drift"
(consumers couldn't fetch a current contract). Now auto-commits on change
with [skip ci] to avoid recursive triggers.
Changes to .github/workflows/openapi-docs.yml:
- Add `permissions: contents: write` to deploy-to-docs-site job (was
missing; push would fail silently on protected default token).
- Explicit `ref: main` + `persist-credentials: true` on checkout so the
push targets main with the job token.
- Switch bot identity to github-actions[bot] noreply address (matches
Phenotype convention).
- Tighter porcelain check scoped to the two spec files; explicit
`git push origin HEAD:main`.
Note: `backend/docs/` is gitignored intentionally (swag-generated build
artifact); the canonical committed spec lives at `docs/public/openapi.{json,yaml}`.
No .gitignore negation required.
Alternative considered: peter-evans/create-pull-request (Option C) would
add review gates on spec changes. Can be adopted later if the team wants
human review on every contract change; for now auto-commit matches the
existing design intent of the job (which already had commit-and-push
wired — just missing write perms).
Ref worklogs/ARCHITECTURE.md 2026-04-24 OpenAPI/spec coverage audit.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
Note
|
| Cohort / File(s) | Summary |
|---|---|
Workflow Configuration .github/workflows/openapi-docs.yml |
Updated permissions to explicitly request contents: write, switched Git identity from custom "OpenAPI Bot" to github-actions[bot], and replaced change detection logic to use git status --porcelain with conditional commit/push and explicit no-op handling. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~12 minutes
Poem
🐰 Permissions granted, credentials persist,
GitHub's bot now commits with a fist,
Status checks shine, no diffs in the night,
OpenAPI specs flow, oh what a sight!
[skip ci] hops along, trouble-free and light!
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly and specifically describes the main change: fixing the CI workflow to commit regenerated OpenAPI artifacts, with reference to the audit. |
| Description check | ✅ Passed | The description is thorough and covers key sections: problem statement, detailed changes, justification for design choice, and test plan. Required template sections are adequately addressed. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
fix/ci-commit-openapi-artifact
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
|
CodeAnt AI finished reviewing your PR. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/openapi-docs.yml (1)
126-166:⚠️ Potential issue | 🟠 MajorAdd a
concurrencygroup (and/or push retry) to avoid racing self-commits tomain.The deploy job now pushes directly to
main, but nothing serializes runs. If two qualifying pushes land close together (e.g. a feature merge followed quickly by another, or a bulk merge), twodeploy-to-docs-sitejobs run in parallel, both check outmain, and whichever pushes second fails with a non-fast-forward (nogit pull --rebase/retry). Worse, withref: maineach run checks out whatevermainis at the time of the checkout, so a later-triggered run can commit an older artifact on top of a newer one from a concurrent run, causing artifact flap until the next trigger.Two low-cost mitigations (pick one, ideally both):
🔧 Proposed fix — serialize the deploy job and add a rebase-retry on push
deploy-to-docs-site: name: Deploy to Docs Site runs-on: ubuntu-latest needs: generate-and-validate if: github.event_name == 'push' && github.ref == 'refs/heads/main' permissions: contents: write + concurrency: + group: openapi-docs-deploy-main + cancel-in-progress: false- name: Commit and push if changed run: | git config user.name 'github-actions[bot]' git config user.email '41898282+github-actions[bot]@users.noreply.github.com' git add docs/public/openapi.json docs/public/openapi.yaml if [ -n "$(git status --porcelain docs/public/openapi.json docs/public/openapi.yaml)" ]; then git commit -m "chore(openapi): regenerate spec artifact [skip ci]" - git push origin HEAD:main + for i in 1 2 3; do + git pull --rebase --autostash origin main && git push origin HEAD:main && break + echo "Push attempt $i failed, retrying..." + sleep $((i * 5)) + done else echo "No OpenAPI spec changes to commit." fiThe
concurrencygroup prevents overlapping runs onmainand removes the race entirely; the rebase-retry handles the remaining edge case where an unrelated push lands between checkout and push.Per the PR objectives,
[skip ci]is relied on to prevent recursive triggers — note that commits authored via the defaultGITHUB_TOKENalready don't trigger further workflow runs by design, so this is belt-and-suspenders and not a concern on its own.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/openapi-docs.yml around lines 126 - 166, The deploy-to-docs-site job is racy when multiple pushes to main trigger simultaneous runs; add a concurrency stanza to the job (e.g., concurrency: { group: "deploy-docs-site-main", cancel-in-progress: false }) to serialize runs and update the "Commit and push if changed" step to perform a safe retry/rebase before push (detect non-fast-forward, run git pull --rebase origin main and re-add/commit, retry push a few times with backoff) so the sequence in the "Checkout code" and "Commit and push if changed" steps handles intervening commits and avoids failed/non-fast-forward pushes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In @.github/workflows/openapi-docs.yml:
- Around line 126-166: The deploy-to-docs-site job is racy when multiple pushes
to main trigger simultaneous runs; add a concurrency stanza to the job (e.g.,
concurrency: { group: "deploy-docs-site-main", cancel-in-progress: false }) to
serialize runs and update the "Commit and push if changed" step to perform a
safe retry/rebase before push (detect non-fast-forward, run git pull --rebase
origin main and re-add/commit, retry push a few times with backoff) so the
sequence in the "Checkout code" and "Commit and push if changed" steps handles
intervening commits and avoids failed/non-fast-forward pushes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: cb207c21-5f46-4c3d-b206-543c515ad530
📒 Files selected for processing (1)
.github/workflows/openapi-docs.yml
|
CodeAnt AI is running the review. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI finished running the review. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI is running the review. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI finished running the review. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI is running the review. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI finished running the review. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI is running the review. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI finished running the review. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
User description
Summary
Audit #118 flagged that
.github/workflows/openapi-docs.ymlregenerates the OpenAPI spec on every push but the spec artifact never reachesorigin— "invisible generator" drift. Consumers (SDK generators, docs site, contract tests) cannot fetch a current contract from the repo.Root cause: the
deploy-to-docs-sitejob already contained a commit-and-push step, but was missingpermissions: contents: write(so the defaultGITHUB_TOKENcould not push) and the checkout did not persist credentials againstmain.Changes
permissions: contents: writetodeploy-to-docs-sitejob.ref: main,persist-credentials: true,token: ${{ secrets.GITHUB_TOKEN }}.git push origin HEAD:main.github-actions[bot]noreply identity (Phenotype convention).[skip ci]on the commit message to avoid recursive triggers.Why Option A (auto-commit) vs C (PR)
Job was already wired for auto-commit — just broken. Kept intent; documented that
peter-evans/create-pull-request@v7is an easy swap if the team later wants human review on contract changes..gitignore
backend/docs/is ignored intentionally (swag build artifact). Canonical committed spec lives atdocs/public/openapi.{json,yaml}which is not ignored. No negation needed.Test plan
maintouchingbackend/**/*.gotriggers regeneration.chore(openapi): regenerate spec artifact [skip ci]commit appears onmainwith updateddocs/public/openapi.{json,yaml}.[skip ci]prevents recursive workflow trigger.Ref:
worklogs/ARCHITECTURE.md2026-04-24 OpenAPI/spec coverage audit.🤖 Generated with Claude Code
Note
Medium Risk
Changes CI to push commits to
mainusingGITHUB_TOKEN, which can create unintended repo writes or loops if misconfigured, but scope is limited to two spec files and uses[skip ci].Overview
Ensures the
deploy-to-docs-siteGitHub Actions job can commit and push regenerated OpenAPI specs back tomain.The workflow now grants
contents: write, checks outmainwith persisted credentials, and only commits whendocs/public/openapi.{json,yaml}changed, pushing explicitly viagit push origin HEAD:mainwith thegithub-actions[bot]identity and a[skip ci]commit message.Reviewed by Cursor Bugbot for commit 0dd90b5. Bugbot is set up for automated code reviews on this repo. Configure here.
CodeAnt-AI Description
Keep the OpenAPI spec committed to the repo after regeneration
What Changed
mainafter regeneration.openapi.jsonoropenapi.yamlchanges, the workflow commits them with a bot identity and skips CI to avoid повторный trigger loops.Impact
✅ Current OpenAPI specs stay available in the repo✅ Fewer stale contract files after backend changes✅ No extra CI runs from spec auto-updates🔄 Retrigger CodeAnt AI Review
Details
💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.