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)
This commit is contained in:
Christian Koop 2022-01-02 22:50:31 +01:00
parent b375c6b2be
commit 6cd6506142
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3

View File

@ -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 }}