Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
codeql-coding-standards/.github/workflows/codeql_unit_tests.yml at main · github/codeql-coding-standards · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
github
codeql-coding-standards
Repository navigation
Code
Issues
116
(116)
Pull requests
28
(28)
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
codeql-coding-standards
/
.github
/
workflows
/
codeql_unit_tests.yml
Copy path
View runs
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
206 lines (182 loc) · 7.87 KB
main
Breadcrumbs
codeql-coding-standards
/
.github
/
workflows
/
codeql_unit_tests.yml
Copy path
Top
File metadata and controls
Code
Blame
206 lines (182 loc) · 7.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name
:
CodeQL Unit Testing
permissions
:
contents
:
read
on
:
merge_group
:
types
:
[checks_requested]
push
:
branches
:
-
main
-
next
-
"
rc/**
"
pull_request
:
branches
:
-
main
-
next
-
"
rc/**
"
jobs
:
prepare-unit-test-matrix
:
name
:
Prepare CodeQL unit test matrix
runs-on
:
ubuntu-22.04
outputs
:
matrix
:
${{ steps.export-unit-test-matrix.outputs.matrix }}
steps
:
-
name
:
Checkout repository
uses
:
actions/checkout@v6
-
name
:
Export unit test matrix
id
:
export-unit-test-matrix
run
:
|
echo "Merging Result:"
python scripts/create_language_matrix.py
echo "matrix=$(
python scripts/create_language_matrix.py | \
jq --compact-output 'map([.+{os: "ubuntu-latest-xl", codeql_standard_library_ident : .codeql_standard_library | sub("\/"; "_")}]) | flatten | {include: .}')" >> $GITHUB_OUTPUT
run-test-suites
:
name
:
Run unit tests
needs
:
prepare-unit-test-matrix
runs-on
:
${{ matrix.os }}
strategy
:
fail-fast
:
false
matrix
:
${{ fromJSON(needs.prepare-unit-test-matrix.outputs.matrix) }}
steps
:
-
name
:
Checkout repository
uses
:
actions/checkout@v6
-
name
:
Install Python
uses
:
actions/setup-python@v6
with
:
python-version
:
"
3.9
"
-
name
:
Install Python dependencies
run
:
pip install -r scripts/requirements.txt
-
name
:
Cache CodeQL
id
:
cache-codeql
uses
:
actions/cache@v6
with
:
#
A list of files, directories, and wildcard patterns to cache and restore
path
:
${{github.workspace}}/codeql_home
#
An explicit key for restoring and saving the cache
key
:
codeql-home-${{matrix.os}}-${{matrix.codeql_cli}}-${{matrix.codeql_standard_library}}
-
name
:
Install CodeQL
if
:
steps.cache-codeql.outputs.cache-hit != 'true'
uses
:
./.github/actions/install-codeql
with
:
codeql-cli-version
:
${{ matrix.codeql_cli }}
codeql-stdlib-version
:
${{ matrix.codeql_standard_library }}
codeql-home
:
${{ github.workspace }}/codeql_home
add-to-path
:
false
-
name
:
Cache queries compilation
id
:
cache-queries-compilation
uses
:
actions/cache/restore@v6
with
:
path
:
${{ github.workspace }}/codeql_cache
key
:
${{ runner.os }}-codeql-compilation-${{ matrix.language }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }}-${{ github.run_id }}
restore-keys
:
${{ runner.os }}-codeql-compilation-${{ matrix.language }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }}
-
name
:
Install CodeQL packs
uses
:
./.github/actions/install-codeql-packs
with
:
cli_path
:
${{ github.workspace }}/codeql_home/codeql
common_caches
:
${{ github.workspace }}/codeql_cache
-
name
:
Pre-Compile Queries
id
:
pre-compile-queries
run
:
|
${{ github.workspace }}/codeql_home/codeql/codeql query compile \
--common-caches=${{ github.workspace }}/codeql_cache \
--compilation-cache-size=1024 \
--threads 0 \
${{ matrix.language }}
-
name
:
Save queries compilation cache
uses
:
actions/cache/save@v6
with
:
path
:
${{ github.workspace }}/codeql_cache
key
:
${{ steps.cache-queries-compilation.outputs.cache-primary-key }}
-
name
:
Run test suites
id
:
run-test-suites
env
:
RUNNER_OS
:
${{ runner.os }}
RUNNER_TEMP
:
${{ runner.temp }}
CODEQL_CLI
:
${{ matrix.codeql_cli }}
CODEQL_STDLIB
:
${{ matrix.codeql_standard_library }}
CODEQL_STDLIB_IDENT
:
${{matrix.codeql_standard_library_ident}}
CODEQL_HOME
:
${{ github.workspace }}/codeql_home
shell
:
python
run
:
|
import os
import sys
import subprocess
import re
import json
from pathlib import Path
def print_error(fmt, *args):
print(f"::error::{fmt}", *args)
def print_error_and_fail(fmt, *args):
print_error(fmt, args)
sys.exit(1)
cli_version = os.environ['CODEQL_CLI']
stdlib_ref = os.environ['CODEQL_STDLIB']
stdlib_ref_ident = os.environ['CODEQL_STDLIB_IDENT']
workspace = os.environ['GITHUB_WORKSPACE']
runner_os = os.environ['RUNNER_OS']
runner_temp = os.environ['RUNNER_TEMP']
codeql_home = os.environ['CODEQL_HOME']
codeql_bin = os.path.join(codeql_home, 'codeql', 'codeql')
language_root = Path(workspace, '${{ matrix.language }}')
test_roots = list(map(str, language_root.glob('*/test')))
for test_root in test_roots:
print(f"Executing tests found (recursively) in the directory '{test_root}'")
files_to_close = []
try:
# XL runners have 8 cores, so split the tests into 8 "slices", and run one per thread
num_slices = 8
procs = []
for slice in range(1, num_slices+1):
test_report_path = os.path.join(runner_temp, "${{ matrix.language }}", f"test_report_{runner_os}_{cli_version}_{stdlib_ref_ident}_slice_{slice}_of_{num_slices}.json")
os.makedirs(os.path.dirname(test_report_path), exist_ok=True)
test_report_file = open(test_report_path, 'w')
files_to_close.append(test_report_file)
procs.append(subprocess.Popen([codeql_bin, "test", "run", "--common-caches=${{ github.workspace }}/codeql_cache", "--failing-exitcode=122", f"--slice={slice}/{num_slices}", "--ram=2048", "--format=json", *test_roots], stdout=test_report_file, stderr=subprocess.PIPE))
for p in procs:
_, err = p.communicate()
if p.returncode != 0:
if p.returncode == 122:
# Failed because a test case failed, so just print the regular output.
# This will allow us to proceed to validate-test-results, which will fail if
# any test cases failed
print(f"{err.decode()}")
else:
# Some more serious problem occurred, so print and fail fast
print_error_and_fail(f"Failed to run tests with return code {p.returncode}\n{err.decode()}")
finally:
for file in files_to_close:
file.close()
-
name
:
Upload test results
uses
:
actions/upload-artifact@v7
with
:
name
:
${{ matrix.language }}-test-results-${{ runner.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }}
path
:
|
${{ runner.temp }}/${{ matrix.language }}/test_report_${{ runner.os }}_${{ matrix.codeql_cli }}_${{ matrix.codeql_standard_library_ident }}_slice_*.json
if-no-files-found
:
error
validate-test-results
:
name
:
Validate test results
if
:
${{ always() }}
needs
:
run-test-suites
runs-on
:
ubuntu-22.04
steps
:
-
name
:
Check if run-test-suites job failed to complete, if so fail
if
:
${{ needs.run-test-suites.result == 'failure' }}
uses
:
actions/github-script@v9
with
:
script
:
|
core.setFailed('Test run job failed')
-
name
:
Collect test results
uses
:
actions/download-artifact@v8
-
name
:
Validate test results
run
:
|
for json_report in *-test-results-*/test_report_*
do
jq --raw-output '"PASS \(map(select(.pass == true)) | length)/\(length)'" $json_report\"" "$json_report"
done
FAILING_TESTS=$(jq --raw-output '.[] | select(.pass == false)' *-test-results-*/test_report_*.json)
if [[ ! -z "$FAILING_TESTS" ]]; then
echo "ERROR: The following tests failed:"
echo $FAILING_TESTS | jq .
exit 1
fi
You can’t perform that action at this time.