Commit af4f6f4ee6967ca5c7e54312034e3c0f564dfc5c
Committed by
GitHub
1 parent
5081bc92
chore(ci): check SONAR_TOKEN exists before executing SonarCloud (#19)
Showing
1 changed file
with
25 additions
and
1 deletions
.github/workflows/sonarcloud.yaml
| @@ -6,10 +6,34 @@ on: | @@ -6,10 +6,34 @@ on: | ||
| 6 | - main | 6 | - main |
| 7 | 7 | ||
| 8 | jobs: | 8 | jobs: |
| 9 | + has_sonar_token: | ||
| 10 | + name: Check for SonarCloud token | ||
| 11 | + runs-on: ubuntu-latest | ||
| 12 | + | ||
| 13 | + outputs: | ||
| 14 | + ok: ${{ steps.check.outputs.ok }} | ||
| 15 | + | ||
| 16 | + steps: | ||
| 17 | + - name: Check for SonarCloud token | ||
| 18 | + id: check | ||
| 19 | + run: | | ||
| 20 | + if [ -n "${{ secrets.SONAR_TOKEN }}" ]; | ||
| 21 | + then | ||
| 22 | + echo "ok=true" >> $GITHUB_OUTPUT; | ||
| 23 | + echo "SONAR_TOKEN secret detected, running Code Quality." | ||
| 24 | + else | ||
| 25 | + echo "ok=false" >> $GITHUB_OUTPUT; | ||
| 26 | + echo "No SONAR_TOKEN secret detected, skipping Code Quality." | ||
| 27 | + fi | ||
| 28 | + | ||
| 9 | code_quality: | 29 | code_quality: |
| 10 | - name: Code quality | 30 | + name: Code quality (SonarCloud) |
| 11 | runs-on: ubuntu-latest | 31 | runs-on: ubuntu-latest |
| 12 | 32 | ||
| 33 | + # This prevents running SonarCloud on forks that don't have a SONAR_TOKEN set. | ||
| 34 | + needs: has_sonar_token | ||
| 35 | + if: needs.has_sonar_token.outputs.ok == 'true' | ||
| 36 | + | ||
| 13 | env: | 37 | env: |
| 14 | SONAR_SCANNER_VERSION: 4.7.0.2747 | 38 | SONAR_SCANNER_VERSION: 4.7.0.2747 |
| 15 | 39 |