Skip to content

Update explanation of default download_dir behavior. #96

Update explanation of default download_dir behavior.

Update explanation of default download_dir behavior. #96

Workflow file for this run

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