|
| 1 | +name: 'Setup Bun Compile Runtime' |
| 2 | +description: 'Download and cache a Bun runtime used by bun build --compile-executable-path' |
| 3 | + |
| 4 | +inputs: |
| 5 | + target: |
| 6 | + description: 'Bun compile target, for example bun-windows-x64-baseline' |
| 7 | + required: true |
| 8 | + |
| 9 | +runs: |
| 10 | + using: 'composite' |
| 11 | + steps: |
| 12 | + - name: Get Bun version |
| 13 | + id: bun-version |
| 14 | + shell: bash |
| 15 | + run: echo "version=$(bun --version)" >> "$GITHUB_OUTPUT" |
| 16 | + |
| 17 | + - name: Cache Bun compile runtime |
| 18 | + uses: actions/cache@v5 |
| 19 | + with: |
| 20 | + path: ${{ runner.temp }}/bun-compile-runtimes/${{ inputs.target }}-v${{ steps.bun-version.outputs.version }} |
| 21 | + key: ${{ runner.os }}-bun-compile-runtime-${{ inputs.target }}-v${{ steps.bun-version.outputs.version }} |
| 22 | + |
| 23 | + - name: Prepare Bun compile runtime |
| 24 | + shell: pwsh |
| 25 | + env: |
| 26 | + BUN_COMPILE_TARGET: ${{ inputs.target }} |
| 27 | + BUN_VERSION: ${{ steps.bun-version.outputs.version }} |
| 28 | + RUNTIME_DIR: ${{ runner.temp }}/bun-compile-runtimes/${{ inputs.target }}-v${{ steps.bun-version.outputs.version }} |
| 29 | + run: | |
| 30 | + $ErrorActionPreference = 'Stop' |
| 31 | +
|
| 32 | + $runtimePath = Join-Path $env:RUNTIME_DIR 'bun.exe' |
| 33 | + if (!(Test-Path -LiteralPath $runtimePath)) { |
| 34 | + New-Item -ItemType Directory -Force -Path $env:RUNTIME_DIR | Out-Null |
| 35 | +
|
| 36 | + $zipPath = Join-Path $env:RUNTIME_DIR "$($env:BUN_COMPILE_TARGET).zip" |
| 37 | + $downloadUrl = "https://github.com/oven-sh/bun/releases/download/bun-v$($env:BUN_VERSION)/$($env:BUN_COMPILE_TARGET).zip" |
| 38 | +
|
| 39 | + Write-Host "Downloading $($env:BUN_COMPILE_TARGET): $downloadUrl" |
| 40 | + Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath |
| 41 | + Expand-Archive -LiteralPath $zipPath -DestinationPath $env:RUNTIME_DIR -Force |
| 42 | +
|
| 43 | + $extractedRuntimePath = Join-Path $env:RUNTIME_DIR "$($env:BUN_COMPILE_TARGET)/bun.exe" |
| 44 | + if (!(Test-Path -LiteralPath $extractedRuntimePath)) { |
| 45 | + throw "Downloaded $($env:BUN_COMPILE_TARGET), but bun.exe was not found at $extractedRuntimePath" |
| 46 | + } |
| 47 | +
|
| 48 | + Copy-Item -LiteralPath $extractedRuntimePath -Destination $runtimePath -Force |
| 49 | + } |
| 50 | +
|
| 51 | + "BUN_COMPILE_EXECUTABLE_PATH=$runtimePath" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 |
0 commit comments