-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun-codeql-unit-tests-javascript.yml
More file actions
175 lines (150 loc) · 5.66 KB
/
run-codeql-unit-tests-javascript.yml
File metadata and controls
175 lines (150 loc) · 5.66 KB
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
name: ⚙️ CodeQL - Run Unit Tests (javascript)
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
workflow_dispatch:
jobs:
create-unit-test-matrix:
name: Create CodeQL Unit Test Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.export-unit-test-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install QLT
id: install-qlt
uses: advanced-security/codeql-development-toolkit/.github/actions/install-qlt@main
with:
qlt-version: 'latest'
add-to-path: true
- name: Export unit test matrix
id: export-unit-test-matrix
run: |
qlt test run get-matrix --os-version ubuntu-latest
run-test-suites:
name: Run Unit Tests
needs: create-unit-test-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.create-unit-test-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install QLT
id: install-qlt
uses: advanced-security/codeql-development-toolkit/.github/actions/install-qlt@main
with:
qlt-version: 'latest'
add-to-path: true
- name: Install CodeQL
id: install-codeql
shell: bash
run: |
echo "Installing CodeQL"
qlt codeql run install
echo "-----------------------------"
echo "CodeQL Home: $QLT_CODEQL_HOME"
echo "CodeQL Binary: $QLT_CODEQL_PATH"
- name: Verify Versions of Tooling
shell: bash
run: |
echo -e "Checking CodeQL Version:"
$QLT_CODEQL_PATH --version
echo -e "Checking QLT Version:"
echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}"
qlt version
- name: Install QL Packs
shell: bash
run: |
qlt query run install-packs
- name: Ensure presence of cds shell command
run: |
if ! command -v cds &> /dev/null
then
## Workaround for https://github.tools.sap/cap/issues/issues/17840
npm install -g @sap/cds-dk@8.6.1
fi
# Compile .cds files to .cds.json files.
- name: Compile CAP CDS files
run: |
for test_dir in $(find . -type f -name '*.expected' -exec dirname {} \;);
do
# The CDS compiler produces locations relative to the working directory
# so we switch to the test directory before running the compiler.
pushd $test_dir
for cds_file in $(find . -type f \( -iname '*.cds' \) -print)
do
echo "I am compiling $cds_file"
_out_path="${cds_file}.json"
cds compile $cds_file \
--locations \
--to json \
--dest "$_out_path" \
2> "$cds_file.err"
# Check if the output is a regular file or a (sub)directory, where
# files generated in an output directory will need to have the file
# extension changed from '.json' to '.cds.json', but we don't need
# to rename anything if the cds compiler just generated a single
# '.cds.json' file.
if [ -d "$_out_path" ]
then
for json_file in $(find "$_out_path" -type f \( -iname '*.json' \) -print)
do
_new_path="${json_file%.json}.cds.json"
echo "Renaming CDS compiler generated JSON file $json_file to $_new_path"
mv "$json_file" "$_new_path"
done
fi
done
popd
done
- name: Run test suites
id: run-test-suites
env:
RUNNER_OS: ${{ runner.os }}
CODEQL_CLI: ${{ matrix.codeql_cli }}
CODEQL_STDLIB: ${{ matrix.codeql_standard_library }}
CODEQL_STDLIB_IDENT: ${{matrix.codeql_standard_library_ident}}
RUNNER_TMP: ${{ runner.temp }}
LGTM_INDEX_XML_MODE: all
LGTM_INDEX_FILETYPES: ".json:JSON\n.cds:JSON"
shell: bash
run: >
qlt test run execute-unit-tests
--codeql-args "--threads=0 --strict-test-discovery"
--num-threads 2
--language javascript
--runner-os $RUNNER_OS
--work-dir $RUNNER_TMP
- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: test-results-${{ runner.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }}
path: |
${{ runner.temp }}/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
needs: [run-test-suites]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install QLT
id: install-qlt
uses: advanced-security/codeql-development-toolkit/.github/actions/install-qlt@main
with:
qlt-version: 'latest'
add-to-path: true
- name: Collect test results
uses: actions/download-artifact@v4
- name: Validate test results
run: |
qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY
qlt test run validate-unit-tests --results-directory .