From 4935238c40aef121dd9f6f23e8fe8acdd3fa4e89 Mon Sep 17 00:00:00 2001 From: Marcel Jacek Date: Mon, 16 Jun 2025 17:40:37 +0200 Subject: [PATCH 1/3] generate test coverage in CI --- .github/workflows/ci.yaml | 14 +++++++++++++- Makefile | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 239a463dc..03e64dca2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,11 @@ name: CI -on: [pull_request, workflow_dispatch] +on: + pull_request: + workflow_dispatch: + push: + branches: + - main jobs: main: @@ -26,8 +31,15 @@ jobs: - name: Test run: make test + - name: Archive code coverage results + uses: actions/upload-artifact@v4 + with: + name: code-coverage + path: coverage.out + config: name: Check GoReleaser config + if: github.event_name == 'pull_request' runs-on: ubuntu-latest steps: - name: Checkout diff --git a/Makefile b/Makefile index 171d9864d..a3b64bb3d 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ lint: lint-golangci-lint lint-yamllint # Test test: @echo ">> Running tests for the CLI application" - @go test ./... -count=1 + @go test ./... -count=1 -coverprofile=coverage.out # Test coverage coverage: From 6ce0ace67d53f86677ff3d90305ca4a15500e310 Mon Sep 17 00:00:00 2001 From: Marcel Jacek Date: Mon, 16 Jun 2025 17:45:07 +0200 Subject: [PATCH 2/3] add test coverage as comment in PR --- .github/workflows/ci.yaml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 03e64dca2..c110ba7fa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -48,4 +48,18 @@ jobs: - name: Check GoReleaser uses: goreleaser/goreleaser-action@v6 with: - args: check \ No newline at end of file + args: check + + code_coverage: + name: "Code coverage report" + if: github.event_name == 'pull_request' # Do not run when workflow is triggered by push to main branch + runs-on: ubuntu-latest + needs: main + permissions: + contents: read + actions: read # to download code coverage results from "main" job + pull-requests: write # write permission needed to comment on PR + steps: + - uses: fgrosse/go-coverage-report@v1.1.1 + with: + coverage-file-name: "coverage.out" \ No newline at end of file From fef0656d4e1d399d4df27c59ec624d5dc8e1cd78 Mon Sep 17 00:00:00 2001 From: Marcel Jacek Date: Tue, 17 Jun 2025 08:52:25 +0200 Subject: [PATCH 3/3] defined path and artifact-name via env --- .github/workflows/ci.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c110ba7fa..3f41f7681 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,6 +7,10 @@ on: branches: - main +env: + CODE_COVERAGE_FILE_NAME: "coverage.out" # must be the same as in Makefile + CODE_COVERAGE_ARTIFACT_NAME: "code-coverage" + jobs: main: name: CI @@ -34,8 +38,8 @@ jobs: - name: Archive code coverage results uses: actions/upload-artifact@v4 with: - name: code-coverage - path: coverage.out + name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }} + path: ${{ env.CODE_COVERAGE_FILE_NAME }} config: name: Check GoReleaser config @@ -62,4 +66,5 @@ jobs: steps: - uses: fgrosse/go-coverage-report@v1.1.1 with: - coverage-file-name: "coverage.out" \ No newline at end of file + coverage-artifact-name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }} + coverage-file-name: ${{ env.CODE_COVERAGE_FILE_NAME }} \ No newline at end of file