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']
@@ -51,32 +58,62 @@ jobs:
51
58
"include": []
52
59
}
53
60
61
+ // Track languages we've already added to avoid duplicates
62
+ const addedLanguages = new Set()
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
+
54
80
for (let [key, value] of Object.entries(response.data)) {
55
81
// remap language
56
82
if (remap_languages[key.toLowerCase()]) {
57
83
console.log(`Remapping language: ${key} to ${remap_languages[key.toLowerCase()]}`)
58
84
key = remap_languages[key.toLowerCase()]
59
85
}
60
- if (supported_languages.includes(key.toLowerCase())) {
61
- console.log(`Found supported language: ${key}`)
86
+
87
+ const normalizedKey = key.toLowerCase()
88
+
89
+ if (supported_languages.includes(normalizedKey) && !addedLanguages.has(normalizedKey)) {
90
+ // Mark this language as added
91
+ addedLanguages.add(normalizedKey)
92
+
93
+ console.log(`Found supported language: ${normalizedKey}`)
62
94
let osList = ['ubuntu-latest'];
63
- if (key.toLowerCase() === 'swift') {
95
+ if (normalizedKey === 'swift') {
64
96
osList = ['macos-latest'];
65
- } else if (key.toLowerCase() === 'cpp') {
66
- // TODO: update macos to latest after the below issue is resolved
67
- // https://github.com/github/codeql-action/issues/2266
68
- osList = ['macos-13', 'ubuntu-latest', 'windows-latest'];
97
+ } else if (normalizedKey === 'cpp') {
98
+ osList = ['macos-latest', 'ubuntu-latest', 'windows-latest'];
69
99
}
70
100
for (let os of osList) {
71
101
// set name for matrix
72
- if (osList.length == 1) {
73
- name = key.toLowerCase()
74
- } else {
75
- name = `${key.toLowerCase()}, ${os}`
102
+ let name = osList.length === 1 ? normalizedKey : `${normalizedKey}, ${os}`
103
+
104
+ // set category for matrix
105
+ let category = `/language:${normalizedKey}`
106
+ if (normalizedKey === 'cpp') {
107
+ category = `/language:cpp-${os.split('-')[0]}`
76
108
}
77
109
78
110
// add to matrix
79
- matrix['include'].push({"language": key.toLowerCase(), "os": os, "name": name})
111
+ matrix['include'].push({
112
+ "category": category,
113
+ "language": normalizedKey,
114
+ "name": name,
115
+ "os": os
116
+ })
80
117
}
81
118
}
82
119
}
87
124
return matrix
88
125
89
126
- name : Continue
90
- uses : actions/github-script@v7
91
127
id : continue
128
+ uses : actions/github-script@v7
92
129
with :
93
130
script : |
94
131
// if matrix['include'] is an empty list return false, otherwise true
@@ -102,24 +139,22 @@ jobs:
102
139
103
140
analyze :
104
141
name : Analyze (${{ matrix.name }})
105
- if : ${{ needs.languages.outputs.continue == 'true' }}
142
+ if : needs.languages.outputs.continue == 'true'
106
143
defaults :
107
144
run :
108
145
shell : ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}
109
146
env :
110
147
GITHUB_CODEQL_BUILD : true
111
- needs : [languages]
112
- runs-on : ${{ matrix.os || 'ubuntu-latest' }}
113
- timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
148
+ needs : languages
114
149
permissions :
115
150
actions : read
116
151
contents : read
117
152
security-events : write
118
-
153
+ runs-on : ${{ matrix.os || 'ubuntu-latest' }}
119
154
strategy :
120
155
fail-fast : false
121
156
matrix : ${{ fromJson(needs.languages.outputs.matrix) }}
122
-
157
+ timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
123
158
steps :
124
159
- name : Maximize build space
125
160
if : >-
@@ -167,8 +202,7 @@ jobs:
167
202
- third-party
168
203
169
204
# Pre autobuild
170
- # create a file named .codeql-prebuild-${{ matrix.language }}.sh in the root of your repository
171
- # 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
172
206
- name : Prebuild
173
207
id : prebuild
174
208
run : |
@@ -187,7 +221,7 @@ jobs:
187
221
- name : Perform CodeQL Analysis
188
222
uses : github/codeql-action/analyze@v3
189
223
with :
190
- category : " /language: ${{matrix.language }}"
224
+ category : " ${{ matrix.category }}"
191
225
output : sarif-results
192
226
upload : failure-only
193
227
@@ -204,11 +238,13 @@ jobs:
204
238
- name : Upload SARIF
205
239
uses : github/codeql-action/upload-sarif@v3
206
240
with :
241
+ category : " ${{ matrix.category }}"
207
242
sarif_file : sarif-results/${{ matrix.language }}.sarif
208
243
209
244
- name : Upload loc as a Build Artifact
210
245
uses : actions/upload-artifact@v4
211
246
with :
212
247
name : sarif-results-${{ matrix.language }}-${{ runner.os }}
213
248
path : sarif-results
249
+ if-no-files-found : error
214
250
retention-days : 1
0 commit comments