File tree Expand file tree Collapse file tree 3 files changed +33
-9
lines changed Expand file tree Collapse file tree 3 files changed +33
-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,38 @@ 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 : Move code coverage report
40
+ if : ${{ github.event_name == 'pull_request' }}
41
+ run : mv stackit/${{env.CODE_COVERAGE_FILE_NAME}} .
42
+
43
+ - name : Upload code coverage results
44
+ if : ${{ github.event_name == 'pull_request' }}
45
+ uses : actions/upload-artifact@v4
46
+ with :
47
+ name : ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
48
+ path : ${{ env.CODE_COVERAGE_FILE_NAME }}
49
+
50
+ code_coverage :
51
+ name : " Code coverage report"
52
+ if : ${{ github.event_name == 'pull_request' }}
53
+ runs-on : ubuntu-latest
54
+ needs : [main]
55
+ permissions :
56
+ contents : read
57
+ actions : read # to download code coverage results from "test" job
58
+ pull-requests : write # write permission needed to comment on PR
59
+ steps :
60
+ - name : Add code coverage report comment to PR
61
+ uses : fgrosse/go-coverage-report@v1.2.0
62
+ with :
63
+ coverage-artifact-name : ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
64
+ coverage-file-name : ${{ env.CODE_COVERAGE_FILE_NAME }}
65
+
36
66
config :
37
67
name : Check GoReleaser config
38
68
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