Skip to content

Commit a3e0306

Browse files
committed
Add test coverage to test-unit Makefile target
Signed-off-by: carlory <baofa.fan@daocloud.io>
1 parent 5176573 commit a3e0306

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

.github/workflows/ci-pr-checks.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,34 @@ jobs:
4747
run: |
4848
make test sidecar-test
4949
50+
- name: Archive code coverage results
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: code-coverage
54+
path: coverage.out # Make sure to use the same file name you chose for the "-coverprofile" in the "make test" step
55+
56+
- name: Archive code coverage results
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: code-coverage
60+
path: coverage.out # Make sure to use the same file name you chose for the "-coverprofile" in the "make test" step
61+
5062
- name: Run make build
5163
shell: bash
5264
run: |
5365
make build sidecar-build
66+
67+
code_coverage:
68+
name: "Code coverage report"
69+
if: github.event_name == 'pull_request'
70+
runs-on: ubuntu-latest
71+
needs: lint-and-test # Depends on the artifact uploaded by the "lint-and-test" job
72+
permissions:
73+
contents: read
74+
actions: read # to download code coverage results from "lint-and-test" job
75+
pull-requests: write # write permission needed to comment on PR
76+
steps:
77+
- uses: fgrosse/go-coverage-report@v1.2.0
78+
with:
79+
coverage-artifact-name: "code-coverage"
80+
coverage-file-name: "coverage.out"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test: test-unit test-e2e ## Run unit tests and e2e tests
9191
.PHONY: test-unit
9292
test-unit: download-tokenizer install-dependencies ## Run unit tests
9393
@printf "\033[33;1m==== Running Unit Tests ====\033[0m\n"
94-
go test -ldflags="$(LDFLAGS)" -v $$(echo $$(go list ./... | grep -v /test/))
94+
go test -ldflags="$(LDFLAGS)" -cover -coverprofile=coverage.out -v $$(echo $$(go list ./... | grep -v /test/))
9595

9696
.PHONY: test-integration
9797
test-integration: download-tokenizer install-dependencies ## Run integration tests

0 commit comments

Comments
 (0)