1
1
---
2
- # This action is centrally managed in https://github.com/<organization>/.github/
2
+ # This workflow is centrally managed in https://github.com/<organization>/.github/
3
3
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
4
4
# the above-mentioned repo.
5
5
6
6
# This workflow will analyze all supported languages in the repository using CodeQL Analysis.
7
7
8
8
name : " CodeQL"
9
+ permissions :
10
+ contents : read
9
11
10
12
on :
11
13
push :
12
- branches : ["master"]
14
+ branches :
15
+ - master
13
16
pull_request :
14
- branches : ["master"]
17
+ branches :
18
+ - master
15
19
schedule :
16
20
- cron : ' 00 12 * * 0' # every Sunday at 12:00 UTC
17
21
@@ -22,14 +26,17 @@ concurrency:
22
26
jobs :
23
27
languages :
24
28
name : Get language matrix
25
- runs-on : ubuntu-latest
26
29
outputs :
27
30
matrix : ${{ steps.lang.outputs.result }}
28
31
continue : ${{ steps.continue.outputs.result }}
32
+ runs-on : ubuntu-latest
29
33
steps :
34
+ - name : Checkout repository
35
+ uses : actions/checkout@v4
36
+
30
37
- name : Get repo languages
31
- uses : actions/github-script@v7
32
38
id : lang
39
+ uses : actions/github-script@v7
33
40
with :
34
41
script : |
35
42
// CodeQL supports ['cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift']
54
61
// Track languages we've already added to avoid duplicates
55
62
const addedLanguages = new Set()
56
63
64
+ // Check if workflow files exist to determine if we should add actions language
65
+ const fs = require('fs');
66
+ const hasYmlFiles = fs.existsSync('.github/workflows') &&
67
+ fs.readdirSync('.github/workflows').some(file => file.endsWith('.yml') || file.endsWith('.yaml'));
68
+
69
+ // Add actions language if workflow files exist
70
+ if (hasYmlFiles) {
71
+ console.log('Found GitHub Actions workflow files. Adding actions to the matrix.');
72
+ matrix['include'].push({
73
+ "category": "/language:actions",
74
+ "language": "actions",
75
+ "name": "actions",
76
+ "os": "ubuntu-latest"
77
+ });
78
+ }
79
+
57
80
for (let [key, value] of Object.entries(response.data)) {
58
81
// remap language
59
82
if (remap_languages[key.toLowerCase()]) {
@@ -78,11 +101,18 @@ jobs:
78
101
// set name for matrix
79
102
let name = osList.length === 1 ? normalizedKey : `${normalizedKey}, ${os}`
80
103
104
+ // set category for matrix
105
+ let category = `/language:${normalizedKey}`
106
+ if (normalizedKey === 'cpp') {
107
+ category = `/language:cpp-${os.split('-')[0]}`
108
+ }
109
+
81
110
// add to matrix
82
111
matrix['include'].push({
112
+ "category": category,
83
113
"language": normalizedKey,
84
- "os ": os ,
85
- "name ": name
114
+ "name ": name ,
115
+ "os ": os
86
116
})
87
117
}
88
118
}
94
124
return matrix
95
125
96
126
- name : Continue
97
- uses : actions/github-script@v7
98
127
id : continue
128
+ uses : actions/github-script@v7
99
129
with :
100
130
script : |
101
131
// if matrix['include'] is an empty list return false, otherwise true
@@ -109,24 +139,22 @@ jobs:
109
139
110
140
analyze :
111
141
name : Analyze (${{ matrix.name }})
112
- if : ${{ needs.languages.outputs.continue == 'true' }}
142
+ if : needs.languages.outputs.continue == 'true'
113
143
defaults :
114
144
run :
115
145
shell : ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}
116
146
env :
117
147
GITHUB_CODEQL_BUILD : true
118
- needs : [languages]
119
- runs-on : ${{ matrix.os || 'ubuntu-latest' }}
120
- timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
148
+ needs : languages
121
149
permissions :
122
150
actions : read
123
151
contents : read
124
152
security-events : write
125
-
153
+ runs-on : ${{ matrix.os || 'ubuntu-latest' }}
126
154
strategy :
127
155
fail-fast : false
128
156
matrix : ${{ fromJson(needs.languages.outputs.matrix) }}
129
-
157
+ timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
130
158
steps :
131
159
- name : Maximize build space
132
160
if : >-
@@ -174,8 +202,7 @@ jobs:
174
202
- third-party
175
203
176
204
# Pre autobuild
177
- # create a file named .codeql-prebuild-${{ matrix.language }}.sh in the root of your repository
178
- # create a file named .codeql-build-${{ matrix.language }}.sh in the root of your repository
205
+ # create a file named .codeql-prebuild-${{ matrix.language }}-${{ runner.os }}.sh in the root of your repository
179
206
- name : Prebuild
180
207
id : prebuild
181
208
run : |
@@ -194,7 +221,7 @@ jobs:
194
221
- name : Perform CodeQL Analysis
195
222
uses : github/codeql-action/analyze@v3
196
223
with :
197
- category : " /language: ${{matrix.language }}"
224
+ category : " ${{ matrix.category }}"
198
225
output : sarif-results
199
226
upload : failure-only
200
227
@@ -211,11 +238,13 @@ jobs:
211
238
- name : Upload SARIF
212
239
uses : github/codeql-action/upload-sarif@v3
213
240
with :
241
+ category : " ${{ matrix.category }}"
214
242
sarif_file : sarif-results/${{ matrix.language }}.sarif
215
243
216
244
- name : Upload loc as a Build Artifact
217
245
uses : actions/upload-artifact@v4
218
246
with :
219
247
name : sarif-results-${{ matrix.language }}-${{ runner.os }}
220
248
path : sarif-results
249
+ if-no-files-found : error
221
250
retention-days : 1
0 commit comments