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']
5461 // Track languages we've already added to avoid duplicates
5562 const addedLanguages = new Set()
5663
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+ "language": "actions",
74+ "os": "ubuntu-latest",
75+ "name": "actions"
76+ });
77+ }
78+
5779 for (let [key, value] of Object.entries(response.data)) {
5880 // remap language
5981 if (remap_languages[key.toLowerCase()]) {
94116 return matrix
95117
96118 - name : Continue
97- uses : actions/github-script@v7
98119 id : continue
120+ uses : actions/github-script@v7
99121 with :
100122 script : |
101123 // if matrix['include'] is an empty list return false, otherwise true
@@ -109,24 +131,22 @@ jobs:
109131
110132 analyze :
111133 name : Analyze (${{ matrix.name }})
112- if : ${{ needs.languages.outputs.continue == 'true' }}
134+ if : needs.languages.outputs.continue == 'true'
113135 defaults :
114136 run :
115137 shell : ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}
116138 env :
117139 GITHUB_CODEQL_BUILD : true
118- needs : [languages]
119- runs-on : ${{ matrix.os || 'ubuntu-latest' }}
120- timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
140+ needs : languages
121141 permissions :
122142 actions : read
123143 contents : read
124144 security-events : write
125-
145+ runs-on : ${{ matrix.os || 'ubuntu-latest' }}
126146 strategy :
127147 fail-fast : false
128148 matrix : ${{ fromJson(needs.languages.outputs.matrix) }}
129-
149+ timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
130150 steps :
131151 - name : Maximize build space
132152 if : >-
0 commit comments