name: Release
on:
push:
tags:
- "[0-9][0-9].[0-9]+.[0-9]+"
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
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: aarch64-apple-darwin
os: macos-latest
use_cross: false
- target: x86_64-pc-windows-msvc
os: windows-latest
use_cross: false
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install cross (aarch64-unknown-linux-gnu)
if: matrix.use_cross
run: cargo install cross --locked
- name: Build release binary (cross)
if: matrix.use_cross
run: cross build --release --target ${{ matrix.target }}
- name: Build release binary (cargo)
if: "!matrix.use_cross"
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Stage artifact (Unix)
if: matrix.os != 'windows-latest'
shell: bash
run: |
set -euo pipefail
BINARY="target/${{ matrix.target }}/release/project-name"
ARTIFACT="project-name-${{ github.ref_name }}-${{ matrix.target }}"
cp "$BINARY" "$ARTIFACT"
echo "ARTIFACT=$ARTIFACT" >> "$GITHUB_ENV"
- name: Stage artifact (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$BINARY = "target/${{ matrix.target }}/release/project-name.exe"
$ARTIFACT = "project-name-${{ github.ref_name }}-${{ matrix.target }}.exe"
Copy-Item $BINARY $ARTIFACT
"ARTIFACT=$ARTIFACT" | Out-File -FilePath $env:GITHUB_ENV -Append
- uses: actions/upload-artifact@v4
with:
name: project-name-${{ github.ref_name }}-${{ matrix.target }}
path: ${{ env.ARTIFACT }}
if-no-files-found: error
retention-days: 1
release:
name: GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: artifacts/*