From af4f6f4ee6967ca5c7e54312034e3c0f564dfc5c Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 29 Oct 2022 10:51:16 +0200 Subject: [PATCH] chore(ci): check SONAR_TOKEN exists before executing SonarCloud (#19) --- .github/workflows/sonarcloud.yaml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yaml b/.github/workflows/sonarcloud.yaml index 20da6a6..02ae68d 100644 --- a/.github/workflows/sonarcloud.yaml +++ b/.github/workflows/sonarcloud.yaml @@ -6,10 +6,34 @@ on: - main jobs: + has_sonar_token: + name: Check for SonarCloud token + runs-on: ubuntu-latest + + outputs: + ok: ${{ steps.check.outputs.ok }} + + steps: + - name: Check for SonarCloud token + id: check + run: | + if [ -n "${{ secrets.SONAR_TOKEN }}" ]; + then + echo "ok=true" >> $GITHUB_OUTPUT; + echo "SONAR_TOKEN secret detected, running Code Quality." + else + echo "ok=false" >> $GITHUB_OUTPUT; + echo "No SONAR_TOKEN secret detected, skipping Code Quality." + fi + code_quality: - name: Code quality + name: Code quality (SonarCloud) runs-on: ubuntu-latest + # This prevents running SonarCloud on forks that don't have a SONAR_TOKEN set. + needs: has_sonar_token + if: needs.has_sonar_token.outputs.ok == 'true' + env: SONAR_SCANNER_VERSION: 4.7.0.2747 -- libgit2 0.21.4