Skip to content

Commit c93120b

Browse files
committed
calculate coverage and report also from the other platforms
1 parent d63d5c8 commit c93120b

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

.github/workflows/test.yml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,71 @@ jobs:
3030

3131
- run: go version
3232

33-
# Checks-out repository under $GITHUB_WORKSPACE
34-
- name: Checkout
35-
if: ${{!startsWith(matrix.os, 'ubuntu')}}
36-
uses: actions/checkout@v4
37-
3833
# Checks-out repository under $GITHUB_WORKSPACE with tags and history (needed by "SonarCloud Scan" step)
3934
- name: Full checkout
40-
if: startsWith(matrix.os,'ubuntu')
4135
uses: actions/checkout@v4
4236
with:
4337
fetch-depth: 0 # Full clone for SonarCloud
4438

4539
# Build everything
4640
- name: Run a build
4741
run: go build ./...
42+
shell: bash
4843

4944
# Runs a single command using the runners shell, -p1 for `race: limit on 8128 simultaneously alive goroutines is exceeded, dying` at macos
5045
- name: Run a test
51-
run: go test -v -race ./... -coverpkg=./... -covermode=atomic -coverprofile=./coverage.txt
46+
run: go test -v -race ./... -coverpkg=./... -covermode=atomic -coverprofile=./coverage.txt -json > ./report.json
47+
shell: bash
48+
49+
- name: Dump test report
50+
if: always()
51+
run: cat ./report.json
52+
shell: bash
53+
54+
- name: Prepare upload files
55+
run: |
56+
mkdir -p ./outputs
57+
cp ./coverage.txt ./outputs/${{ matrix.os }}.coverage.txt
58+
cp ./report.json ./outputs/${{ matrix.os }}.report.json
59+
shell: bash
60+
61+
- name: Upload coverage and report files
62+
uses: actions/upload-artifact@v3
63+
with:
64+
name: ${{ hashFiles('./outputs') || 'none' }}
65+
path: ./outputs
66+
retention-days: 1
67+
if-no-files-found: warn
68+
69+
coverage-sonar-cloud-scan:
70+
needs: test
71+
# The type of runner that the job will run on
72+
runs-on: ubuntu-latest
73+
steps:
74+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
75+
- uses: actions/checkout@v4
76+
with:
77+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
78+
79+
- name: Download artifacts
80+
uses: actions/download-artifact@v3
81+
with:
82+
path: ./outputs
83+
84+
- name: Prepare coverage and report files
85+
run: |
86+
mkdir -p .tmp/coverage
87+
mkdir -p .tmp/report
88+
find ./outputs -name "*.coverage.txt" -exec sh -c 'cp $1 .tmp/coverage/$(echo $1 | sed "s/[\/.]/-/g" ).coverage.txt' _ {} \;
89+
find ./outputs -name "*.report.json" -exec sh -c 'cp $1 .tmp/report/$(echo $1 | sed "s/[\/.]/-/g" ).report.json' _ {} \;
5290
53-
# Skip this step when running from forked repository (no write privileges)
54-
- name: Publish the coverage
55-
if: startsWith(matrix.os,'ubuntu')
56-
run: bash <(curl -s https://codecov.io/bash)
91+
- name: Code coverage
92+
uses: codecov/codecov-action@v4.0.0-beta.3
93+
with:
94+
token: ${{ secrets.CODECOV_TOKEN }}
95+
directory: .tmp/
5796

58-
# Skip this step when running from forked repository (no access to ${{ secrets }})
5997
- name: SonarCloud Scan
60-
if: startsWith(matrix.os,'ubuntu')
6198
uses: SonarSource/sonarcloud-github-action@master
6299
env:
63100
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ sonar.test.exclusions=
2020
#wildcard do not work for tests.reportPaths
2121
#sonar.go.tests.reportPaths=.tmp/report/certificate-authority.report.json,.tmp/report/cloud2cloud-connector.report.json,.tmp/report/cloud2cloud-gateway.report.json,.tmp/report/coap-gateway.report.json,.tmp/report/grpc-gateway.report.json,.tmp/report/http-gateway.report.json,.tmp/report/identity-store.report.json,.tmp/report/resource-aggregate.report.json,.tmp/report/resource-directory.report.json
2222

23-
sonar.go.coverage.reportPaths=./coverage.txt
23+
sonar.go.coverage.reportPaths=.tmp/coverage/*.coverage.txt
2424
sonar.coverage.exclusions=examples/**,**/main.go,**/*.pb.go,**/*.pb.gw.go,**/*.js,**/*.py,**/*_test.go

0 commit comments

Comments
 (0)