Skip to content

Commit b8173bc

Browse files
committed
Run SonarCloud analysis only when SONAR_TOKEN is available
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 af79856 commit b8173bc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.github/workflows/maven.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
restore-keys: |
4141
${{ runner.os }}-maven-
4242
- name: Cache SonarCloud packages
43+
if: ${{ env.SONAR_TOKEN != null && env.SONAR_TOKEN != '' && matrix.java_version == '11' }}
44+
env:
45+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4346
uses: actions/[email protected]
4447
if: matrix.java_version == '11'
4548
with:
@@ -49,7 +52,7 @@ jobs:
4952
- name: Run tests
5053
run: ./mvnw -V -B -ntp -ff verify jacoco:report
5154
- name: Static Analysis (Sonar)
52-
if: matrix.java_version == '11'
55+
if: ${{ env.SONAR_TOKEN != null && env.SONAR_TOKEN != '' && matrix.java_version == '11' }}
5356
env:
5457
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5558
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/pr.yml

+4-2
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/[email protected]
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)