fix(workflow): Improve Windows platform support #12
This file contains 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
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 | |
- version: "linux-arm64" | |
os: ubuntu-latest | |
platform: linux-arm64 | |
- version: "windows-x64" | |
os: windows-latest | |
platform: win32-x64 | |
- version: "windows-arm64" | |
os: windows-latest | |
platform: win32-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: Compile Code | |
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 }} | |
- 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: | | |
Get-FileHash -Algorithm SHA1 ${{ steps.setup_env.outputs.BINARY_NAME }}* | ForEach-Object { "$($_.Hash.ToLower()) $($_.Path.Split('\')[-1])" } | Out-File -Encoding utf8 checksum.txt | |
- 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: | | |
Compress-Archive -Path "${{ steps.setup_env.outputs.BINARY_NAME }}*.exe","checksum.txt" -DestinationPath "${{ steps.setup_env.outputs.ARCHIVE_NAME }}" | |
Remove-Item "${{ steps.setup_env.outputs.BINARY_NAME }}*.exe" | |
Copy-Item "checksum.txt" "${{ steps.setup_env.outputs.BINARY_NAME }}.checksum.txt" | |
- 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 |