Skip to content

Commit 283feb3

Browse files
committed
Run SonarCloud analysis only when SONAR_TOKEN is available (#195)
Forked repositories don't have access to the `SONAR_TOKEN` secret and thus cannot run the SonarCloud analysis as part of the build. Refs #184
1 parent acaeaae commit 283feb3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

.github/workflows/maven.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ jobs:
4141
${{ runner.os }}-maven-
4242
- name: Cache SonarCloud packages
4343
uses: actions/cache@v2.1.3
44-
if: matrix.java_version == '11'
44+
if: ${{ env.SONAR_TOKEN != null && env.SONAR_TOKEN != '' && matrix.java_version == '11' }}
45+
env:
46+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4547
with:
4648
path: ~/.sonar/cache
4749
key: ${{ runner.os }}-sonar
4850
restore-keys: ${{ runner.os }}-sonar
4951
- name: Run tests
5052
run: ./mvnw -V -B -ntp -ff verify jacoco:report
5153
- name: Static Analysis (Sonar)
52-
if: matrix.java_version == '11'
54+
if: ${{ env.SONAR_TOKEN != null && env.SONAR_TOKEN != '' && matrix.java_version == '11' }}
5355
env:
5456
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5557
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/pr.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ jobs:
3434
${{ runner.os }}-maven-
3535
- name: Cache SonarCloud packages
3636
uses: actions/cache@v2.1.3
37-
if: matrix.java_version == '11'
37+
if: ${{ env.SONAR_TOKEN != null && env.SONAR_TOKEN != '' && matrix.java_version == '11' }}
38+
env:
39+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3840
with:
3941
path: ~/.sonar/cache
4042
key: ${{ runner.os }}-sonar
4143
restore-keys: ${{ runner.os }}-sonar
4244
- name: Run tests
4345
run: ./mvnw -V -B -ntp -ff verify
4446
- name: Static Analysis (Sonar)
45-
if: matrix.java_version == '11'
47+
if: ${{ env.SONAR_TOKEN != null && env.SONAR_TOKEN != '' && matrix.java_version == '11' }}
4648
env:
4749
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4850
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

0 commit comments

Comments
 (0)