ci: add code coverage reporting to CI pipeline
Update code coverage file handling in the Dockerfile to generate coverage reports properly. Change temporary coverage file name and exclude specific files from the report. Remove the temporary file after processing. Add steps to the CI pipeline to download and execute the Codecov uploader, ensuring coverage data is uploaded for analysis during the build stage.
This commit is contained in:
@@ -13,6 +13,9 @@ build:
|
|||||||
stage: build
|
stage: build
|
||||||
script:
|
script:
|
||||||
- build
|
- build
|
||||||
|
- curl -Os https://uploader.codecov.io/latest/linux/codecov
|
||||||
|
- chmod +x codecov
|
||||||
|
- ./codecov -t ${CODECOV_TOKEN} -R $CI_PROJECT_DIR -C $CI_COMMIT_SHA -r $CI_PROJECT_PATH
|
||||||
- push
|
- push
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
+8
-4
@@ -5,10 +5,11 @@ ADD . /build
|
|||||||
RUN if [ $(go mod tidy -v 2>&1 | grep -c unused) != 0 ]; then echo "Unused modules, please run 'go mod tidy'"; exit 1; fi
|
RUN if [ $(go mod tidy -v 2>&1 | grep -c unused) != 0 ]; then echo "Unused modules, please run 'go mod tidy'"; exit 1; fi
|
||||||
RUN go fmt ./...
|
RUN go fmt ./...
|
||||||
RUN go vet ./...
|
RUN go vet ./...
|
||||||
RUN CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=.testCoverage.txt.tmp -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./...
|
RUN CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=coverage.txt.tmp -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./...
|
||||||
RUN cat .testCoverage.txt.tmp | grep -v generated.go | grep -v _gen.go > .testCoverage.txt
|
RUN ["/bin/bash", "-c", "cat coverage.txt.tmp | grep -v testing.go | grep -v -f <(find . -type f | xargs grep -l 'Code generated by github.com/99designs/gqlgen, DO NOT EDIT') > coverage.txt"]
|
||||||
RUN go tool cover -html=.testCoverage.txt -o coverage.html
|
RUN go tool cover -html=coverage.txt -o coverage.html
|
||||||
RUN go tool cover -func=.testCoverage.txt
|
RUN go tool cover -func=coverage.txt
|
||||||
|
RUN rm coverage.txt.tmp
|
||||||
|
|
||||||
RUN GOOS=linux GOARCH=amd64 go build \
|
RUN GOOS=linux GOARCH=amd64 go build \
|
||||||
-tags prod \
|
-tags prod \
|
||||||
@@ -18,6 +19,9 @@ RUN GOOS=linux GOARCH=amd64 go build \
|
|||||||
-ldflags '-w -s' \
|
-ldflags '-w -s' \
|
||||||
./cmd/dancefetcher/dancefetcher.go
|
./cmd/dancefetcher/dancefetcher.go
|
||||||
|
|
||||||
|
FROM scratch as export
|
||||||
|
COPY --from=build /build/coverage.txt /
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
COPY --from=build /release/dancefetcher /
|
COPY --from=build /release/dancefetcher /
|
||||||
|
|||||||
Reference in New Issue
Block a user