Skip to content

Commit

Permalink
Sonar Cloud analysis + coverage gathering (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
sievdokymov-virtru committed Sep 20, 2023
1 parent 8ddcdfc commit 3d1d52b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: SonarCloud
on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
gotest:
name: 'Generate Golang Test Reports'
runs-on: ubuntu-latest
permissions:
contents: read

steps:

- name: 'Checkout repo'
uses: actions/checkout@v3

- name: 'Setup Go'
uses: actions/setup-go@v3
with:
go-version: '${{ inputs.go-version }}'
cache: true

- name: 'Generate Golang Test Reports'
run: go test -v -coverprofile coverage.out -json ./... | tee coverage.json

- name: 'Archive Golang Test Results'
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: coverage.*
retention-days: 1

sonarcloud:
name: 'SonarCloud'
runs-on: ubuntu-latest
needs: [gotest]
permissions:
contents: read

steps:
- name: 'Checkout repo'
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 'Download Code Coverage Report'
uses: actions/download-artifact@v3
with:
name: code-coverage-report

- name: 'SonarCloud Scan'
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
17 changes: 17 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# must be unique in a given SonarQube instance
sonar.projectKey=opentdf_backend-go
sonar.organization=opentdf

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=pkg
sonar.exclusions=**/*_test.go,**/mock_*.go,cmd/*.go

sonar.tests=.
sonar.test.inclusions=**/*_test.go

sonar.go.coverage.reportPaths=coverage.out
sonar.go.tests.reportPaths=coverage.json

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

0 comments on commit 3d1d52b

Please sign in to comment.