-
Notifications
You must be signed in to change notification settings - Fork 1
417 lines (351 loc) · 14.4 KB
/
Copy pathtest-downloader.yml
File metadata and controls
417 lines (351 loc) · 14.4 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
name: Test R2 Downloader & Cygwin + Wget Installer
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize]
branches: [ main ]
paths:
- 'mlc-r2-downloader.sh'
- 'cygwin-wget-installer.bat'
- '.github/workflows/test-downloader.yml'
# Prevent simultaneous runs from the same PR
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# Define all test cases in a centralized matrix
define-tests:
runs-on: ubuntu-latest
outputs:
test-matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
- id: set-matrix
run: |
echo "matrix<<EOF" >> $GITHUB_OUTPUT
cat .github/workflows/test-matrix.json >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Unix platforms (Linux and macOS)
test-unix:
needs: define-tests
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
if [[ "${{ matrix.os }}" == "macos-latest" ]]; then
# Install md5sum on macOS (not available by default)
brew install md5sha1sum
fi
- name: Load secrets
id: op-load-secrets
uses: 1password/load-secrets-action@v3
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
CF_ACCESS_CLIENT_ID: "op://x4h33jlflygxmifnxfrizew4oa/7g2fhcv3tpsogr2vhkielewvsm/wsyxxjrdsyj36zsaanbh3kybfe"
CF_ACCESS_CLIENT_SECRET: "op://x4h33jlflygxmifnxfrizew4oa/7g2fhcv3tpsogr2vhkielewvsm/5x3sr7bry5a3ealsemvx5vcbuy"
- name: Run all test cases
env:
CF_ACCESS_CLIENT_ID: ${{ steps.op-load-secrets.outputs.CF_ACCESS_CLIENT_ID }}
CF_ACCESS_CLIENT_SECRET: ${{ steps.op-load-secrets.outputs.CF_ACCESS_CLIENT_SECRET }}
run: |
set +e # Don't exit on error so we can check exit codes
# Parse the test matrix JSON
tests='${{ needs.define-tests.outputs.test-matrix }}'
# Initialize counters
total_tests=0
passed_tests=0
failed_tests=0
echo "=== Running All Test Cases on ${{ matrix.os }} ==="
# Process each test case
echo "$tests" | jq -r '.include[] | @base64' | while read -r encoded_test; do
# Decode the test case
test_data=$(echo "$encoded_test" | base64 -d)
# Extract test properties
test_name=$(echo "$test_data" | jq -r '.name')
test_desc=$(echo "$test_data" | jq -r '.description')
test_args=$(echo "$test_data" | jq -r '.args')
test_url=$(echo "$test_data" | jq -r '.url')
expected_exit=$(echo "$test_data" | jq -r '.expect_exit')
needs_auth=$(echo "$test_data" | jq -r '.needs_auth')
skip_url=$(echo "$test_data" | jq -r '.skip_url')
skip_creds=$(echo "$test_data" | jq -r '.skip_creds')
echo ""
echo "--- Test: $test_name ---"
echo "Description: $test_desc"
echo "Expected exit code: $expected_exit"
# Set up environment variables for this test
if [[ "$skip_creds" == "true" ]]; then
unset CF_ACCESS_CLIENT_ID CF_ACCESS_CLIENT_SECRET
else
export CF_ACCESS_CLIENT_ID="${{ steps.op-load-secrets.outputs.CF_ACCESS_CLIENT_ID }}"
export CF_ACCESS_CLIENT_SECRET="${{ steps.op-load-secrets.outputs.CF_ACCESS_CLIENT_SECRET }}"
fi
# Build command
if [[ "$skip_url" == "true" ]]; then
cmd="bash ./mlc-r2-downloader.sh $test_args"
else
cmd="bash ./mlc-r2-downloader.sh $test_args $test_url"
fi
echo "Running: $cmd"
# Execute the test
eval "$cmd"
actual_exit=$?
# Check result
total_tests=$((total_tests + 1))
if [ $actual_exit -eq $expected_exit ]; then
echo "✅ [PASS] $test_name - Expected exit code $expected_exit, got $actual_exit"
passed_tests=$((passed_tests + 1))
else
echo "❌ [FAIL] $test_name - Expected exit code $expected_exit, got $actual_exit"
failed_tests=$((failed_tests + 1))
fi
done
# Final summary
echo ""
echo "=== Test Summary for ${{ matrix.os }} ==="
echo "Total tests: $total_tests"
echo "Passed: $passed_tests"
echo "Failed: $failed_tests"
# Exit with failure if any tests failed
if [ $failed_tests -gt 0 ]; then
echo "❌ Some tests failed on ${{ matrix.os }}"
exit 1
else
echo "✅ All tests passed on ${{ matrix.os }}"
fi
# Windows WSL
test-windows-wsl:
needs: define-tests
runs-on: windows-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure git for Unix line endings
shell: powershell
run: |
# Re-checkout files with Unix line endings
git config core.autocrlf false
git rm --cached -rf .
git reset --hard HEAD
- name: Load secrets
id: op-load-secrets
uses: 1password/load-secrets-action@v3
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
CF_ACCESS_CLIENT_ID: "op://x4h33jlflygxmifnxfrizew4oa/7g2fhcv3tpsogr2vhkielewvsm/wsyxxjrdsyj36zsaanbh3kybfe"
CF_ACCESS_CLIENT_SECRET: "op://x4h33jlflygxmifnxfrizew4oa/7g2fhcv3tpsogr2vhkielewvsm/5x3sr7bry5a3ealsemvx5vcbuy"
- name: Setup WSL
uses: Vampire/setup-wsl@v5
with:
distribution: Ubuntu-22.04
- name: Run all test cases in WSL
shell: powershell
run: |
# Parse the test matrix JSON
$tests = '${{ needs.define-tests.outputs.test-matrix }}' | ConvertFrom-Json
# Initialize counters
$totalTests = 0
$passedTests = 0
$failedTests = 0
Write-Host "=== Running All Test Cases in WSL ==="
# Process each test case
foreach ($test in $tests.include) {
Write-Host ""
Write-Host "--- Test: $($test.name) ---"
Write-Host "Description: $($test.description)"
Write-Host "Expected exit code: $($test.expect_exit)"
# Set up environment variables for this test
$clientId = "${{ steps.op-load-secrets.outputs.CF_ACCESS_CLIENT_ID }}"
$clientSecret = "${{ steps.op-load-secrets.outputs.CF_ACCESS_CLIENT_SECRET }}"
if ($test.skip_creds -eq "true") {
$clientId = ""
$clientSecret = ""
}
# Build command
$envVars = ""
if ($clientId -and $clientSecret) {
$envVars = "export CF_ACCESS_CLIENT_ID='$clientId'; export CF_ACCESS_CLIENT_SECRET='$clientSecret';"
}
if ($test.skip_url -eq "true") {
$cmd = "$envVars bash ./mlc-r2-downloader.sh $($test.args)"
} else {
$cmd = "$envVars bash ./mlc-r2-downloader.sh $($test.args) $($test.url)"
}
Write-Host "Running WSL command: $cmd"
# Execute and capture output/exit code
$output = wsl bash -c $cmd
$exitCode = $LASTEXITCODE
# Display output
Write-Host "Output:"
$output | ForEach-Object { Write-Host $_ }
# Check result
$totalTests++
if ($exitCode -eq $test.expect_exit) {
Write-Host "✅ [PASS] $($test.name) - Expected exit code $($test.expect_exit), got $exitCode"
$passedTests++
} else {
Write-Host "❌ [FAIL] $($test.name) - Expected exit code $($test.expect_exit), got $exitCode"
$failedTests++
}
}
# Final summary
Write-Host ""
Write-Host "=== Test Summary for WSL ==="
Write-Host "Total tests: $totalTests"
Write-Host "Passed: $passedTests"
Write-Host "Failed: $failedTests"
# Exit with failure if any tests failed
if ($failedTests -gt 0) {
Write-Host "❌ Some tests failed in WSL"
exit 1
} else {
Write-Host "✅ All tests passed in WSL"
exit 0
}
# Windows Cygwin
test-windows-cygwin:
needs: define-tests
runs-on: windows-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure git for Unix line endings
shell: powershell
run: |
# Re-checkout files with Unix line endings
git config core.autocrlf false
git rm --cached -rf .
git reset --hard HEAD
- name: Load secrets
id: op-load-secrets
uses: 1password/load-secrets-action@v3
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
CF_ACCESS_CLIENT_ID: "op://x4h33jlflygxmifnxfrizew4oa/7g2fhcv3tpsogr2vhkielewvsm/wsyxxjrdsyj36zsaanbh3kybfe"
CF_ACCESS_CLIENT_SECRET: "op://x4h33jlflygxmifnxfrizew4oa/7g2fhcv3tpsogr2vhkielewvsm/5x3sr7bry5a3ealsemvx5vcbuy"
- name: Install Cygwin+Wget using installer
shell: powershell
run: |
# Run the cygwin-wget-installer.bat to test the installer and install Cygwin
Write-Host "Testing and running cygwin-wget-installer.bat..."
.\cygwin-wget-installer.bat
# Verify Cygwin installation and wget
if (Test-Path "C:\cygwin64\bin\bash.exe") {
Write-Host "[PASS] Cygwin bash installation successful"
} else {
Write-Host "[FAIL] Cygwin bash installation failed"
exit 1
}
if (Test-Path "C:\cygwin64\bin\wget.exe") {
Write-Host "[PASS] wget installation successful"
} else {
Write-Host "[FAIL] wget installation failed"
# List what's actually in the bin directory
Write-Host "Contents of C:\cygwin64\bin:"
Get-ChildItem "C:\cygwin64\bin" | Select-Object Name | Format-Table -AutoSize
}
- name: Run all test cases in Cygwin
shell: powershell
run: |
# Parse the test matrix JSON
$tests = '${{ needs.define-tests.outputs.test-matrix }}' | ConvertFrom-Json
# Initialize counters
$totalTests = 0
$passedTests = 0
$failedTests = 0
# Convert Windows path to Cygwin path
$repoPath = (Get-Location).Path -replace '\\', '/' -replace '^([A-Z]):', '/cygdrive/$1'
$repoPath = $repoPath.ToLower()
Write-Host "=== Running All Test Cases in Cygwin ==="
# Process each test case
foreach ($test in $tests.include) {
Write-Host ""
Write-Host "--- Test: $($test.name) ---"
Write-Host "Description: $($test.description)"
Write-Host "Expected exit code: $($test.expect_exit)"
# Set up environment variables for this test
$clientId = "${{ steps.op-load-secrets.outputs.CF_ACCESS_CLIENT_ID }}"
$clientSecret = "${{ steps.op-load-secrets.outputs.CF_ACCESS_CLIENT_SECRET }}"
if ($test.skip_creds -eq "true") {
$clientId = ""
$clientSecret = ""
}
# Build command
$envVars = ""
if ($clientId -and $clientSecret) {
$envVars = "export CF_ACCESS_CLIENT_ID='$clientId'; export CF_ACCESS_CLIENT_SECRET='$clientSecret';"
}
if ($test.skip_url -eq "true") {
$cmd = "$envVars bash '$repoPath/mlc-r2-downloader.sh' $($test.args); echo `"EXIT_CODE:`$?`""
} else {
$cmd = "$envVars bash '$repoPath/mlc-r2-downloader.sh' $($test.args) $($test.url); echo `"EXIT_CODE:`$?`""
}
Write-Host "Running Cygwin command: $cmd"
# Execute command
$output = C:\cygwin64\bin\bash.exe --login -c $cmd
# Extract exit code from output
$exitCode = 0
$cleanOutput = @()
foreach ($line in $output) {
if ($line -match "^EXIT_CODE:(\d+)$") {
$exitCode = [int]$matches[1]
} else {
$cleanOutput += $line
}
}
# Display clean output
Write-Host "Output:"
$cleanOutput | ForEach-Object { Write-Host $_ }
# Check result
$totalTests++
if ($exitCode -eq $test.expect_exit) {
Write-Host "✅ [PASS] $($test.name) - Expected exit code $($test.expect_exit), got $exitCode"
$passedTests++
} else {
Write-Host "❌ [FAIL] $($test.name) - Expected exit code $($test.expect_exit), got $exitCode"
$failedTests++
}
}
# Final summary
Write-Host ""
Write-Host "=== Test Summary for Cygwin ==="
Write-Host "Total tests: $totalTests"
Write-Host "Passed: $passedTests"
Write-Host "Failed: $failedTests"
# Exit with failure if any tests failed
if ($failedTests -gt 0) {
Write-Host "❌ Some tests failed in Cygwin"
exit 1
} else {
Write-Host "✅ All tests passed in Cygwin"
}
# Summary job that depends on all test jobs
test-summary:
needs: [test-unix, test-windows-wsl, test-windows-cygwin]
runs-on: ubuntu-latest
if: always()
steps:
- name: Check test results
run: |
echo "Test Results Summary:"
echo "Unix tests: ${{ needs.test-unix.result }}"
echo "WSL tests: ${{ needs.test-windows-wsl.result }}"
echo "Cygwin tests: ${{ needs.test-windows-cygwin.result }}"
if [[ "${{ needs.test-unix.result }}" != "success" ]] || \
[[ "${{ needs.test-windows-wsl.result }}" != "success" ]] || \
[[ "${{ needs.test-windows-cygwin.result }}" != "success" ]]; then
echo "❌ Some tests failed!"
exit 1
else
echo "✅ All tests passed!"
fi