Skip to content

fix(build): handle windows bun-build file rename (Workaround for Bun) #16

fix(build): handle windows bun-build file rename (Workaround for Bun)

fix(build): handle windows bun-build file rename (Workaround for Bun) #16

Workflow file for this run

permissions:
contents: write
packages: write
actions: read
on:
push:
branches:
- main
paths:
- "package.json"
- "src/**"
- ".github/**"
jobs:
build:
strategy:
matrix:
include:
- version: "linux-x64"
os: ubuntu-latest
platform: linux-x64-baseline
- version: "linux-arm64"
os: ubuntu-latest
platform: linux-arm64
- version: "windows-x64"
os: windows-latest
platform: windows-x64-baseline
# Wait https://github.com/oven-sh/bun/issues/9824
# - version: "windows-arm64"
# os: windows-latest
# platform: windows-arm64
- version: "darwin-x64"
os: ubuntu-latest
platform: darwin-x64
- version: "darwin-arm64"
os: ubuntu-latest
platform: darwin-arm64
runs-on: ${{ matrix.os }}
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
platform: ${{ steps.detect_platform.outputs.PLATFORM }}
binary_name: ${{ steps.setup_env.outputs.BINARY_NAME }}
archive_name: ${{ steps.setup_env.outputs.ARCHIVE_NAME }}
steps:
- uses: actions/checkout@v4
- uses: oven-sh/[email protected]
with:
bun-version: canary
- name: Detect Platform and Compress Format
id: detect_platform
shell: bash
run: |
PLATFORM="${{ matrix.version }}"
echo "PLATFORM=${PLATFORM}" >> $GITHUB_OUTPUT
echo "Current platform: ${PLATFORM}"
if [[ "${PLATFORM}" == *"linux"* ]]; then
echo "COMPRESS_FORMAT=tar.xz" >> $GITHUB_OUTPUT
else
echo "COMPRESS_FORMAT=zip" >> $GITHUB_OUTPUT
fi
- name: Extract version number
id: get_version
shell: bash
run: |
VERSION=$(jq -r .version < package.json)
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Setup Build Environment
id: setup_env
shell: bash
run: |
mkdir -p ${{ runner.temp }}/build/out
mkdir -p ${{ runner.temp }}/build/logs
echo "BINARY_NAME=aqua-speed-${{ steps.detect_platform.outputs.PLATFORM }}_v${{ steps.get_version.outputs.VERSION }}" >> $GITHUB_OUTPUT
echo "ARCHIVE_NAME=aqua-speed-${{ steps.detect_platform.outputs.PLATFORM }}_v${{ steps.get_version.outputs.VERSION }}.${{ steps.detect_platform.outputs.COMPRESS_FORMAT }}" >> $GITHUB_OUTPUT
- name: Update System
if: runner.os == 'Linux'
run: |
sudo apt-get update -y
sudo apt-get install -y --only-upgrade tar
- name: Install Dependencies (Linux)
if: runner.os == 'Linux'
uses: nick-fields/retry@v2
with:
timeout_seconds: 30
max_attempts: 3
retry_wait_seconds: 5
command: bun install || { echo "Failed to install dependencies"; exit 1; }
shell: bash
- name: Install Dependencies (Windows)
if: runner.os == 'Windows'
uses: nick-fields/retry@v2
with:
timeout_seconds: 30
max_attempts: 3
retry_wait_seconds: 5
command: bun install
shell: powershell
- name: Setup Windows Cache Directory
if: runner.os == 'Windows'
shell: powershell
run: |
$cacheDir = "$env:USERPROFILE\.bun\install\cache"
New-Item -Path $cacheDir -ItemType Directory -Force
$acl = Get-Acl $cacheDir
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($rule)
Set-Acl $cacheDir $acl
- name: Compile Code
if: runner.os != 'Windows'
shell: bash
run: |
bun build --compile --sourcemap --minify --bytecode \
--target=bun-${{ matrix.platform }} \
./src/cli.ts \
--outfile ${{ runner.temp }}/build/out/${{ steps.setup_env.outputs.BINARY_NAME }}
# https://github.com/oven-sh/bun/discussions/12247
# FIXME: Workaround!!!
- name: Compile Code (Windows)
if: runner.os == 'Windows'
shell: powershell
run: |
$buildDir = "${{ runner.temp }}/build/out"
# Run bun build without outfile
bun build --compile --sourcemap --minify --bytecode `
--target=bun-${{ matrix.platform }} `
./src/cli.ts
# Find the generated .bun-build file and rename it
Get-ChildItem -Path "." -Filter "*.bun-build" |
Select-Object -First 1 |
ForEach-Object {
Move-Item $_.FullName "$buildDir/${{ steps.setup_env.outputs.BINARY_NAME }}.exe" -Force
}
- name: Generate Checksums (Linux/macOS)
if: runner.os != 'Windows'
working-directory: ${{ runner.temp }}/build/out
shell: bash
run: |
sha1sum ${{ steps.setup_env.outputs.BINARY_NAME }}* > checksum.txt
- name: Generate Checksums (Windows)
if: runner.os == 'Windows'
working-directory: ${{ runner.temp }}/build/out
shell: powershell
run: |
$files = Get-ChildItem -Filter "${{ steps.setup_env.outputs.BINARY_NAME }}*"
$files | ForEach-Object {
$hash = Get-FileHash -Algorithm SHA1 -Path $_.FullName
"$($hash.Hash.ToLower()) $($_.Name)"
} | Set-Content -Path "checksum.txt" -Encoding utf8
- name: Compress artifacts (Linux)
if: startsWith(steps.detect_platform.outputs.PLATFORM, 'linux')
working-directory: ${{ runner.temp }}/build/out
shell: bash
run: |
tar -c -I 'xz -5 -T0' -f ${{ steps.setup_env.outputs.ARCHIVE_NAME }} ${{ steps.setup_env.outputs.BINARY_NAME }}* checksum.txt
rm -f ${{ steps.setup_env.outputs.BINARY_NAME }}
cp checksum.txt ${{ steps.setup_env.outputs.BINARY_NAME }}.checksum.txt
- name: Compress artifacts (macOS)
if: contains(steps.detect_platform.outputs.PLATFORM, 'darwin')
working-directory: ${{ runner.temp }}/build/out
shell: bash
run: |
zip -j ${{ steps.setup_env.outputs.ARCHIVE_NAME }} ${{ steps.setup_env.outputs.BINARY_NAME }}* checksum.txt
rm -f ${{ steps.setup_env.outputs.BINARY_NAME }}
cp checksum.txt ${{ steps.setup_env.outputs.BINARY_NAME }}.checksum.txt
- name: Compress artifacts (Windows)
if: runner.os == 'Windows'
working-directory: ${{ runner.temp }}/build/out
shell: powershell
run: |
$files = Get-ChildItem -Path "${{ steps.setup_env.outputs.BINARY_NAME }}*.exe", "checksum.txt"
Compress-Archive -Path $files -DestinationPath "${{ steps.setup_env.outputs.ARCHIVE_NAME }}" -Force
Get-ChildItem -Filter "${{ steps.setup_env.outputs.BINARY_NAME }}*.exe" | Remove-Item
Copy-Item -Path "checksum.txt" -Destination "${{ steps.setup_env.outputs.BINARY_NAME }}.checksum.txt" -Force
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.setup_env.outputs.ARCHIVE_NAME }}
path: |
${{ runner.temp }}/build/out/${{ steps.setup_env.outputs.ARCHIVE_NAME }}
${{ runner.temp }}/build/out/${{ steps.setup_env.outputs.BINARY_NAME }}.checksum.txt
retention-days: 1
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
pattern: "aqua-speed-*"
path: ${{ runner.temp }}/release/
merge-multiple: true
- name: Consolidate checksums
working-directory: ${{ runner.temp }}/release/
run: |
cat *.checksum.txt > checksums.txt
rm *.checksum.txt
- name: List all files in the temp directory
run: |
ls -la ${{ runner.temp }}/release/
- name: Get Previous Version
id: get_prev_version
uses: actions/github-script@v7
with:
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const currentVersion = '${{ needs.build.outputs.version }}';
console.log(`Releases: ${context.repo.owner}/${context.repo.repo}`, releases.data.map(r => r.tag_name));
console.log(`Creating version: v${currentVersion}`);
if (releases.data.length === 0) {
core.setOutput('version', 'first-commit');
core.setOutput('compare_url', `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/commits`);
core.setOutput('changes_text', 'all commits');
} else {
const previousRelease = releases.data[0];
const previousTag = previousRelease.tag_name;
const previousVersion = previousTag.replace('v', '');
console.log(`Previous version: ${previousTag}`);
core.setOutput('version', previousVersion);
core.setOutput('compare_url',
`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/compare/v${previousVersion}...v${currentVersion}`
);
core.setOutput('changes_text', `changes since v${previousVersion}`);
}
- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
artifacts: |
${{ runner.temp }}/release/*.tar.xz
${{ runner.temp }}/release/*.zip
${{ runner.temp }}/release/checksums.txt
token: ${{ github.token }}
tag: v${{ needs.build.outputs.version }}
name: Release ${{ needs.build.outputs.version }}
body: |
Release of version ${{ needs.build.outputs.version }}
[View ${{ steps.get_prev_version.outputs.changes_text }}](${{ steps.get_prev_version.outputs.compare_url }})
draft: false
prerelease: false
allowUpdates: true
generateReleaseNotes: true