Skip to content

Commit 509ce5d

Browse files
committed
build(kamaji): run the tests of the packages the patches touch
The image build ran go build only, and go build never compiles a _test.go, so nothing ran the tests of the code the patches change. Run go test in the builder stage on the packages the patches touch. The list is read from the patches themselves, so a new patch is covered without an edit to the Dockerfile. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent f57bdbd commit 509ce5d

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎packages/system/kamaji/images/kamaji/Dockerfile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ RUN curl -sSL https://github.com/clastix/kamaji/archive/refs/tags/${VERSION}.tar
1212
COPY patches /patches
1313
RUN git apply /patches/*.diff
1414

15+
# go build never compiles a _test.go, so nothing else runs the tests of the
16+
# packages the patches touch. Each package is tested from its own directory:
17+
# that finds the module it belongs to, and an empty list runs nothing.
18+
# The list is read into a variable first: a for loop drops the exit status
19+
# of a command substitution, so a patch git cannot read would leave the list
20+
# empty and the step green.
21+
RUN files=$(git apply --numstat /patches/*.diff) || exit 1; \
22+
for dir in $(printf '%s\n' "$files" | cut -f3 | grep '\.go$' | xargs -r -n1 dirname | sort -u); do \
23+
(cd "$dir" && go test .) || exit 1; \
24+
done
25+
1526
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build \
1627
-ldflags "-X github.com/clastix/kamaji/internal.GitRepo=$GIT_REPO -X github.com/clastix/kamaji/internal.GitTag=$GIT_LAST_TAG -X github.com/clastix/kamaji/internal.GitCommit=$GIT_HEAD_COMMIT -X github.com/clastix/kamaji/internal.GitDirty=$GIT_MODIFIED -X github.com/clastix/kamaji/internal.BuildTime=$BUILD_DATE" \
1728
-a -o kamaji main.go

0 commit comments

Comments
 (0)