Skip to content

Commit 35287b9

Browse files
authored
Merge pull request moby#3727 from crazy-max/test-annotations
ci: output annotations for failures
2 parents 170e440 + 65540db commit 35287b9

File tree

5 files changed

+61
-51
lines changed

5 files changed

+61
-51
lines changed

.github/workflows/.test.yml

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ env:
3131
SETUP_BUILDX_VERSION: "latest"
3232
SETUP_BUILDKIT_IMAGE: "moby/buildkit:latest"
3333
TESTFLAGS: "-v --parallel=6 --timeout=30m"
34+
GOTESTSUM_FORMAT: "standard-verbose"
3435

3536
jobs:
3637
prepare:
@@ -143,6 +144,7 @@ jobs:
143144
name: Test
144145
continue-on-error: ${{ matrix.tags == 'nydus' }}
145146
run: |
147+
export TEST_REPORT_SUFFIX=-${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.skip-integration-tests }}-${{ matrix.kind }}-${{ matrix.worker }}-${{ matrix.tags }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]')
146148
if [ -n "${{ matrix.tags }}" ]; then
147149
TESTFLAGS="${TESTFLAGS} --tags=${{ matrix.tags }}"
148150
export BUILDKITD_TAGS="${{ matrix.tags }}"
@@ -151,48 +153,28 @@ jobs:
151153
export TESTFLAGS="${TESTFLAGS} --run=//worker=${{ matrix.worker }}$"
152154
fi
153155
./hack/test ${{ matrix.kind }}
154-
mv ./coverage/coverage.txt ./coverage/coverage-${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.skip-integration-tests }}-${{ matrix.kind }}-${{ matrix.worker }}-${{ matrix.tags }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]').txt
155156
env:
156157
TEST_COVERAGE: 1
157158
TESTPKGS: ${{ matrix.pkg }}
158159
SKIP_INTEGRATION_TESTS: ${{ matrix.skip-integration-tests }}
159160
CACHE_FROM: type=gha,scope=${{ inputs.cache_scope }}
160161
-
161-
name: Upload coverage file
162-
continue-on-error: ${{ matrix.tags == 'nydus' }}
163-
uses: actions/upload-artifact@v3
164-
with:
165-
name: coverage
166-
path: ./coverage
167-
168-
upload-coverage:
169-
runs-on: ubuntu-20.04
170-
needs:
171-
- run
172-
steps:
173-
-
174-
name: Checkout
175-
uses: actions/checkout@v3
176-
-
177-
name: Download coverage files
178-
uses: actions/download-artifact@v3
162+
name: Send to Codecov
163+
if: always()
164+
uses: codecov/codecov-action@v3
179165
with:
180-
name: coverage
181-
path: ./coverage
166+
directory: ./bin/testreports
167+
flags: ${{ matrix.codecov_flags }}
182168
-
183-
name: List coverage files
184-
id: files
185-
uses: actions/github-script@v6
169+
name: Generate annotations
170+
if: always()
171+
uses: crazy-max/.github/.github/actions/gotest-annotations@5af0882e0496d2f7e98a53ae4048e3d86682496f
186172
with:
187-
result-encoding: string
188-
script: |
189-
return require('fs').readdirSync('./coverage', {withFileTypes: true})
190-
.filter(item => !item.isDirectory())
191-
.map(item => `./coverage/${item.name}`)
192-
.join(',');
173+
directory: ./bin/testreports
193174
-
194-
name: Send to Codecov
195-
uses: codecov/codecov-action@v3
175+
name: Upload test reports
176+
if: always()
177+
uses: actions/upload-artifact@v3
196178
with:
197-
files: ${{ steps.files.outputs.result }}
198-
flags: ${{ matrix.codecov_flags }}
179+
name: test-reports
180+
path: ./bin/testreports

.github/workflows/test-os.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ on:
2121
env:
2222
GO_VERSION: "1.20"
2323
TESTFLAGS: "-v --parallel=6 --timeout=30m"
24+
GOTESTSUM_VERSION: "v1.9.0" # same as one in Dockerfile
25+
GOTESTSUM_FORMAT: "standard-verbose"
2426

2527
jobs:
2628
test:
@@ -43,22 +45,43 @@ jobs:
4345
go-version: "${{ env.GO_VERSION }}"
4446
cache: true
4547
-
46-
name: Go mod
48+
name: Install gotestsum
4749
run: |
48-
go mod download
50+
go install gotest.tools/gotestsum@${{ env.GOTESTSUM_VERSION }}
4951
-
5052
name: Test
5153
env:
5254
TMPDIR: ${{ runner.temp }}
5355
SKIP_INTEGRATION_TESTS: 1
5456
run: |
55-
mkdir -p ./coverage
56-
go test -coverprofile=./coverage/coverage.txt -covermode=atomic ${TESTFLAGS} ./...
57+
mkdir -p ./bin/testreports
58+
gotestsum \
59+
--jsonfile="./bin/testreports/go-test-report.json" \
60+
--junitfile="./bin/testreports/junit-report.xml" \
61+
--packages="./..." \
62+
-- \
63+
"-mod=vendor" \
64+
"-coverprofile" "./bin/testreports/coverage.txt" \
65+
"-covermode" "atomic" ${TESTFLAGS}
5766
shell: bash
5867
-
5968
name: Send to Codecov
69+
if: always()
6070
uses: codecov/codecov-action@v3
6171
with:
62-
files: ./coverage/coverage.txt
72+
directory: ./bin/testreports
6373
env_vars: RUNNER_OS
6474
flags: unit
75+
-
76+
name: Generate annotations
77+
if: always()
78+
uses: crazy-max/.github/.github/actions/gotest-annotations@5af0882e0496d2f7e98a53ae4048e3d86682496f
79+
with:
80+
directory: ./bin/testreports
81+
-
82+
name: Upload test reports
83+
if: always()
84+
uses: actions/upload-artifact@v3
85+
with:
86+
name: test-reports
87+
path: ./bin/testreports

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
# if you want to ignore files created by your editor/tools,
33
# please consider a global .gitignore https://help.github.com/articles/ignoring-files
44
bin
5-
coverage
65
.certs
76
.tmp

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ARG NYDUS_VERSION=v2.1.0
1414
ARG MINIO_VERSION=RELEASE.2022-05-03T20-36-08Z
1515
ARG MINIO_MC_VERSION=RELEASE.2022-05-04T06-07-55Z
1616
ARG AZURITE_VERSION=3.18.0
17+
ARG GOTESTSUM_VERSION=v1.9.0
1718

1819
ARG GO_VERSION=1.20
1920
ARG ALPINE_VERSION=3.17
@@ -207,6 +208,12 @@ SHELL ["/bin/bash", "-c"]
207208
RUN wget https://github.com/dragonflyoss/image-service/releases/download/$NYDUS_VERSION/nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz
208209
RUN mkdir -p /out/nydus-static && tar xzvf nydus-static-$NYDUS_VERSION-$TARGETOS-$TARGETARCH.tgz -C /out
209210

211+
FROM gobuild-base AS gotestsum
212+
ARG GOTESTSUM_VERSION
213+
RUN --mount=target=/root/.cache,type=cache \
214+
GOBIN=/out/ go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" && \
215+
/out/gotestsum --version
216+
210217
FROM buildkit-export AS buildkit-linux
211218
COPY --link --from=binaries / /usr/bin/
212219
ENTRYPOINT ["buildkitd"]
@@ -249,6 +256,8 @@ ENTRYPOINT ["/docker-entrypoint.sh"]
249256
ENV BUILDKIT_INTEGRATION_CONTAINERD_EXTRA="containerd-1.6=/opt/containerd-alt-16/bin"
250257
ENV BUILDKIT_INTEGRATION_SNAPSHOTTER=stargz
251258
ENV CGO_ENABLED=0
259+
ENV GOTESTSUM_FORMAT=standard-verbose
260+
COPY --link --from=gotestsum /out/gotestsum /usr/bin/
252261
COPY --link --from=minio /opt/bin/minio /usr/bin/
253262
COPY --link --from=minio-mc /usr/bin/mc /usr/bin/
254263
COPY --link --from=nydus /out/nydus-static/* /usr/bin/

hack/test

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set -eu -o pipefail
1111
: ${TEST_DOCKERFILE=}
1212
: ${TEST_DOCKERD=}
1313
: ${TEST_DOCKERD_BINARY=$(which dockerd)}
14-
: ${TEST_COVERAGE=}
14+
: ${TEST_REPORT_SUFFIX=}
1515
: ${TEST_KEEP_CACHE=}
1616
: ${DOCKERFILE_RELEASES=}
1717
: ${BUILDKIT_WORKER_RANDOM=}
@@ -54,14 +54,11 @@ done
5454
iid="buildkit-tests"
5555
iidfile=$(mktemp -t docker-iidfile.XXXXXXXXXX)
5656

57-
coverageVol=""
58-
coverageFlags=""
59-
if [ "$TEST_COVERAGE" = "1" ]; then
60-
covdir="$(pwd)/coverage"
61-
mkdir -p "$covdir"
62-
coverageVol="-v $covdir:/coverage"
63-
coverageFlags="-coverprofile=/coverage/coverage.txt -covermode=atomic"
64-
fi
57+
testReportsDir="$(pwd)/bin/testreports"
58+
mkdir -p "$testReportsDir"
59+
testReportsVol="-v $testReportsDir:/testreports"
60+
gotestsumArgs="--format=standard-verbose --jsonfile=/testreports/go-test-report$TEST_REPORT_SUFFIX.json --junitfile=/testreports/junit-report$TEST_REPORT_SUFFIX.xml"
61+
gotestArgs="-mod=vendor -coverprofile=/testreports/coverage-report$TEST_REPORT_SUFFIX.txt -covermode=atomic"
6562

6663
buildxCmd build $cacheFromFlags \
6764
--build-arg BUILDKITD_TAGS \
@@ -78,7 +75,7 @@ if ! docker container inspect "$cacheVolume" >/dev/null 2>/dev/null; then
7875
fi
7976

8077
if [ "$TEST_INTEGRATION" == 1 ]; then
81-
cid=$(docker create --rm -v /tmp $coverageVol --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e SKIP_INTEGRATION_TESTS -e BUILDKIT_TEST_ENABLE_FEATURES -e BUILDKIT_TEST_DISABLE_FEATURES ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_INTEGRATION_DOCKERD_FLAGS --privileged $iid go test $coverageFlags ${TESTFLAGS:--v} ${TESTPKGS:-./...})
78+
cid=$(docker create --rm -v /tmp $testReportsVol --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e SKIP_INTEGRATION_TESTS -e BUILDKIT_TEST_ENABLE_FEATURES -e GOTESTSUM_FORMAT ${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_INTEGRATION_DOCKERD_FLAGS --privileged $iid gotestsum $gotestsumArgs --packages="${TESTPKGS:-./...}" -- $gotestArgs ${TESTFLAGS:--v})
8279
if [ "$TEST_DOCKERD" = "1" ]; then
8380
docker cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/dockerd
8481
fi
@@ -118,7 +115,7 @@ if [ "$TEST_DOCKERFILE" == 1 ]; then
118115

119116
if [ -s $tarout ]; then
120117
if [ "$release" = "mainline" ] || [ "$release" = "labs" ] || [ -n "$DOCKERFILE_RELEASES_CUSTOM" ] || [ "$GITHUB_ACTIONS" = "true" ]; then
121-
cid=$(docker create -v /tmp $coverageVol --rm --privileged --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e BUILDKIT_TEST_ENABLE_FEATURES -e BUILDKIT_TEST_DISABLE_FEATURES -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_WORKER_RANDOM -e BUILDKIT_INTEGRATION_DOCKERD_FLAGS -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid go test $coverageFlags --count=1 -tags "$buildtags" ${TESTFLAGS:--v} ./frontend/dockerfile)
118+
cid=$(docker create -v /tmp $testReportsVol --rm --privileged --volumes-from=$cacheVolume -e GITHUB_REF -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e TEST_DOCKERD -e BUILDKIT_TEST_ENABLE_FEATURES -e GOTESTSUM_FORMAT -e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry -e BUILDKIT_WORKER_RANDOM -e BUILDKIT_INTEGRATION_DOCKERD_FLAGS -e FRONTEND_GATEWAY_ONLY=local:/$release.tar -e EXTERNAL_DF_FRONTEND=/dockerfile-frontend $iid gotestsum $gotestsumArgs --packages=./frontend/dockerfile -- $gotestArgs --count=1 -tags "$buildtags" ${TESTFLAGS:--v})
122119
docker cp $tarout $cid:/$release.tar
123120
if [ "$TEST_DOCKERD" = "1" ]; then
124121
docker cp "$TEST_DOCKERD_BINARY" $cid:/usr/bin/dockerd

0 commit comments

Comments
 (0)