Skip to content

Commit

Permalink
sonar cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeev-flexion committed May 24, 2024
1 parent 688fb66 commit 8c56091
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: SonarQube Analysis

on:
push: # Trigger on push to any branch
pull_request: # Trigger on pull request to any branch

jobs:
sonarQube:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.17'

- name: Cache Go modules
uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install SonarQube Scanner
run: |
curl -sSLo sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-linux.zip
unzip sonar-scanner.zip -d $HOME
export PATH="$HOME/sonar-scanner-4.6.2.2472-linux/bin:$PATH"
- name: Run tests and generate coverage
run: |
go test -v ./... -coverprofile=coverage.out
go tool cover -func=coverage.out
- name: SonarQube Scan
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
-Dsonar.projectKey=<your_project_key> \
-Dsonar.organization=<your_organization_key> \ # For SonarCloud only
-Dsonar.host.url=https://sonarcloud.io \ # Use your SonarQube URL if using SonarQube
-Dsonar.login=$SONAR_TOKEN \
-Dsonar.sources=. \
-Dsonar.tests=. \
-Dsonar.go.coverage.reportPaths=coverage.out

0 comments on commit 8c56091

Please sign in to comment.