Skip to content

Commit

Permalink
calculate coverage and report also from the other platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Nov 15, 2023
1 parent d63d5c8 commit c93120b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
63 changes: 50 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,71 @@ jobs:

- run: go version

# Checks-out repository under $GITHUB_WORKSPACE
- name: Checkout
if: ${{!startsWith(matrix.os, 'ubuntu')}}
uses: actions/checkout@v4

# Checks-out repository under $GITHUB_WORKSPACE with tags and history (needed by "SonarCloud Scan" step)
- name: Full checkout
if: startsWith(matrix.os,'ubuntu')
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full clone for SonarCloud

# Build everything
- name: Run a build
run: go build ./...
shell: bash

# Runs a single command using the runners shell, -p1 for `race: limit on 8128 simultaneously alive goroutines is exceeded, dying` at macos
- name: Run a test
run: go test -v -race ./... -coverpkg=./... -covermode=atomic -coverprofile=./coverage.txt
run: go test -v -race ./... -coverpkg=./... -covermode=atomic -coverprofile=./coverage.txt -json > ./report.json
shell: bash

- name: Dump test report
if: always()
run: cat ./report.json
shell: bash

- name: Prepare upload files
run: |
mkdir -p ./outputs
cp ./coverage.txt ./outputs/${{ matrix.os }}.coverage.txt
cp ./report.json ./outputs/${{ matrix.os }}.report.json
shell: bash

- name: Upload coverage and report files
uses: actions/upload-artifact@v3
with:
name: ${{ hashFiles('./outputs') || 'none' }}
path: ./outputs
retention-days: 1
if-no-files-found: warn

coverage-sonar-cloud-scan:
needs: test
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./outputs

- name: Prepare coverage and report files
run: |
mkdir -p .tmp/coverage
mkdir -p .tmp/report
find ./outputs -name "*.coverage.txt" -exec sh -c 'cp $1 .tmp/coverage/$(echo $1 | sed "s/[\/.]/-/g" ).coverage.txt' _ {} \;
find ./outputs -name "*.report.json" -exec sh -c 'cp $1 .tmp/report/$(echo $1 | sed "s/[\/.]/-/g" ).report.json' _ {} \;
# Skip this step when running from forked repository (no write privileges)
- name: Publish the coverage
if: startsWith(matrix.os,'ubuntu')
run: bash <(curl -s https://codecov.io/bash)
- name: Code coverage
uses: codecov/codecov-action@v4.0.0-beta.3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: .tmp/

# Skip this step when running from forked repository (no access to ${{ secrets }})
- name: SonarCloud Scan
if: startsWith(matrix.os,'ubuntu')
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ sonar.test.exclusions=
#wildcard do not work for tests.reportPaths
#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

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

0 comments on commit c93120b

Please sign in to comment.