11---
2- # This action is centrally managed in https://github.com/<organization>/.github/
2+ # This workflow is centrally managed in https://github.com/<organization>/.github/
33# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
44# the above-mentioned repo.
55
66# This workflow will analyze all supported languages in the repository using CodeQL Analysis.
77
88name : " CodeQL"
9+ permissions :
10+ contents : read
911
1012on :
1113 push :
12- branches : ["master"]
14+ branches :
15+ - master
1316 pull_request :
14- branches : ["master"]
17+ branches :
18+ - master
1519 schedule :
1620 - cron : ' 00 12 * * 0' # every Sunday at 12:00 UTC
1721
@@ -22,14 +26,17 @@ concurrency:
2226jobs :
2327 languages :
2428 name : Get language matrix
25- runs-on : ubuntu-latest
2629 outputs :
2730 matrix : ${{ steps.lang.outputs.result }}
2831 continue : ${{ steps.continue.outputs.result }}
32+ runs-on : ubuntu-latest
2933 steps :
34+ - name : Checkout repository
35+ uses : actions/checkout@v4
36+
3037 - name : Get repo languages
31- uses : actions/github-script@v7
3238 id : lang
39+ uses : actions/github-script@v7
3340 with :
3441 script : |
3542 // CodeQL supports ['cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift']
@@ -51,32 +58,62 @@ jobs:
5158 "include": []
5259 }
5360
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+
5480 for (let [key, value] of Object.entries(response.data)) {
5581 // remap language
5682 if (remap_languages[key.toLowerCase()]) {
5783 console.log(`Remapping language: ${key} to ${remap_languages[key.toLowerCase()]}`)
5884 key = remap_languages[key.toLowerCase()]
5985 }
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}`)
6294 let osList = ['ubuntu-latest'];
63- if (key.toLowerCase() === 'swift') {
95+ if (normalizedKey === 'swift') {
6496 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'];
6999 }
70100 for (let os of osList) {
71101 // 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]}`
76108 }
77109
78110 // 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+ })
80117 }
81118 }
82119 }
87124 return matrix
88125
89126 - name : Continue
90- uses : actions/github-script@v7
91127 id : continue
128+ uses : actions/github-script@v7
92129 with :
93130 script : |
94131 // if matrix['include'] is an empty list return false, otherwise true
@@ -102,24 +139,22 @@ jobs:
102139
103140 analyze :
104141 name : Analyze (${{ matrix.name }})
105- if : ${{ needs.languages.outputs.continue == 'true' }}
142+ if : needs.languages.outputs.continue == 'true'
106143 defaults :
107144 run :
108145 shell : ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}
109146 env :
110147 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
114149 permissions :
115150 actions : read
116151 contents : read
117152 security-events : write
118-
153+ runs-on : ${{ matrix.os || 'ubuntu-latest' }}
119154 strategy :
120155 fail-fast : false
121156 matrix : ${{ fromJson(needs.languages.outputs.matrix) }}
122-
157+ timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
123158 steps :
124159 - name : Maximize build space
125160 if : >-
@@ -167,8 +202,7 @@ jobs:
167202 - third-party
168203
169204 # 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
172206 - name : Prebuild
173207 id : prebuild
174208 run : |
@@ -187,7 +221,7 @@ jobs:
187221 - name : Perform CodeQL Analysis
188222 uses : github/codeql-action/analyze@v3
189223 with :
190- category : " /language: ${{matrix.language }}"
224+ category : " ${{ matrix.category }}"
191225 output : sarif-results
192226 upload : failure-only
193227
@@ -204,11 +238,13 @@ jobs:
204238 - name : Upload SARIF
205239 uses : github/codeql-action/upload-sarif@v3
206240 with :
241+ category : " ${{ matrix.category }}"
207242 sarif_file : sarif-results/${{ matrix.language }}.sarif
208243
209244 - name : Upload loc as a Build Artifact
210245 uses : actions/upload-artifact@v4
211246 with :
212247 name : sarif-results-${{ matrix.language }}-${{ runner.os }}
213248 path : sarif-results
249+ if-no-files-found : error
214250 retention-days : 1
0 commit comments