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
+ "language": "actions",
74
+ "os": "ubuntu-latest",
75
+ "name": "actions"
76
+ });
77
+ }
78
+
57
79
for (let [key, value] of Object.entries(response.data)) {
58
80
// remap language
59
81
if (remap_languages[key.toLowerCase()]) {
94
116
return matrix
95
117
96
118
- name : Continue
97
- uses : actions/github-script@v7
98
119
id : continue
120
+ uses : actions/github-script@v7
99
121
with :
100
122
script : |
101
123
// if matrix['include'] is an empty list return false, otherwise true
@@ -109,24 +131,22 @@ jobs:
109
131
110
132
analyze :
111
133
name : Analyze (${{ matrix.name }})
112
- if : ${{ needs.languages.outputs.continue == 'true' }}
134
+ if : needs.languages.outputs.continue == 'true'
113
135
defaults :
114
136
run :
115
137
shell : ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}
116
138
env :
117
139
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
121
141
permissions :
122
142
actions : read
123
143
contents : read
124
144
security-events : write
125
-
145
+ runs-on : ${{ matrix.os || 'ubuntu-latest' }}
126
146
strategy :
127
147
fail-fast : false
128
148
matrix : ${{ fromJson(needs.languages.outputs.matrix) }}
129
-
149
+ timeout-minutes : ${{ (matrix.language == 'swift' && 120) || 360 }}
130
150
steps :
131
151
- name : Maximize build space
132
152
if : >-
0 commit comments