diff --git a/.gitea/workflows/sonarqube.yml b/.gitea/workflows/sonarqube.yml index dc03a14..77d4cf4 100644 --- a/.gitea/workflows/sonarqube.yml +++ b/.gitea/workflows/sonarqube.yml @@ -24,10 +24,30 @@ jobs: run: go mod tidy - name: Run tests with coverage - run: go test ./... -coverprofile=coverage + run: go test ./... -coverprofile=coverage -json > test-results.json + + - name: Set SonarQube project key + run: | + BRANCH_NAME=${GITHUB_REF#refs/heads/} + if [ "$BRANCH_NAME" = "main" ]; then + SONAR_PROJECT_KEY="tunnel-please" + else + BRANCH_KEY=${BRANCH_NAME//\//-} + SONAR_PROJECT_KEY="tunnel-please-$BRANCH_KEY" + fi + echo "SONAR_PROJECT_KEY=tunnel-please-$BRANCH_KEY" >> $GITHUB_ENV + echo "Using SonarQube Project Key: $SONAR_PROJECT_KEY" - name: SonarQube Scan uses: SonarSource/sonarqube-scan-action@v7.0.0 env: SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }} SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} + with: + args: > + -Dsonar.projectKey=${{ env.SONAR_PROJECT_KEY }} + -Dsonar.go.coverage.reportPaths=coverage + -Dsonar.test.inclusions=**/*_test.go + -Dsonar.test.exclusions=**/vendor/** + -Dsonar.exclusions=**/*_test.go,**/vendor/** + -Dsonar.go.tests.reportPaths=test-results.json \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6c907a9..fd6e5af 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ id_rsa* tmp certs app -coverage \ No newline at end of file +coverage +test-results.json \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index 626044d..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,3 +0,0 @@ -sonar.projectKey=tunnel-please -sonar.go.coverage.reportPaths=coverage -sonar.test.inclusions=**/*_test.go \ No newline at end of file