f4f53c4d9f
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.
29 lines
1.2 KiB
Docker
29 lines
1.2 KiB
Docker
FROM amd64/golang:1.25.3@sha256:9ac0edc3f9da2acc34e132363b6c2be45378feea0b73c451456a5449853af2aa as build
|
|
WORKDIR /build
|
|
ENV CGO_ENABLED=0
|
|
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 go fmt ./...
|
|
RUN go vet ./...
|
|
RUN CGO_ENABLED=1 go test -mod=readonly -race -coverprofile=coverage.txt.tmp -covermode=atomic -coverpkg=$(go list ./... | tr '\n' , | sed 's/,$//') ./...
|
|
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=coverage.txt -o coverage.html
|
|
RUN go tool cover -func=coverage.txt
|
|
RUN rm coverage.txt.tmp
|
|
|
|
RUN GOOS=linux GOARCH=amd64 go build \
|
|
-tags prod \
|
|
-a -installsuffix cgo \
|
|
-mod=readonly \
|
|
-o /release/dancefetcher \
|
|
-ldflags '-w -s' \
|
|
./cmd/dancefetcher/dancefetcher.go
|
|
|
|
FROM scratch as export
|
|
COPY --from=build /build/coverage.txt /
|
|
|
|
FROM scratch
|
|
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
COPY --from=build /release/dancefetcher /
|
|
CMD ["/dancefetcher"]
|