Skip to content

Commit 4357090

Browse files
Only run Sonar when tokens exist
1 parent 9eedc67 commit 4357090

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

.github/workflows/sonar.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,30 @@ on:
1111
pull_request:
1212
types: [opened, synchronize, reopened]
1313
jobs:
14+
sonarCheck:
15+
name: SonarQube config check
16+
runs-on: ubuntu-latest
17+
outputs:
18+
enabled: ${{ steps.check.outputs.enabled }}
19+
steps:
20+
- id: check
21+
env:
22+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
23+
SONAR_HOST_URL: ${{ secrets.SONAR_HOST }}
24+
run: |
25+
if [ -n "$SONAR_TOKEN" ] && [ -n "$SONAR_HOST_URL" ]; then
26+
echo "enabled=true" >> "$GITHUB_OUTPUT"
27+
echo "SonarQube secrets detected; scans will run."
28+
else
29+
echo "enabled=false" >> "$GITHUB_OUTPUT"
30+
echo "SonarQube secrets not configured; skipping scans."
31+
fi
32+
1433
sonarQubeServer:
1534
name: SonarQube Server
1635
runs-on: ubuntu-latest
36+
needs: sonarCheck
37+
if: ${{ needs.sonarCheck.outputs.enabled == 'true' }}
1738
steps:
1839
- uses: actions/checkout@v4
1940
with:
@@ -45,6 +66,8 @@ jobs:
4566
sonarQubeFrontend:
4667
name: sonarQube Frontend
4768
runs-on: ubuntu-latest
69+
needs: sonarCheck
70+
if: ${{ needs.sonarCheck.outputs.enabled == 'true' }}
4871
steps:
4972
- uses: actions/checkout@v4
5073
with:
@@ -68,6 +91,8 @@ jobs:
6891
sonarQubeScreenshot:
6992
name: SonarQube Screenshot
7093
runs-on: ubuntu-latest
94+
needs: sonarCheck
95+
if: ${{ needs.sonarCheck.outputs.enabled == 'true' }}
7196
steps:
7297
- uses: actions/checkout@v4
7398
with:

0 commit comments

Comments
 (0)