name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
use_cross: false
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
use_cross: true
- target: x86_64-apple-darwin
os: macos-14
use_cross: false
- target: aarch64-apple-darwin
os: macos-latest
use_cross: false
- target: x86_64-pc-windows-msvc
os: windows-latest
use_cross: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.use_cross
run: cargo install cross --version 0.2.5
- name: Build (cross)
if: matrix.use_cross
run: cross build --release --target ${{ matrix.target }}
env:
CROSS_CONTAINER_ENGINE: docker
- name: Build (cargo)
if: "!matrix.use_cross"
run: cargo build --release --target ${{ matrix.target }}
- name: Determine binary name
id: binary
shell: bash
run: echo "name=$(cargo metadata --no-deps --format-version 1 | python3 -c 'import json,sys; d=json.load(sys.stdin); bins=[t["name"] for p in d["packages"] for t in p.get("targets",[]) if "bin" in t.get("kind",[])] ; print(bins[0] if bins else d["packages"][0]["name"])')" >> $GITHUB_OUTPUT
- name: Package (Unix)
if: runner.os != 'Windows'
run: tar czf ${{ steps.binary.outputs.name }}-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release ${{ steps.binary.outputs.name }}
- name: Package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: Compress-Archive -Path target/${{ matrix.target }}/release/${{ steps.binary.outputs.name }}.exe -DestinationPath ${{ steps.binary.outputs.name }}-${{ matrix.target }}.zip
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.binary.outputs.name }}-${{ matrix.target }}
path: ${{ steps.binary.outputs.name }}-${{ matrix.target }}.*
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Create GitHub Release
run: |
gh release create ${{ github.ref_name }} \
--generate-notes \
artifacts/**/*
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-features -- -D warnings
- run: cargo test --all-features
- name: Publish to crates.io
run: cargo publish --allow-dirty || true
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}