try windows edition #97
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: PR Windows Build | |
| on: | |
| pull_request: | |
| paths: | |
| - "Dockerfile.windows" | |
| - "build-windows.ps1" | |
| - ".github/workflows/pr-build-windows.yml" | |
| jobs: | |
| build-windows: | |
| runs-on: windows-2022 | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Get bootstrap script hash | |
| id: bootstrap-hash | |
| run: | | |
| $content = (Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/oven-sh/bun/main/scripts/bootstrap.ps1').Content | |
| $bytes = [System.Text.Encoding]::UTF8.GetBytes($content) | |
| $hash = (Get-FileHash -InputStream ([System.IO.MemoryStream]::new($bytes)) -Algorithm SHA256).Hash | |
| $shortHash = $hash.Substring(0, 7) | |
| echo "HASH=$shortHash" >> $env:GITHUB_OUTPUT | |
| shell: pwsh | |
| - name: Get Bun repo commit SHA | |
| id: bun-sha | |
| run: | | |
| $sha = gh api repos/oven-sh/bun/commits/main --jq .sha | |
| $shortSha = $sha.Substring(0, 7) | |
| echo "SHA=$shortSha" >> $env:GITHUB_OUTPUT | |
| shell: pwsh | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # === BOOTSTRAP STAGE === | |
| - name: Pull bootstrap cache | |
| run: | | |
| docker pull ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }}-pr-${{ github.event.number }} || docker pull ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} || true | |
| shell: pwsh | |
| - name: Build bootstrap stage | |
| run: | | |
| docker build ` | |
| --isolation=process ` | |
| --memory 14g ` | |
| --pull ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| -f Dockerfile.windows ` | |
| --target bootstrap ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }}-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-bootstrap-pr-${{ github.event.number }} ` | |
| . | |
| shell: pwsh | |
| - name: Push bootstrap stage (background) | |
| run: | | |
| Start-Job -Name "push-bootstrap" -ScriptBlock { | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }}-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-bootstrap-pr-${{ github.event.number }} | |
| } | |
| shell: pwsh | |
| # === BASE STAGE === | |
| - name: Pull base cache | |
| run: | | |
| docker pull ghcr.io/${{ github.repository }}-windows:preview-base-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} || docker pull ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} || true | |
| shell: pwsh | |
| - name: Build base stage | |
| run: | | |
| docker build ` | |
| --isolation=process ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --build-arg CACHEBUST=${{ steps.bun-sha.outputs.SHA }} ` | |
| -f Dockerfile.windows ` | |
| --target base ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-base-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-base-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-base-amd64-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-base-pr-${{ github.event.number }} ` | |
| . | |
| shell: pwsh | |
| - name: Push base stage (background) | |
| run: | | |
| Start-Job -Name "push-base" -ScriptBlock { | |
| Get-Job -Name "push-bootstrap" | Wait-Job | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-base-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-base-amd64-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-base-pr-${{ github.event.number }} | |
| } | |
| shell: pwsh | |
| # === PREBUILT STAGE === | |
| - name: Pull prebuilt cache | |
| run: | | |
| docker pull ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} || docker pull ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} || true | |
| shell: pwsh | |
| - name: Build prebuilt stage | |
| run: | | |
| docker build ` | |
| --isolation=process ` | |
| --memory 14g ` | |
| --cpu-quota="300000" ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --build-arg CACHEBUST=${{ steps.bun-sha.outputs.SHA }} ` | |
| -f Dockerfile.windows ` | |
| --target prebuilt ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-base-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-prebuilt-pr-${{ github.event.number }} ` | |
| . | |
| shell: pwsh | |
| - name: Push prebuilt stage (background) | |
| run: | | |
| Start-Job -Name "push-prebuilt" -ScriptBlock { | |
| Get-Job -Name "push-base" | Wait-Job | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-prebuilt-pr-${{ github.event.number }} | |
| } | |
| shell: pwsh | |
| # === ARTIFACTS STAGE === | |
| - name: Pull artifacts cache | |
| run: | | |
| docker pull ghcr.io/${{ github.repository }}-windows:preview-artifacts-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} || docker pull ghcr.io/${{ github.repository }}-windows:artifacts-amd64-${{ steps.bun-sha.outputs.SHA }} || true | |
| shell: pwsh | |
| - name: Build artifacts stage | |
| run: | | |
| docker build ` | |
| --isolation=process ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --build-arg CACHEBUST=${{ steps.bun-sha.outputs.SHA }} ` | |
| -f Dockerfile.windows ` | |
| --target artifacts ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-base-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-artifacts-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:artifacts-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-artifacts-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-artifacts-amd64-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-artifacts-pr-${{ github.event.number }} ` | |
| . | |
| shell: pwsh | |
| - name: Push artifacts stage (background) | |
| run: | | |
| Start-Job -Name "push-artifacts" -ScriptBlock { | |
| Get-Job -Name "push-prebuilt" | Wait-Job | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-artifacts-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-artifacts-amd64-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-artifacts-pr-${{ github.event.number }} | |
| } | |
| shell: pwsh | |
| # === RUN STAGE === | |
| - name: Pull run cache | |
| run: | | |
| docker pull ghcr.io/${{ github.repository }}-windows:preview-run-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} || docker pull ghcr.io/${{ github.repository }}-windows:run-amd64-${{ steps.bun-sha.outputs.SHA }} || true | |
| shell: pwsh | |
| - name: Build run stage | |
| run: | | |
| docker build ` | |
| --isolation=process ` | |
| --build-arg BOOTSTRAP_HASH=${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --build-arg CACHEBUST=${{ steps.bun-sha.outputs.SHA }} ` | |
| -f Dockerfile.windows ` | |
| --target run ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:bootstrap-amd64-${{ steps.bootstrap-hash.outputs.HASH }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-base-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:base-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:prebuilt-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:preview-run-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| --cache-from ghcr.io/${{ github.repository }}-windows:run-amd64-${{ steps.bun-sha.outputs.SHA }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-run-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-run-amd64-pr-${{ github.event.number }} ` | |
| -t ghcr.io/${{ github.repository }}-windows:preview-run-pr-${{ github.event.number }} ` | |
| . | |
| shell: pwsh | |
| - name: Push run stage (background) | |
| run: | | |
| Start-Job -Name "push-run" -ScriptBlock { | |
| Get-Job -Name "push-artifacts" | Wait-Job | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-run-amd64-${{ steps.bun-sha.outputs.SHA }}-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-run-amd64-pr-${{ github.event.number }} | |
| docker push ghcr.io/${{ github.repository }}-windows:preview-run-pr-${{ github.event.number }} | |
| } | |
| shell: pwsh | |
| # === ENSURE ALL UPLOADS COMPLETED === | |
| - name: Ensure all uploads completed successfully | |
| run: | | |
| $jobs = Get-Job | |
| if ($jobs) { | |
| Write-Host "Waiting for all background uploads to complete..." -ForegroundColor Cyan | |
| $jobs | Wait-Job | Out-Null | |
| Write-Host "`nBackground job output:" -ForegroundColor Yellow | |
| foreach ($job in $jobs) { | |
| Write-Host "`n[$($job.Name)] - State: $($job.State)" -ForegroundColor Magenta | |
| $output = Receive-Job -Job $job | |
| if ($output) { | |
| $output | ForEach-Object { Write-Host " $_" } | |
| } | |
| } | |
| $failed = $jobs | Where-Object { $_.State -eq 'Failed' } | |
| if ($failed) { | |
| Write-Host "`nFailed jobs detected!" -ForegroundColor Red | |
| $jobs | Remove-Job | |
| throw "One or more uploads failed" | |
| } | |
| Write-Host "`nAll uploads completed successfully" -ForegroundColor Green | |
| $jobs | Remove-Job | |
| } | |
| shell: pwsh | |
| # === TEST === | |
| - name: Test prebuilt container | |
| run: | | |
| @" | |
| FROM ghcr.io/${{ github.repository }}-windows:preview-prebuilt-amd64-pr-${{ github.event.number }} | |
| RUN C:\workspace\bun\build\debug\bun-debug.exe --version | |
| CMD ["C:\\workspace\\bun\\build\\debug\\bun-debug.exe", "--version"] | |
| "@ | Out-File -FilePath Dockerfile.test -Encoding utf8 | |
| docker build --isolation=process -f Dockerfile.test -t test-bun-pr-${{ github.event.number }} . | |
| docker run --isolation=process --rm test-bun-pr-${{ github.event.number }} | |
| shell: pwsh |