-
-
Notifications
You must be signed in to change notification settings - Fork 592
161 lines (140 loc) · 5 KB
/
codeql-analysis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ main ]
paths:
- '.github/workflows/codeql-analysis.yml'
- 'scripts/*.py'
- 'archive/c/c/*.c'
- 'archive/c/c-plus-plus/*.cpp'
- 'archive/c/c-sharp/*.cs'
- 'archive/g/go/*.go'
- 'archive/j/java/*.java'
- 'archive/j/javascript/*.js'
- 'archive/k/kotlin/*.kt'
- 'archive/p/python/*.py'
- 'archive/r/ruby/*.rb'
- 'archive/s/swift/*.swift'
- 'archive/t/typescript/*.ts'
pull_request:
branches:
- 'main'
paths:
- '.github/workflows/codeql-analysis.yml'
- 'scripts/*.py'
- 'archive/c/c/*.c'
- 'archive/c/c-plus-plus/*.cpp'
- 'archive/c/c-sharp/*.cs'
- 'archive/g/go/*.go'
- 'archive/j/java/*.java'
- 'archive/j/javascript/*.js'
- 'archive/k/kotlin/*.kt'
- 'archive/p/python/*.py'
- 'archive/r/ruby/*.rb'
- 'archive/s/swift/*.swift'
- 'archive/t/typescript/*.ts'
schedule:
# Run every Thursday at 4:53 UTC (randomly chosen)
- cron: '53 4 * * 6'
jobs:
# We need this job to check if changed files should trigger analysis
changed-files:
name: "Changed Files"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
changed-files: ${{ steps.changed-files.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get changed code files
id: changed-files
uses: tj-actions/changed-files@v45
- name: List all relevant changed files
if: steps.changed-files.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed"
done
# Reference: https://stackoverflow.com/questions/65384420/how-do-i-make-a-github-action-matrix-element-conditional
- name: Get CodeQL Languages
id: set-matrix
run: |
matrix=$(python scripts/get_codeql_languages.py --event ${{ github.event_name}} ${{ steps.changed-files.outputs.all_changed_files }})
echo "${matrix}"
echo "matrix={\"include\": ${matrix}}" >> $GITHUB_OUTPUT
analyze:
name: Analyze
needs: changed-files
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.changed-files.outputs.matrix) }}
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Install Java 23
if: ${{ matrix.language == 'java' }}
uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '23'
- name: Install C# compiler
if: ${{ matrix.language == 'c#' }}
run: sudo apt-get update && sudo apt-get install -y mono-mcs
- name: Remove ignored paths
if: ${{ github.event_name == 'pull_request' }}
run: rm -f ${{ matrix.paths-ignore }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Run Poetry Image
uses: abatilo/actions-poetry@v3
with:
poetry-version: "1.8.5"
- name: Install Dependencies
run: poetry install
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
if: ${{ matrix.build-mode != 'manual' }}
uses: github/codeql-action/autobuild@v3
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
- name: Manual build
if: ${{ matrix.build-mode == 'manual' }}
run: poetry run python scripts/build_codeql_language.py ${{ matrix.language }} ${{ matrix.paths }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3