- Add generated-output dirs (pkg/generated, internal/crdinstall/manifests, packages/system/*/definitions) and Makefile to the workflow paths: filter so PRs that modify only generated artifacts still trigger the drift check. - Mirror the same paths in the root pre-commit hook's files: regex so manual edits to generated files or changes to the root generate target re-run make generate through pre-commit. - Switch drift detection in the workflow from `git diff --exit-code` to `git status --porcelain` so new untracked files produced by make generate (e.g. generated YAML/Go for a new API type) also fail the job; dump `git diff --color=always` on failure for easier debugging. Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
61 lines
1.9 KiB
YAML
61 lines
1.9 KiB
YAML
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
|