Skip to content

Commit 1cc4b30

Browse files
committed
ci: add generated code freshness check
Adds a CI workflow that runs go generate on native amd64 and arm64 runners and verifies no tracked .go files differ from what is committed. Three checks per arch: - Stale generated .go files (diffs output against committed code) - Missing generated files (new files from go generate not committed) - Non-empty .o stubs (tracked .o files must be 0 bytes) Signed-off-by: Quang Nguyen <nguyenquang@microsoft.com>
1 parent 12cd764 commit 1cc4b30

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Check Generated Code
2+
on:
3+
pull_request:
4+
branches: [main]
5+
6+
permissions:
7+
contents: read
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
generate-check:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- arch: amd64
20+
runner: ubuntu-latest
21+
- arch: arm64
22+
runner: ubuntu-24.04-arm
23+
name: Generate (${{ matrix.arch }})
24+
runs-on: ${{ matrix.runner }}
25+
timeout-minutes: 15
26+
steps:
27+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28+
29+
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
30+
with:
31+
go-version-file: go.mod
32+
33+
- name: Install BPF build dependencies
34+
run: |
35+
sudo apt-get update -qq
36+
sudo apt-get install -y --no-install-recommends clang llvm lld libbpf-dev linux-headers-$(uname -r)
37+
sudo apt-get install -y --no-install-recommends linux-tools-$(uname -r) linux-tools-common || true
38+
39+
- name: Run make generate for ${{ matrix.arch }}
40+
run: |
41+
# Generate BPF objects and Go bindings for this runner's native arch only,
42+
# then run the remaining (non-BPF) generators.
43+
GOARCH=${{ matrix.arch }} go generate ./pkg/plugin/...
44+
go generate ./...
45+
46+
- name: Check for uncommitted changes
47+
run: |
48+
# Ignore .o files — they are empty stubs in the repo and get
49+
# populated with real BPF objects during generate. Only the
50+
# generated .go files matter for correctness.
51+
git diff --exit-code -- ':!*.o' || {
52+
echo ""
53+
echo "============================================================"
54+
echo "ERROR: Generated code is out of date."
55+
echo ""
56+
echo "The following files differ after running 'make generate':"
57+
git diff --name-only -- ':!*.o'
58+
echo ""
59+
echo "Please run 'make generate' locally and commit the changes."
60+
echo "============================================================"
61+
exit 1
62+
}
63+
64+
- name: Check for untracked generated files
65+
run: |
66+
untracked=$(git ls-files --others --exclude-standard -- '*.go' | head -20)
67+
if [ -n "$untracked" ]; then
68+
echo ""
69+
echo "============================================================"
70+
echo "ERROR: New generated files are not committed."
71+
echo ""
72+
echo "$untracked"
73+
echo ""
74+
echo "Please run 'make generate' locally and commit the new files."
75+
echo "============================================================"
76+
exit 1
77+
fi
78+
79+
- name: Check that committed .o files are empty stubs
80+
run: |
81+
# Tracked .o files must be empty (0 bytes). They exist so that
82+
# Go source files with //go:embed or bpf2go references compile
83+
# without running go generate first. Real BPF objects are built
84+
# at image build time — committing non-empty .o files bloats
85+
# the repo and may contain host-specific binaries.
86+
non_empty=$(git ls-files '*.o' | xargs -I{} sh -c 'test -s "{}" && echo "{}"')
87+
if [ -n "$non_empty" ]; then
88+
echo ""
89+
echo "============================================================"
90+
echo "ERROR: The following .o files must be empty stubs (0 bytes)."
91+
echo ""
92+
echo "$non_empty"
93+
echo ""
94+
echo "Run 'make empty-bpf-objects' to truncate them, then commit."
95+
echo "============================================================"
96+
exit 1
97+
fi

0 commit comments

Comments
 (0)