From 6cd650614271480e16b8aec030c4099750c1f053 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Sun, 2 Jan 2022 22:50:31 +0100 Subject: [PATCH] GitHub-Actions: Only run SonarCloud when token is set Pull Requests often don't have the token (e.g. somebody outside of Songoda created it) --- .github/workflows/sonarcloud.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index c44caa10..5bd42b4a 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -10,21 +10,26 @@ jobs: build: name: Build runs-on: ubuntu-latest + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} steps: # Setup Java - uses: actions/setup-java@v2 + if: ${{ env.SONAR_TOKEN != null }} with: java-version: 17 distribution: adopt # Checkout project files - uses: actions/checkout@v2 + if: ${{ env.SONAR_TOKEN != null }} with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis # Caches - name: 'Cache: Maven' uses: actions/cache@v2 + if: ${{ env.SONAR_TOKEN != null }} with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -36,7 +41,7 @@ jobs: key: ${{ runner.os }}-sonar - name: Analyze project + if: ${{ env.SONAR_TOKEN != null }} run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=songoda_SongodaCore env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}