-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (197 loc) · 8.56 KB
/
build.yml
File metadata and controls
231 lines (197 loc) · 8.56 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
name: Build Check
on: [pull_request, push]
permissions:
contents: read
pull-requests: write # Required to post comments on PRs
jobs:
# Matrix job that compiles and tests all architectures
build-and-test:
strategy:
fail-fast: false # Continue testing other architectures even if one fails
matrix:
include:
# x64 architecture - native runner
- arch: x64
runner: windows-latest
vcvars_arch: x64
# x86 architecture - runs on x64 via WoW64
- arch: x86
runner: windows-latest
vcvars_arch: x64_x86
# ARM64 architecture - native ARM runner for testing
- arch: arm64
runner: windows-11-arm
vcvars_arch: arm64
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Setup MSVC for ${{ matrix.arch }}
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.vcvars_arch }}
- name: Compile for ${{ matrix.arch }}
shell: pwsh
run: |
# Compile the executable with architecture-specific name
cl /O2 /std:c++20 /EHsc main.cpp /DUNICODE /D_UNICODE /Fe:win-witr-${{ matrix.arch }}.exe
# Create a copy with the standard name for tests
Copy-Item -Path "win-witr-${{ matrix.arch }}.exe" -Destination "win-witr.exe"
# Add the current directory to PATH
$env:PATH = "$PWD;$env:PATH"
# Verify the exe is accessible
Write-Host "Checking win-witr-${{ matrix.arch }}.exe availability..."
.\win-witr-${{ matrix.arch }}.exe --version
- name: Run Tests for ${{ matrix.arch }}
id: run_tests
shell: pwsh
run: |
# Initialize test counters
$totalTests = 0
$passedTests = 0
$failedTests = 0
$testResults = @()
# Add the current directory to PATH
$env:PATH = "$PWD;$env:PATH"
# Run all test .bat files
Get-ChildItem -Path tests -Recurse -Filter *.bat | ForEach-Object {
$totalTests++
$testName = $_.Name
Write-Host "Running test: $testName"
# Initialize output variable outside try block
$output = $null
try {
# Run the test and capture output and exit code
$output = & $_.FullName 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
$passedTests++
# Include output in the result
$outputText = if ($output) { "`n Output: $($output -join "`n ")" } else { "" }
$testResults += "✅ $testName - PASSED$outputText"
Write-Host "✅ Test passed: $testName"
} else {
$failedTests++
# Include output and exit code in the result
$outputText = if ($output) { "`n Output: $($output -join "`n ")" } else { "" }
$testResults += "❌ $testName - FAILED (Exit code: $exitCode)$outputText"
Write-Host "❌ Test failed: $testName (Exit code: $exitCode)"
}
} catch {
$failedTests++
# Include exception and any captured output
$outputText = if ($output) { "`n Output: $($output -join "`n ")" } else { "" }
$testResults += "❌ $testName - FAILED (Exception: $_)$outputText"
Write-Host "❌ Test failed with exception: $testName"
}
}
# Output test summary
Write-Host "`n=== Test Summary for ${{ matrix.arch }} ==="
Write-Host "Total: $totalTests"
Write-Host "Passed: $passedTests"
Write-Host "Failed: $failedTests"
# Store results for PR comment
$results = @{
total = $totalTests
passed = $passedTests
failed = $failedTests
details = $testResults -join "`n"
}
# Export results to GitHub output using multiline format
"total=$totalTests" >> $env:GITHUB_OUTPUT
"passed=$passedTests" >> $env:GITHUB_OUTPUT
"failed=$failedTests" >> $env:GITHUB_OUTPUT
$delimiter = "EOF_DETAILS_$(Get-Date -Format 'yyyyMMddHHmmss')"
"details<<$delimiter" >> $env:GITHUB_OUTPUT
$testResults -join "`n" >> $env:GITHUB_OUTPUT
"$delimiter" >> $env:GITHUB_OUTPUT
# Exit with error if any tests failed
if ($failedTests -gt 0) {
Write-Error "Some tests failed for ${{ matrix.arch }}"
exit 1
}
# Upload test results as artifacts for the comment job
- name: Save test results
if: always()
shell: pwsh
run: |
# Determine job status based on previous steps
$jobStatus = if ("${{ steps.run_tests.outcome }}" -eq "success") { "success" } else { "failure" }
$results = @{
arch = "${{ matrix.arch }}"
status = $jobStatus
total = "${{ steps.run_tests.outputs.total }}"
passed = "${{ steps.run_tests.outputs.passed }}"
failed = "${{ steps.run_tests.outputs.failed }}"
details = "${{ steps.run_tests.outputs.details }}"
}
$results | ConvertTo-Json | Out-File -FilePath "test-results-${{ matrix.arch }}.json"
- name: Upload test results artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.arch }}
path: test-results-${{ matrix.arch }}.json
# Job to post test results as a PR comment
post-test-results:
needs: build-and-test
if: always() && github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Download all test results
uses: actions/download-artifact@v4
with:
pattern: test-results-*
merge-multiple: true
- name: Generate and post comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
// Read all test result files
const files = fs.readdirSync('.').filter(f => f.startsWith('test-results-') && f.endsWith('.json'));
let commentBody = '## 🧪 Test Results\n\n';
let allPassed = true;
// Process each architecture
for (const file of files) {
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
const arch = data.arch;
const status = data.status || 'unknown';
const total = data.total || 0;
const passed = data.passed || 0;
const failed = data.failed || 0;
// Mark as failed if either tests failed OR job status is not success
if (failed > 0 || status !== 'success') {
allPassed = false;
}
// Determine emoji based on both test results and job status
const emoji = (failed === 0 && status === 'success') ? '✅' : '❌';
commentBody += `### ${emoji} ${arch.toUpperCase()}\n`;
// Show appropriate message based on job status
if (status !== 'success') {
commentBody += `**Job failed** - Tests may not have run due to compile or setup failure\n\n`;
} else {
commentBody += `**${passed}/${total} tests passed**\n\n`;
}
if (data.details && data.details.trim()) {
commentBody += '<details>\n';
commentBody += '<summary>Test Details</summary>\n\n';
commentBody += '```\n';
commentBody += data.details;
commentBody += '\n```\n';
commentBody += '</details>\n\n';
}
}
if (allPassed) {
commentBody += '\n✨ All tests passed across all architectures!\n';
} else {
commentBody += '\n⚠️ Some tests failed. Please review the details above.\n';
}
// Post comment to PR
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});