Build Compiler Tests #115
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Compiler Tests | |
| on: | |
| schedule: | |
| - cron: '0 */6 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| test-linux: | |
| runs-on: ubuntu-latest | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # These commands use the compiler executable (chemical) from the release asset. | |
| COMPILER_CMD_REGULAR: "./chemical lang/tests/build.lab -o lang/tests/build.exe -arg-minimal -bm --ignore-errors -v --assertions --mode debug_complete" | |
| COMPILER_CMD_TCC: "./chemical lang/tests/build.lab -o lang/tests/build.exe -arg-minimal -bm --ignore-errors -v --assertions --mode debug_complete" | |
| ASSET_REGULAR: "linux-x86-64.zip" | |
| ASSET_TCC: "linux-x86-64-tcc.zip" | |
| steps: | |
| - name: Checkout repository (tests) | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 1 | |
| - name: Clean repository, Keep only lang/tests | |
| run: | | |
| echo "Cleaning repository: Removing all directories except 'lang'" | |
| find . -maxdepth 1 -mindepth 1 -type d ! -name "lang" -exec rm -rf {} + | |
| echo "Inside lang, removing all directories except 'tests'" | |
| cd lang | |
| find . -maxdepth 1 -mindepth 1 -type d ! -name "tests" -exec rm -rf {} + | |
| cd .. | |
| shell: bash | |
| - name: Create output directory | |
| run: mkdir -p output | |
| - name: Process Linux Regular Variant | |
| run: | | |
| echo "== Processing Linux Regular Variant ==" | |
| echo "Fetching release information..." | |
| releases=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases") | |
| ASSET_URL=$(echo "$releases" | jq -r '[.[] | select(.assets | map(.name) | index("'"${ASSET_REGULAR}"'"))] | .[0].assets[] | select(.name=="'"${ASSET_REGULAR}"'") | .browser_download_url') | |
| if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then | |
| echo "Error: Asset ${ASSET_REGULAR} not found." | |
| exit 1 | |
| fi | |
| echo "Downloading asset from $ASSET_URL" | |
| curl -L -o asset.zip "$ASSET_URL" | |
| unzip -o -q asset.zip || true | |
| # Determine the release root | |
| release_root=$(find . -maxdepth 1 -type d ! -path "." | head -n 1) | |
| if [ -z "$release_root" ]; then | |
| echo "Error: No release directory found." | |
| exit 1 | |
| fi | |
| echo "Using release root: $release_root" | |
| # If the asset does not already include the tests module, copy it from the repository. | |
| if [ ! -d "$release_root/lang/tests" ]; then | |
| mkdir -p "$release_root/lang" | |
| cp -r "$GITHUB_WORKSPACE/lang/tests" "$release_root/lang" | |
| fi | |
| pushd "$release_root" | |
| echo "Running compile command for Linux Regular Variant:" | |
| echo "${COMPILER_CMD_REGULAR}" | tee compile_output.txt | |
| eval ${COMPILER_CMD_REGULAR} | tee -a compile_output.txt | |
| popd | |
| cp "$release_root/compile_output.txt" "$GITHUB_WORKSPACE/output/linux-regular-output.txt" | |
| shell: bash | |
| - name: Process Linux TCC Variant | |
| run: | | |
| echo "== Processing Linux TCC Variant ==" | |
| echo "Fetching release information..." | |
| releases=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases") | |
| ASSET_URL=$(echo "$releases" | jq -r '[.[] | select(.assets | map(.name) | index("'"${ASSET_TCC}"'"))] | .[0].assets[] | select(.name=="'"${ASSET_TCC}"'") | .browser_download_url') | |
| if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then | |
| echo "Error: Asset ${ASSET_TCC} not found." | |
| exit 1 | |
| fi | |
| echo "Downloading asset from $ASSET_URL" | |
| curl -L -o asset.zip "$ASSET_URL" | |
| unzip -o -q asset.zip || true | |
| # Determine the release root | |
| release_root=$(find . -maxdepth 1 -type d ! -path "." | head -n 1) | |
| if [ -z "$release_root" ]; then | |
| echo "Error: No release directory found." | |
| exit 1 | |
| fi | |
| echo "Using release root: $release_root" | |
| if [ ! -d "$release_root/lang/tests" ]; then | |
| mkdir -p "$release_root/lang" | |
| cp -r "$GITHUB_WORKSPACE/lang/tests" "$release_root/lang" | |
| fi | |
| pushd "$release_root" | |
| rm -rf lang/tests/build | |
| echo "Running compile command for Linux TCC Variant:" | |
| echo "${COMPILER_CMD_TCC}" | tee compile_output.txt | |
| eval ${COMPILER_CMD_TCC} | tee -a compile_output.txt | |
| popd | |
| cp "$release_root/compile_output.txt" "$GITHUB_WORKSPACE/output/linux-tcc-output.txt" | |
| shell: bash | |
| - name: Upload Linux Outputs | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-tests-output | |
| path: output | |
| test-windows: | |
| runs-on: windows-latest | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| COMPILER_CMD_REGULAR: ".\\chemical.exe lang/tests/build.lab -o lang/tests/build.exe -arg-minimal -bm --ignore-errors -v --assertions --mode debug_complete" | |
| COMPILER_CMD_TCC: ".\\chemical.exe lang/tests/build.lab -o lang/tests/build.exe -arg-minimal -bm --ignore-errors -v --assertions --mode debug_complete" | |
| ASSET_REGULAR: "windows-x64.zip" | |
| ASSET_TCC: "windows-x64-tcc.zip" | |
| steps: | |
| - name: Checkout repository (tests) | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 1 | |
| - name: Clean repository, Keep only lang/tests (Windows) | |
| run: | | |
| Write-Host "Cleaning repository: Removing all directories except 'lang'" | |
| Get-ChildItem -Directory | Where-Object { $_.Name -ne "lang" } | Remove-Item -Recurse -Force | |
| Write-Host "Inside 'lang', removing all directories except 'tests'" | |
| Set-Location lang | |
| Get-ChildItem -Directory | Where-Object { $_.Name -ne "tests" } | Remove-Item -Recurse -Force | |
| Set-Location .. | |
| shell: pwsh | |
| - name: Create output directory | |
| run: New-Item -ItemType Directory -Path output -Force | |
| shell: pwsh | |
| - name: Process Windows Regular Variant | |
| run: | | |
| Write-Host "== Processing Windows Regular Variant ==" | |
| New-Item -ItemType Directory -Path variant-regular -Force | Out-Null | |
| Set-Location variant-regular | |
| Write-Host "Fetching asset URL for $env:ASSET_REGULAR..." | |
| $assetUrl = (Invoke-RestMethod -Uri "https://api.github.com/repos/$env:GITHUB_REPOSITORY/releases" -Headers @{ Authorization = "token $env:GITHUB_TOKEN" } | | |
| ForEach-Object { $_.assets } | Where-Object { $_.name -eq $env:ASSET_REGULAR } | Select-Object -First 1).browser_download_url | |
| if (-not $assetUrl) { | |
| Write-Error "Error: Asset $env:ASSET_REGULAR not found." | |
| exit 1 | |
| } | |
| Write-Host "Downloading asset from $assetUrl" | |
| Invoke-WebRequest -Uri $assetUrl -OutFile asset.zip | |
| Expand-Archive -Path asset.zip -DestinationPath . -Force | |
| $releaseRoot = (Get-ChildItem -Directory | Where-Object { $_.Name -ne "lang" } | Select-Object -First 1).FullName | |
| if (-not $releaseRoot) { | |
| Write-Error "Error: No release directory found." | |
| exit 1 | |
| } | |
| Write-Host "Using release root: $releaseRoot" | |
| if (-not (Test-Path -Path "$releaseRoot\lang\tests\build.lab")) { | |
| Copy-Item -Path ..\lang\tests -Destination "$releaseRoot\lang\tests" -Recurse | |
| } | |
| Set-Location $releaseRoot | |
| Write-Host "Running compile command for Windows Regular Variant:" | |
| Write-Host $env:COMPILER_CMD_REGULAR | Tee-Object -FilePath compile_output.txt | |
| Invoke-Expression $env:COMPILER_CMD_REGULAR | Tee-Object -FilePath compile_output.txt -Append | |
| Copy-Item -Path compile_output.txt -Destination ..\..\output\windows-regular-output.txt | |
| shell: pwsh | |
| - name: Process Windows TCC Variant | |
| run: | | |
| Write-Host "== Processing Windows TCC Variant ==" | |
| New-Item -ItemType Directory -Path variant-tcc -Force | Out-Null | |
| Set-Location variant-tcc | |
| Write-Host "Fetching asset URL for $env:ASSET_TCC..." | |
| $assetUrl = (Invoke-RestMethod -Uri "https://api.github.com/repos/$env:GITHUB_REPOSITORY/releases" -Headers @{ Authorization = "token $env:GITHUB_TOKEN" } | | |
| ForEach-Object { $_.assets } | Where-Object { $_.name -eq $env:ASSET_TCC } | Select-Object -First 1).browser_download_url | |
| if (-not $assetUrl) { | |
| Write-Error "Error: Asset $env:ASSET_TCC not found." | |
| exit 1 | |
| } | |
| Write-Host "Downloading asset from $assetUrl" | |
| Invoke-WebRequest -Uri $assetUrl -OutFile asset.zip | |
| Expand-Archive -Path asset.zip -DestinationPath . -Force | |
| $releaseRoot = (Get-ChildItem -Directory | Where-Object { $_.Name -ne "lang" } | Select-Object -First 1).FullName | |
| if (-not $releaseRoot) { | |
| Write-Error "Error: No release directory found." | |
| exit 1 | |
| } | |
| Write-Host "Using release root: $releaseRoot" | |
| if (-not (Test-Path -Path "$releaseRoot\lang\tests\build.lab")) { | |
| Copy-Item -Path ..\lang\tests -Destination "$releaseRoot\lang\tests" -Recurse | |
| } | |
| Set-Location $releaseRoot | |
| if (Test-Path "$releaseRoot\lang\tests\build") { Remove-Item "$releaseRoot\lang\tests\build" -Recurse -Force } | |
| Write-Host "Running compile command for Windows TCC Variant:" | |
| Write-Host $env:COMPILER_CMD_TCC | Tee-Object -FilePath compile_output.txt | |
| Invoke-Expression $env:COMPILER_CMD_TCC | Tee-Object -FilePath compile_output.txt -Append | |
| Copy-Item -Path compile_output.txt -Destination ..\..\output\windows-tcc-output.txt | |
| shell: pwsh | |
| - name: Upload Windows Outputs | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-tests-output | |
| path: output |