From 533bb6a399daec9660fc50b7fdc1b0926b039da2 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 3 Feb 2025 10:19:41 -0800 Subject: [PATCH 1/5] Add unit test code coverage --- .github/workflows/lint-and-tests.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml index d0200e72..44d39f4e 100644 --- a/.github/workflows/lint-and-tests.yml +++ b/.github/workflows/lint-and-tests.yml @@ -64,4 +64,9 @@ jobs: restore-keys: | ${{ runner.os }}-go- - name: Run Unit Tests - run: make test \ No newline at end of file + run: make test + - name: Publish Unit Test Coverage + uses: codecov/codecov-action@v1 + with: + flags: unittests + file: cover.out \ No newline at end of file From 06f4f2b664a3d592d6208b3cfe0bae4a3f424fd5 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 3 Feb 2025 10:22:05 -0800 Subject: [PATCH 2/5] enable unit test to run if change in pkg/ --- .github/workflows/lint-and-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml index 44d39f4e..bfb844f7 100644 --- a/.github/workflows/lint-and-tests.yml +++ b/.github/workflows/lint-and-tests.yml @@ -16,6 +16,7 @@ on: - 'pkg/**' - 'cmd/**' - 'api/**' + - 'pkg/**' - 'go.mod' - 'go.sum' - '.golangci.yml' @@ -69,4 +70,4 @@ jobs: uses: codecov/codecov-action@v1 with: flags: unittests - file: cover.out \ No newline at end of file + file: cover.out From 14e3a9f962781bcd29b9ebc33268fe8eddb04c46 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 3 Feb 2025 10:24:35 -0800 Subject: [PATCH 3/5] enable unit test to run if change in github workflow --- .github/workflows/lint-and-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml index bfb844f7..2ade65b9 100644 --- a/.github/workflows/lint-and-tests.yml +++ b/.github/workflows/lint-and-tests.yml @@ -4,6 +4,7 @@ on: push: branches: [ "main" ] paths: + - '.github/workflows/**' - 'pkg/**' - 'cmd/**' - 'api/**' @@ -13,10 +14,10 @@ on: pull_request: branches: [ "main" ] paths: + - '.github/workflows/**' - 'pkg/**' - 'cmd/**' - 'api/**' - - 'pkg/**' - 'go.mod' - 'go.sum' - '.golangci.yml' From ce90655e2d96483e770128edd45917f628a35188 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Tue, 4 Feb 2025 09:59:13 -0800 Subject: [PATCH 4/5] add codecov token --- .github/workflows/lint-and-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml index 2ade65b9..560c8a34 100644 --- a/.github/workflows/lint-and-tests.yml +++ b/.github/workflows/lint-and-tests.yml @@ -72,3 +72,4 @@ jobs: with: flags: unittests file: cover.out + token: ${{ secrets.CODECOV_TOKEN }} From e304705d1216b4a04a09b57288e461fc0b476486 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Tue, 4 Feb 2025 11:30:10 -0800 Subject: [PATCH 5/5] nit --- .github/workflows/lint-and-tests.yml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml index 560c8a34..ddb103df 100644 --- a/.github/workflows/lint-and-tests.yml +++ b/.github/workflows/lint-and-tests.yml @@ -67,9 +67,23 @@ jobs: ${{ runner.os }}-go- - name: Run Unit Tests run: make test - - name: Publish Unit Test Coverage - uses: codecov/codecov-action@v1 + - name: Archive code coverage results + uses: actions/upload-artifact@v4 with: - flags: unittests - file: cover.out - token: ${{ secrets.CODECOV_TOKEN }} + name: code-coverage + path: cover.out # Make sure to use the same file name you chose for the "-coverprofile" in the "Test" step + + 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: test # Depends on the artifact uploaded by the "unit_tests" job + permissions: + contents: read + actions: read # to download code coverage results from "test" job + pull-requests: write # write permission needed to comment on PR + steps: + - uses: fgrosse/go-coverage-report@v1.1.1 # Consider using a Git revision for maximum security + with: + coverage-artifact-name: "code-coverage" # can be omitted if you used this default value + coverage-file-name: "cover.out" # can be omitted if you used this default value