Skip to content

Commit d18b3ac

Browse files
authored
Add CI check to verify generated code is up-to-date (#39)
1 parent 1909ba4 commit d18b3ac

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Verify
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
verify:
9+
name: Verify Codegen
10+
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Clone the code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version-file: go.mod
20+
21+
- name: Run Codegen
22+
shell: bash
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
run: make update-codegen
26+
27+
- name: Verify
28+
shell: bash
29+
run: |
30+
# URL encode function for GitHub Actions annotations
31+
# From: https://backreference.org/2009/12/23/how-to-match-newlines-in-sed/
32+
function urlencode() {
33+
sed ':begin;$!N;s/\n/%0A/;tbegin'
34+
}
35+
36+
if [[ -z "$(git status --porcelain)" ]]; then
37+
echo "${{ github.repository }} up to date."
38+
else
39+
echo "Found diffs in: $(git diff-index --name-only HEAD --)"
40+
for x in $(git diff-index --name-only HEAD --); do
41+
echo "::error file=$x::Please run 'make update-codegen'.%0A$(git diff $x | urlencode)"
42+
done
43+
echo "Generated code is out of date. Please run 'make update-codegen' and commit the changes."
44+
exit 1
45+
fi

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.
239239
create-kind-cluster:
240240
./hack/create-kind-cluster.sh
241241

242+
.PHONY: update-codegen
243+
update-codegen: generate manifests gen-mocks
244+
242245
##@ Dependencies
243246

244247
## Location to install dependencies to

0 commit comments

Comments
 (0)