Skip to content

Commit 1ffc858

Browse files
committed
build(keycloak-operator): 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 e2757ba commit 1ffc858

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • packages/system/keycloak-operator/images/keycloak-operator

‎packages/system/keycloak-operator/images/keycloak-operator/Dockerfile‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ COPY --from=source /src/go.mod /src/go.sum ./
2121
RUN go mod download
2222

2323
COPY --from=source /src .
24+
25+
COPY --from=source /patches /patches
26+
27+
# go build never compiles a _test.go, so nothing else runs the tests of the
28+
# packages the patches touch. Each package is tested from its own directory:
29+
# that finds the module it belongs to, and an empty list runs nothing.
30+
# The list is read into a variable first: a for loop drops the exit status
31+
# of a command substitution, so a patch git cannot read would leave the list
32+
# empty and the step green.
33+
RUN files=$(git apply --numstat /patches/*.diff) || exit 1; \
34+
for dir in $(printf '%s\n' "$files" | cut -f3 | grep '\.go$' | xargs -r -n1 dirname | sort -u); do \
35+
(cd "$dir" && go test .) || exit 1; \
36+
done
37+
2438
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /build/manager ./cmd
2539

2640
FROM gcr.io/distroless/static:nonroot@sha256:e2e927ec666bae08560abb3c55d0659eceabb657f56b6782ab500a9fc7f555e3

0 commit comments

Comments
 (0)