ci(api): add codegen drift check (#2463)
## What this PR does - Adds a pre-commit hook and a dedicated GitHub Actions workflow that run `make generate` at the repo root to catch drift in generated API code (CRDs, DeepCopy, clients, RBAC) before it lands on main. - Pre-commit hook is scoped to paths that actually affect codegen (`api/`, `pkg/apis/`, `hack/update-codegen.sh`, `hack/boilerplate.go.txt`) so unrelated commits are not slowed down. - CI workflow (`.github/workflows/codegen-drift.yml`) installs Go from `go.mod`, runs `make generate`, and fails on drift with an error pointing contributors to the local fix. - Includes one drift fix the check surfaced: `RestoreJobSpec.Options` (added in #2437) had no `DeepCopyInto` handling — regenerated. ### Release note ```release-note ci(api): add pre-commit hook and GitHub Actions workflow that verify generated API code (CRDs, deepcopy, clients, RBAC) is in sync with `make generate`. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Added a CI workflow that checks generated code during PRs and fails the build if generated artifacts diverge. * Added a pre-commit hook that runs generation checks locally to prevent committing outdated generated files. * Fixed deep-copy behavior for backup restore job specs so nested options are correctly duplicated. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
commit
82d1f8a1d2
3 changed files with 77 additions and 0 deletions
61
.github/workflows/codegen-drift.yml
vendored
Normal file
61
.github/workflows/codegen-drift.yml
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
name: Codegen Drift Check
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
paths:
|
||||
- 'api/**'
|
||||
- 'pkg/apis/**'
|
||||
- 'pkg/generated/**'
|
||||
- 'internal/crdinstall/manifests/**'
|
||||
- 'packages/system/cozystack-controller/definitions/**'
|
||||
- 'packages/system/application-definition-crd/definition/**'
|
||||
- 'packages/system/backup-controller/definitions/**'
|
||||
- 'packages/system/backupstrategy-controller/definitions/**'
|
||||
- 'hack/update-codegen.sh'
|
||||
- 'hack/boilerplate.go.txt'
|
||||
- 'Makefile'
|
||||
- 'go.mod'
|
||||
- 'go.sum'
|
||||
- '.github/workflows/codegen-drift.yml'
|
||||
|
||||
concurrency:
|
||||
group: codegen-drift-${{ github.workflow }}-${{ github.event.pull_request.number }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
codegen-drift:
|
||||
name: Verify generated code is up to date
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
|
||||
- name: Pre-fetch k8s.io/code-generator module
|
||||
# hack/update-codegen.sh sources kube_codegen.sh from the Go module cache.
|
||||
# The module is not declared in go.mod, so fetch it explicitly at the
|
||||
# version pinned in the script.
|
||||
run: |
|
||||
version=$(grep -oP 'code-generator@\Kv[0-9.]+' hack/update-codegen.sh)
|
||||
tmpdir=$(mktemp -d)
|
||||
cd "$tmpdir"
|
||||
go mod init codegen-fetch
|
||||
go get "k8s.io/code-generator@${version}"
|
||||
|
||||
- name: Run make generate
|
||||
run: make generate
|
||||
|
||||
- name: Fail on drift
|
||||
run: |
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "::error::'make generate' produced changes. Run 'make generate' locally and commit the result."
|
||||
git status --short
|
||||
git diff --color=always
|
||||
exit 1
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue