diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 0000000..3eeafd2 --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,65 @@ +name: Sonarqube + +on: + pull_request: + types: [opened, synchronize, reopened] + branches: + - main + + workflow_dispatch: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + permissions: # permission to comment a PR + contents: read + pull-requests: write + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - uses: sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + + # If you wish to fail your job when the Quality Gate is red, uncomment the following lines. + # Check the Quality Gate status. + # - name: SonarQube Quality Gate check + # id: sonarqube-quality-gate-check + # uses: sonarsource/sonarqube-quality-gate-action@master + # # #Enforce a timeout to fail the step after a specific time. + # timeout-minutes: 5 + # env: + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + # SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} # OPTIONAL + + # PR Decoration + - name: SonarQube Pull Request Comment + if: always() + uses: campos-pay/sonarqube-pr-comment@main + with: + sonar_token: ${{ secrets.SONAR_TOKEN }} + sonar_host_url: ${{ secrets.SONAR_HOST_URL }} + sonar_projectkey: ${{ vars.SONAR_PROJECT_KEY }} #github.event.repository.name + github-token: ${{ secrets.GITHUB_TOKEN }} + repo_name: ${{ github.repository }} + pr_number: ${{ github.event.pull_request.number }} + + - uses: phwt/sonarqube-quality-gate-action@v1 + id: quality-gate-check + with: + sonar-project-key: ${{ vars.SONAR_PROJECT_KEY }} + sonar-host-url: ${{ secrets.SONAR_HOST_URL }} + sonar-token: ${{ secrets.SONAR_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} #PR_GITHUB_TOKEN + + - name: Output result + run: | + echo "${{ steps.quality-gate-check.outputs.project-status }}" + echo "${{ steps.quality-gate-check.outputs.quality-gate-result }}" + diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..493b7f3 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,2 @@ + +sonar.projectKey=sparrow-app-auth \ No newline at end of file