File tree Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ on: [pull_request, workflow_dispatch]
4
4
5
5
env :
6
6
GO_VERSION : " 1.24"
7
+ CODE_COVERAGE_FILE_NAME : " coverage.out" # must be the same as in Makefile
8
+ CODE_COVERAGE_ARTIFACT_NAME : " code-coverage"
7
9
8
10
jobs :
9
11
main :
@@ -29,10 +31,33 @@ jobs:
29
31
30
32
- name : Lint
31
33
run : make lint
32
-
34
+
35
+ # note: test make task creates the coverage.out file
33
36
- name : Test
34
37
run : make test
35
38
39
+ - name : Upload code coverage results
40
+ uses : actions/upload-artifact@v4
41
+ with :
42
+ name : ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
43
+ path : ${{ env.CODE_COVERAGE_FILE_NAME }}
44
+
45
+ code_coverage :
46
+ name : " Code coverage report"
47
+ if : ${{ github.event_name == 'pull_request' }}
48
+ runs-on : ubuntu-latest
49
+ needs : [main]
50
+ permissions :
51
+ contents : read
52
+ actions : read # to download code coverage results from "test" job
53
+ pull-requests : write # write permission needed to comment on PR
54
+ steps :
55
+ - name : Add code coverage report comment to PR
56
+ uses : fgrosse/go-coverage-report@v1.2.0
57
+ with :
58
+ coverage-artifact-name : ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
59
+ coverage-file-name : ${{ env.CODE_COVERAGE_FILE_NAME }}
60
+
36
61
config :
37
62
name : Check GoReleaser config
38
63
runs-on : ubuntu-latest
Original file line number Diff line number Diff line change @@ -25,8 +25,7 @@ These commands can be executed from the project root:
25
25
- ` make project-tools ` : get the required dependencies
26
26
- ` make lint ` : lint the code and examples
27
27
- ` make generate-docs ` : generate terraform documentation
28
- - ` make test ` : run unit tests
29
- - ` make coverage ` : create unit test coverage report (output file: ` stackit/coverage.html ` )
28
+ - ` make test ` : run unit tests and create unit test coverage report (output file: ` stackit/coverage.html ` )
30
29
- ` make test-acceptance-tf ` : run acceptance tests
31
30
32
31
### Repository structure
Original file line number Diff line number Diff line change 35
35
# TEST
36
36
test :
37
37
@echo " Running tests for the terraform provider"
38
- @cd $(ROOT_DIR ) /stackit && go test ./... -count=1 && cd $(ROOT_DIR )
39
-
40
- # Test coverage
41
- coverage :
42
- @echo " >> Creating test coverage report for the terraform provider"
43
- @cd $(ROOT_DIR ) /stackit && (go test ./... -count=1 -coverprofile=coverage.out || true) && cd $(ROOT_DIR )
38
+ @cd $(ROOT_DIR ) /stackit && (go test ./... -count=1 -coverprofile=coverage.out) && cd $(ROOT_DIR )
44
39
@cd $(ROOT_DIR ) /stackit && go tool cover -html=coverage.out -o coverage.html && cd $(ROOT_DIR )
45
40
46
41
test-acceptance-tf :
You can’t perform that action at this time.
0 commit comments