-
Notifications
You must be signed in to change notification settings - Fork 4
351 lines (296 loc) · 11.8 KB
/
ql-unit-tests-windows.yml
File metadata and controls
351 lines (296 loc) · 11.8 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
name: QL Unit Tests (Windows)
# This workflow runs CodeQL unit tests for the 'javascript' language on Windows.
# The 'qlt' CLI is not supported on Windows, so this workflow uses 'codeql test run'
# directly, following the pattern from the Actions language unit tests workflow.
#
# Tests are run in parallel using a matrix strategy for improved performance.
on:
pull_request:
branches:
- 'main'
paths:
- '.github/workflows/ql-unit-tests-windows.yml'
- 'qlt.conf.json'
- 'extractors/cds/**'
- 'extractors/javascript/tools/**'
- 'javascript/**'
push:
branches:
- 'main'
paths:
- '.github/workflows/ql-unit-tests-windows.yml'
- 'qlt.conf.json'
- 'extractors/cds/**'
- 'extractors/javascript/tools/**'
- 'javascript/**'
workflow_dispatch:
permissions:
contents: read
jobs:
run-windows-tests:
name: ${{ matrix.test_suite }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
test_suite:
- cap-models
- cap-queries
- ui5-lib
- ui5-models
- ui5-queries
- ui5-webcomponents-queries
- xsjs-models
- xsjs-queries
- heuristic-models
include:
- test_suite: cap-models
test_path: javascript/frameworks/cap/test/models
- test_suite: cap-queries
test_path: javascript/frameworks/cap/test/queries
- test_suite: ui5-lib
test_path: javascript/frameworks/ui5/test/lib
- test_suite: ui5-models
test_path: javascript/frameworks/ui5/test/models
- test_suite: ui5-queries
test_path: javascript/frameworks/ui5/test/queries
- test_suite: ui5-webcomponents-queries
test_path: javascript/frameworks/ui5-webcomponents/test/queries
- test_suite: xsjs-models
test_path: javascript/frameworks/xsjs/test/models
- test_suite: xsjs-queries
test_path: javascript/frameworks/xsjs/test/queries
- test_suite: heuristic-models
test_path: javascript/heuristic-models/tests
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup CodeQL CLI
id: setup-codeql
shell: pwsh
run: |
# Read CodeQL CLI version from qlt.conf.json
$qltConfig = Get-Content "qlt.conf.json" | ConvertFrom-Json
$cliVersion = $qltConfig.CodeQLCLI
# Ensure version has 'v' prefix for GitHub releases
if (-not $cliVersion.StartsWith("v")) {
$version = "v$cliVersion"
} else {
$version = $cliVersion
}
Write-Host "Installing CodeQL CLI version: $version (from qlt.conf.json)"
# Determine download URL for Windows
$downloadUrl = "https://github.com/github/codeql-cli-binaries/releases/download/$version/codeql-win64.zip"
# Create installation directory
$installDir = "$env:RUNNER_TOOL_CACHE\codeql"
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
# Download and extract CodeQL CLI
$zipPath = "$env:RUNNER_TEMP\codeql.zip"
Write-Host "Downloading from: $downloadUrl"
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath
Write-Host "Extracting CodeQL CLI to: $installDir"
Expand-Archive -Path $zipPath -DestinationPath $installDir -Force
# Set up environment
$codeqlPath = "$installDir\codeql"
$codeqlExe = "$codeqlPath\codeql.exe"
if (-not (Test-Path $codeqlExe)) {
Write-Error "CodeQL executable not found at: $codeqlExe"
exit 1
}
Write-Host "CodeQL executable: $codeqlExe"
# Add to PATH for subsequent steps
echo "$codeqlPath" >> $env:GITHUB_PATH
echo "CODEQL_HOME=$codeqlPath" >> $env:GITHUB_ENV
echo "codeql-path=$codeqlPath" >> $env:GITHUB_OUTPUT
# Verify installation
& $codeqlExe --version
- name: Verify CodeQL Installation
shell: pwsh
run: |
Write-Host "CodeQL version:"
codeql --version
Write-Host ""
Write-Host "CodeQL resolve languages:"
codeql resolve languages
- name: Install QL Packs
shell: pwsh
run: |
Write-Host "Installing QL packs from qlpack.yml files..."
# Find all qlpack.yml files and install dependencies
$qlpacks = Get-ChildItem -Path "javascript" -Filter "qlpack.yml" -Recurse
foreach ($qlpack in $qlpacks) {
$dir = $qlpack.DirectoryName
Write-Host "Installing packs for: $dir"
Push-Location $dir
try {
codeql pack install
} catch {
Write-Warning "Failed to install packs in $dir : $_"
}
Pop-Location
}
Write-Host "QL pack installation complete"
- name: Setup Node.js for CDS compilation
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 'extractors/cds/tools/package-lock.json'
- name: Verify Node.js and npm tools
shell: pwsh
run: |
Write-Host "Node.js version: $(node --version)"
Write-Host "npm version: $(npm --version)"
Write-Host "npx version: $(npx --version)"
# Verify npx can access @sap/cds-dk
Write-Host "Testing npx access to @sap/cds-dk..."
try {
npx --yes --package @sap/cds-dk@latest cds --version
} catch {
Write-Host "CDS will be installed per-project as needed"
}
- name: Compile CAP CDS files
shell: cmd
run: |
REM Compile CDS files for the specific test suite path
call extractors\cds\tools\workflow\cds-compilation-for-actions.cmd ${{ matrix.test_path }}
- name: Run CodeQL unit tests
id: run-tests
shell: pwsh
env:
LGTM_INDEX_XML_MODE: all
LGTM_INDEX_FILETYPES: ".json:JSON\n.cds:JSON"
run: |
Write-Host "Running CodeQL unit tests for: ${{ matrix.test_suite }}"
# Create results directory
$resultsDir = Join-Path $env:RUNNER_TEMP "test-results"
New-Item -ItemType Directory -Force -Path $resultsDir | Out-Null
# Get the test path for this matrix job
$testPath = "${{ matrix.test_path }}"
# Check if test path exists
if (-not (Test-Path $testPath)) {
Write-Host "⚠️ Test path does not exist: $testPath"
Write-Host "Skipping tests for this suite"
exit 0
}
# Use CodeQL's strict test discovery to find valid tests
Write-Host "Resolving tests with strict test discovery in: $testPath"
$resolveOutputFile = Join-Path $resultsDir "resolve-output.txt"
$resolveErrorFile = Join-Path $resultsDir "resolve-errors.txt"
# Run codeql resolve tests with strict discovery
$resolveProcess = Start-Process -FilePath "codeql" `
-ArgumentList @("resolve", "tests", "--strict-test-discovery", "--format=text", "--", $testPath) `
-Wait `
-PassThru `
-NoNewWindow `
-RedirectStandardOutput $resolveOutputFile `
-RedirectStandardError $resolveErrorFile
# Check if resolve succeeded
if ($resolveProcess.ExitCode -ne 0) {
Write-Host "❌ Failed to resolve tests"
if (Test-Path $resolveErrorFile) {
Get-Content $resolveErrorFile | Write-Host
}
exit $resolveProcess.ExitCode
}
# Read discovered test directories
$testDirs = @()
if (Test-Path $resolveOutputFile) {
$testDirs = Get-Content $resolveOutputFile | Where-Object { $_.Trim() -ne "" }
}
if ($testDirs.Count -eq 0) {
Write-Host "⚠️ No valid test directories found in: $testPath"
Write-Host "Skipping tests for this suite"
exit 0
}
Write-Host "Found $($testDirs.Count) valid test directory(ies):"
$testDirs | ForEach-Object { Write-Host " - $_" }
Write-Host ""
# Run tests using codeql test run
Write-Host "Running: codeql test run --format=text -- $($testDirs -join ' ')"
$outputFile = Join-Path $resultsDir "test-output.txt"
$errorFile = Join-Path $resultsDir "test-errors.txt"
# Build argument list for codeql test run
$codeqlArgs = @("test", "run", "--format=text", "--")
$codeqlArgs += $testDirs
# Run tests and capture output
$testProcess = Start-Process -FilePath "codeql" `
-ArgumentList $codeqlArgs `
-Wait `
-PassThru `
-NoNewWindow `
-RedirectStandardOutput $outputFile `
-RedirectStandardError $errorFile
# Display output
if (Test-Path $outputFile) {
Get-Content $outputFile | Write-Host
}
if (Test-Path $errorFile) {
$errors = Get-Content $errorFile
if ($errors) {
Write-Host "Standard Error Output:"
$errors | Write-Host
}
}
# Check exit code
if ($testProcess.ExitCode -ne 0) {
Write-Host "❌ Tests failed with exit code: $($testProcess.ExitCode)"
exit $testProcess.ExitCode
}
Write-Host "✅ Tests completed successfully"
- name: Upload test results
if: ${{ always() }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
with:
name: windows-test-results-${{ matrix.test_suite }}
path: |
${{ runner.temp }}/test-results/
if-no-files-found: warn
- name: Upload CAP test artifacts
if: ${{ always() && (matrix.test_suite == 'cap-models' || matrix.test_suite == 'cap-queries') }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
with:
name: windows-cap-debug-${{ matrix.test_suite }}
path: |
javascript/frameworks/cap/test/**/*.cds.json
javascript/frameworks/cap/test/**/*.actual
if-no-files-found: warn
validate-results:
name: Validate Windows Test Results
needs: [run-windows-tests]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Download test results
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
pattern: windows-test-results-*
path: test-results/
merge-multiple: true
- name: Display test results
shell: bash
run: |
echo "=== Windows Unit Test Results ==="
# Check if results exist
if [ ! -d "test-results/" ] || [ -z "$(find test-results/ -type f 2>/dev/null)" ]; then
echo "❌ No test results found"
exit 1
fi
# Display test output
if [ -f "test-results/test-output.txt" ]; then
echo "Test output:"
cat test-results/test-output.txt
echo ""
fi
# Check for failures
if [ -f "test-results/test-output.txt" ]; then
if grep -q "FAILED" test-results/test-output.txt 2>/dev/null; then
echo "❌ Some tests failed"
exit 1
else
echo "✅ All tests passed"
fi
fi
echo "================================="