-
Notifications
You must be signed in to change notification settings - Fork 679
ci: add check to verify generated code is up-to-date #258
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
ci: add check to verify generated code is up-to-date #258
Conversation
WalkthroughThe GitHub Actions workflow configuration was updated to allow manual workflow runs and to add a new job that verifies code generation consistency by running code generation commands and checking for uncommitted changes. Changes
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This commit adds a new CI job that runs code generation and verifies no uncommitted changes exist. This prevents accidental manual edits to autogenerated files by: 1. Running `go generate ./...` during CI 2. Failing the build when generated code differs from committed code 3. Providing clear error messages with instructions for developers
6336adc
to
ccf95cd
Compare
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
.github/workflows/ci.yml (2)
19-25
: Optimize job setup with caching and full checkout
Consider adding module caching to speed up dependency resolution and settingfetch-depth: 0
on checkout to ensure all tags and history are available (helpful if any codegen scripts rely on git metadata).Apply this diff within the
verify-codegen
job setup steps:- uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' + - name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-
29-35
: Simplify update check usinggit diff --exit-code
You can reduce boilerplate and improve clarity by leveraginggit diff --exit-code
(it exits non-zero if diffs exist) and explicitly specifying the shell.Replace the current check with:
- run: | - if [[ -n $(git status --porcelain) ]]; then - echo "Error: Generated code is not up to date. Please run 'go generate ./...' and commit the changes." - git status - git diff - exit 1 - fi + shell: bash + run: | + set -eo pipefail + echo "Verifying generated code is up to date..." + git diff --exit-code || { + echo "Error: Generated code is not up to date. Please run 'go generate ./...' and commit the changes." + git status + git diff + exit 1 + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/ci.yml
(2 hunks)
🔇 Additional comments (2)
.github/workflows/ci.yml (2)
7-8
: Enable manual workflow triggers
Addingworkflow_dispatch
alongside existing triggers allows ad-hoc, manual runs of the CI workflow, which is useful for verifying codegen or rerunning tests without pushing new commits.
26-28
: Approve codegen execution step
Thego generate ./...
invocation correctly regenerates all autogenerated code based on//go:generate
directives. This integrates well into CI.
This commit adds a new CI job that runs code generation and verifies no uncommitted changes exist. This prevents accidental manual edits to autogenerated files by: 1. Running `go generate ./...` during CI 2. Failing the build when generated code differs from committed code 3. Providing clear error messages with instructions for developers
This commit adds a new CI job that runs code generation and verifies no uncommitted changes exist. This prevents accidental manual edits to autogenerated files by:
go generate ./...
during CISummary by CodeRabbit