Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export code coverage in github actions #21

Merged
merged 14 commits into from
Aug 30, 2024
17 changes: 15 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ concurrency:
jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
pull-requests: write
steps:
- name: Detect version
run: |-
Expand All @@ -31,11 +35,20 @@ jobs:
- name: Running tests
uses: docker/build-push-action@v6
with:
target: test
push: false
target: coverage
outputs: type=local,dest=coverage/
build-args: |
VERSION=${{ env.VERSION }}

- name: Archive code coverage results
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: code-coverage-report
path: |
coverage/coverage.out
coverage/coverage.html

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand Down
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ COPY pkg/ ./pkg
FROM base AS test

RUN go vet -v ./...
RUN go test -v ./...
RUN go test -race -v -coverprofile=cover.out -covermode=atomic ./...
RUN go tool cover -html cover.out -o cover.html

FROM scratch AS coverage

COPY --from=test /work/cover.html coverage.html
COPY --from=test /work/cover.out coverage.out

# Stage to build the binary
FROM base AS build
Expand Down