diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml new file mode 100644 index 0000000..1ae7dbd --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -0,0 +1,56 @@ +--- +name: SonarCloud + +on: + push: + branches: + - main + pull_request: + paths: + - '**.go' + +permissions: read-all + +jobs: + generate-coverage: + name: Generate Coverage Report + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Run test + run: make test-unit + - name: Upload artifact + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: coverage + path: coverage.out + sonarcloud: + if: ${{ github.event.pull_request.base.repo.url == github.event.pull_request.head.repo.url }} + needs: generate-coverage + name: SonarCloud + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Get coverage + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: coverage + - name: SonarCloud Scan + uses: SonarSource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + "-Dsonar.go.coverage.reportPaths=coverage.out" + "-Dsonar.projectKey=rh-psce_complyctl" + "-Dsonar.organization=rh-psce" + - name: SonarQube Quality Gate check + uses: sonarsource/sonarqube-quality-gate-action@cf038b0e0cdecfa9e56c198bbb7d21d751d62c3b #v1.2.0 + # Force to fail step after specific time + timeout-minutes: 5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}