Skip to content

Commit f93f31f

Browse files
committed
update security scan to run separate codeQL steps but only one Sonar scan step at the end, which combines files from previous codeQL scans
1 parent 3048fe3 commit f93f31f

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

.github/workflows/security-scan.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ jobs:
2020
analyze:
2121
name: Analyze (${{ matrix.language }})
2222
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
23-
env:
24-
# PRs for forks can't use secrets, can't upload to Sonar
25-
CAN_USE_SECRETS: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
2623
permissions:
2724
# required for all workflows
2825
security-events: write
@@ -117,17 +114,39 @@ jobs:
117114
name: codeql-artifacts-${{ matrix.language }}
118115
path: ${{ env.RESULTS_DIR }}
119116

117+
sonar:
118+
name: SonarQube Scan
119+
needs: analyze
120+
runs-on: ubuntu-latest
121+
# PRs for forks can't use secrets, can't upload to Sonar
122+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
123+
permissions:
124+
actions: read
125+
contents: read
126+
steps:
127+
- name: Checkout repository
128+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 #v4.3.1
129+
with:
130+
fetch-depth: 0
131+
132+
- name: Download CodeQL Artifacts
133+
uses: actions/download-artifact@v4
134+
with:
135+
pattern: codeql-artifacts-*
136+
path: codeql-results
137+
120138
- name: collect stripped .sarif file paths
121-
if: env.CAN_USE_SECRETS == 'true'
122139
shell: bash
123140
run: |
124-
sarif_paths="$(find "${{ github.workspace }}/../results" -name '*_stripped.sarif' -type f | paste -sd, -)"
141+
echo "downloaded CodeQL artifact files:"
142+
find "${{ github.workspace }}/codeql-results" -type f | sort
143+
144+
sarif_paths="$(find "${{ github.workspace }}/codeql-results" -name '*_stripped.sarif' -type f | paste -sd, -)"
125145
echo "sarif paths: $sarif_paths"
126146
test -n "$sarif_paths"
127147
echo "SARIF_REPORT_PATHS=$sarif_paths" >> "$GITHUB_ENV"
128148
129149
- name: SonarQube Scan
130-
if: env.CAN_USE_SECRETS == 'true'
131150
uses: SonarSource/sonarqube-scan-action@7006c4492b2e0ee0f816d36501671557c97f5995 # v8.1.0
132151
env:
133152
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

0 commit comments

Comments
 (0)