diff --git a/.github/actions/setup-bun-compile-runtime/action.yml b/.github/actions/setup-bun-compile-runtime/action.yml new file mode 100644 index 0000000000..0628278d7d --- /dev/null +++ b/.github/actions/setup-bun-compile-runtime/action.yml @@ -0,0 +1,51 @@ +name: 'Setup Bun Compile Runtime' +description: 'Download and cache a Bun runtime used by bun build --compile-executable-path' + +inputs: + target: + description: 'Bun compile target, for example bun-windows-x64-baseline' + required: true + +runs: + using: 'composite' + steps: + - name: Get Bun version + id: bun-version + shell: bash + run: echo "version=$(bun --version)" >> "$GITHUB_OUTPUT" + + - name: Cache Bun compile runtime + uses: actions/cache@v5 + with: + path: ${{ runner.temp }}/bun-compile-runtimes/${{ inputs.target }}-v${{ steps.bun-version.outputs.version }} + key: ${{ runner.os }}-bun-compile-runtime-${{ inputs.target }}-v${{ steps.bun-version.outputs.version }} + + - name: Prepare Bun compile runtime + shell: pwsh + env: + BUN_COMPILE_TARGET: ${{ inputs.target }} + BUN_VERSION: ${{ steps.bun-version.outputs.version }} + RUNTIME_DIR: ${{ runner.temp }}/bun-compile-runtimes/${{ inputs.target }}-v${{ steps.bun-version.outputs.version }} + run: | + $ErrorActionPreference = 'Stop' + + $runtimePath = Join-Path $env:RUNTIME_DIR 'bun.exe' + if (!(Test-Path -LiteralPath $runtimePath)) { + New-Item -ItemType Directory -Force -Path $env:RUNTIME_DIR | Out-Null + + $zipPath = Join-Path $env:RUNTIME_DIR "$($env:BUN_COMPILE_TARGET).zip" + $downloadUrl = "https://github.com/oven-sh/bun/releases/download/bun-v$($env:BUN_VERSION)/$($env:BUN_COMPILE_TARGET).zip" + + Write-Host "Downloading $($env:BUN_COMPILE_TARGET): $downloadUrl" + Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath + Expand-Archive -LiteralPath $zipPath -DestinationPath $env:RUNTIME_DIR -Force + + $extractedRuntimePath = Join-Path $env:RUNTIME_DIR "$($env:BUN_COMPILE_TARGET)/bun.exe" + if (!(Test-Path -LiteralPath $extractedRuntimePath)) { + throw "Downloaded $($env:BUN_COMPILE_TARGET), but bun.exe was not found at $extractedRuntimePath" + } + + Copy-Item -LiteralPath $extractedRuntimePath -Destination $runtimePath -Force + } + + "BUN_COMPILE_EXECUTABLE_PATH=$runtimePath" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 diff --git a/.github/workflows/cli-release-build.yml b/.github/workflows/cli-release-build.yml index 758794d880..741b32bbd7 100644 --- a/.github/workflows/cli-release-build.yml +++ b/.github/workflows/cli-release-build.yml @@ -315,13 +315,18 @@ jobs: echo "$ENV_OVERRIDES" | jq -r 'to_entries | .[] | .key + "=" + .value' >> $GITHUB_ENV fi + - name: Prepare Windows baseline Bun compile runtime + uses: ./.github/actions/setup-bun-compile-runtime + with: + target: bun-windows-x64-baseline + - name: Build binary run: bun run scripts/build-binary.ts ${{ inputs.binary-name }} ${{ inputs.new-version }} working-directory: cli shell: bash env: VERBOSE: true - OVERRIDE_TARGET: bun-windows-x64 + OVERRIDE_TARGET: bun-windows-x64-baseline OVERRIDE_PLATFORM: win32 OVERRIDE_ARCH: x64 diff --git a/.github/workflows/freebuff-e2e.yml b/.github/workflows/freebuff-e2e.yml index a090ade3ab..f1fc8afbba 100644 --- a/.github/workflows/freebuff-e2e.yml +++ b/.github/workflows/freebuff-e2e.yml @@ -162,6 +162,11 @@ jobs: echo "NEXT_PUBLIC_CB_ENVIRONMENT=prod" >> $GITHUB_ENV echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV + - name: Prepare Windows baseline Bun compile runtime + uses: ./.github/actions/setup-bun-compile-runtime + with: + target: bun-windows-x64-baseline + - name: Build Freebuff binary run: bun freebuff/cli/build.ts 0.0.0-e2e shell: bash diff --git a/.github/workflows/npm-app-release-build.yml b/.github/workflows/npm-app-release-build.yml index 486716d0de..691a41a6e4 100644 --- a/.github/workflows/npm-app-release-build.yml +++ b/.github/workflows/npm-app-release-build.yml @@ -53,7 +53,7 @@ jobs: arch: arm64 - os: windows-latest target: win32-x64 - bun_target: bun-windows-x64 + bun_target: bun-windows-x64-baseline platform: win32 arch: x64 runs-on: ${{ matrix.os }} diff --git a/cli/scripts/build-binary.ts b/cli/scripts/build-binary.ts index 5888808b41..3401e85288 100644 --- a/cli/scripts/build-binary.ts +++ b/cli/scripts/build-binary.ts @@ -28,6 +28,8 @@ const OVERRIDE_PLATFORM = process.env.OVERRIDE_PLATFORM as | NodeJS.Platform | undefined const OVERRIDE_ARCH = process.env.OVERRIDE_ARCH ?? undefined +const OVERRIDE_COMPILE_EXECUTABLE_PATH = + process.env.BUN_COMPILE_EXECUTABLE_PATH const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) @@ -95,7 +97,7 @@ function getTargetInfo(): TargetInfo { arch: 'arm64', }, 'win32-x64': { - bunTarget: 'bun-windows-x64', + bunTarget: 'bun-windows-x64-baseline', platform: 'win32', arch: 'x64', }, @@ -172,6 +174,9 @@ async function main() { '--compile', '--production', // Required so compiled binaries use the production JSX runtime (avoids jsxDEV crashes). `--target=${targetInfo.bunTarget}`, + ...(OVERRIDE_COMPILE_EXECUTABLE_PATH + ? [`--compile-executable-path=${OVERRIDE_COMPILE_EXECUTABLE_PATH}`] + : []), `--outfile=${outputFile}`, '--sourcemap=none', ...defineFlags.flatMap(([key, value]) => ['--define', `${key}=${value}`]),