ci: switch release workflow to Linux cross-compilation (#50)

* ci: cross-compile release assets on Linux

* ci: use OS runners and Linux-only cross-arch builds

* ci: sanitize non-release artifact version tags
This commit is contained in:
existedinnettw 2026-04-11 21:31:13 +08:00 committed by GitHub
parent e92b8b970c
commit 1e2852eac4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 10 deletions

View File

@ -4,13 +4,16 @@ on:
release:
types:
- published
pull_request:
paths:
- .github/workflows/release.yaml
permissions:
contents: write
contents: read
jobs:
build:
name: Build ${{ matrix.target_os }}-${{ matrix.arch }}
name: Build ${{ matrix.target_os }}-${{ matrix.target_arch }}
runs-on: ${{ matrix.runs_on }}
strategy:
fail-fast: false
@ -18,19 +21,19 @@ jobs:
include:
- runs_on: ubuntu-24.04
target_os: linux
arch: x64
target_arch: x64
ext: ''
- runs_on: ubuntu-24.04-arm
- runs_on: ubuntu-24.04
target_os: linux
arch: arm64
target_arch: arm64
ext: ''
- runs_on: macos-14
target_os: macos
arch: arm64
target_arch: arm64
ext: ''
- runs_on: windows-2022
target_os: windows
arch: x64
target_arch: x64
ext: .exe
steps:
@ -45,26 +48,41 @@ jobs:
run: dart run build_runner build --delete-conflicting-outputs
- name: Build executable
run: dart compile exe bin/code_work_spawner.dart -o dist/code_work_spawner${{ matrix.ext }}
shell: bash
run: |
mkdir -p dist
if [[ "${{ matrix.target_os }}" == "linux" ]]; then
dart compile exe bin/code_work_spawner.dart --target-os=linux --target-arch=${{ matrix.target_arch }} -o dist/code_work_spawner${{ matrix.ext }}
else
dart compile exe bin/code_work_spawner.dart -o dist/code_work_spawner${{ matrix.ext }}
fi
- name: Prepare release asset
shell: bash
run: |
mkdir -p release-assets
asset_name="code_work_spawner-${{ github.ref_name }}-${{ matrix.target_os }}-${{ matrix.arch }}${{ matrix.ext }}"
if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
version_tag="${GITHUB_REF_NAME}"
else
version_tag="${GITHUB_REF_NAME//\//-}"
fi
asset_name="code_work_spawner-${version_tag}-${{ matrix.target_os }}-${{ matrix.target_arch }}${{ matrix.ext }}"
cp "dist/code_work_spawner${{ matrix.ext }}" "release-assets/${asset_name}"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: code_work_spawner-${{ matrix.target_os }}-${{ matrix.arch }}
name: code_work_spawner-${{ matrix.target_os }}-${{ matrix.target_arch }}
path: release-assets/*
if-no-files-found: error
publish:
name: Upload release assets
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4