name: Build Binaries
on:
pull_request:
push:
branches:
- master
tags:
- "v*"
workflow_dispatch:
inputs:
release_tag:
description: "Optional v* tag to build and attach to its GitHub Release"
required: false
type: string
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- name: Linux x86_64
os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
archive: via-linux-x86_64.tar.gz
- name: Linux arm64
os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
archive: via-linux-arm64.tar.gz
- name: macOS x86_64
os: macos-15-intel
target: x86_64-apple-darwin
archive: via-macos-x86_64.tar.gz
- name: macOS arm64
os: macos-15
target: aarch64-apple-darwin
archive: via-macos-arm64.tar.gz
- name: Windows x86_64
os: windows-2025
target: x86_64-pc-windows-msvc
archive: via-windows-x86_64.zip
- name: Windows arm64
os: windows-11-arm
target: aarch64-pc-windows-msvc
archive: via-windows-arm64.zip
steps:
- name: Validate release tag
if: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag != '' }}
env:
RELEASE_TAG: ${{ inputs.release_tag }}
run: |
case "$RELEASE_TAG" in
v*) ;;
*)
echo "::error::release_tag must start with v"
exit 1
;;
esac
- name: Checkout
if: ${{ github.event_name != 'workflow_dispatch' || inputs.release_tag == '' }}
uses: actions/checkout@v4
- name: Checkout release tag
if: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag != '' }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.release_tag }}
- name: Install Rust
run: |
rustup toolchain install stable --profile minimal
rustup default stable
rustup target add ${{ matrix.target }}
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package Unix binary
if: runner.os != 'Windows'
shell: bash
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/via dist/via
tar -C dist -czf ${{ matrix.archive }} via
- name: Package Windows binary
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -ItemType Directory -Force dist | Out-Null
Copy-Item "target/${{ matrix.target }}/release/via.exe" "dist/via.exe"
Compress-Archive -Path "dist/via.exe" -DestinationPath "${{ matrix.archive }}" -Force
- name: Upload CI artifact
if: ${{ !startsWith(github.ref, 'refs/tags/v') && (github.event_name != 'workflow_dispatch' || inputs.release_tag == '') }}
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.archive }}
path: ${{ matrix.archive }}
if-no-files-found: error
- name: Ensure GitHub Release exists
if: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.release_tag != '') }}
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag || github.ref_name }}
run: |
if ! gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
gh release create "$RELEASE_TAG" --title "$RELEASE_TAG" --generate-notes || gh release view "$RELEASE_TAG" >/dev/null
fi
- name: Upload release asset
if: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.release_tag != '') }}
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.release_tag || github.ref_name }}
run: |
for attempt in 1 2 3; do
if gh release upload "$RELEASE_TAG" "${{ matrix.archive }}" --clobber; then
exit 0
fi
sleep $((attempt * 10))
done
echo "::error::Failed to upload ${{ matrix.archive }} to $RELEASE_TAG"
exit 1