name: Release Binary
on:
push:
tags:
- 'v*.*.*'
env:
REPO_NAME: ${{ github.event.repository.name }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- os: linux
arch: x86_64
target: x86_64-unknown-linux-gnu
ext: ""
- os: linux
arch: aarch64
target: aarch64-unknown-linux-gnu
ext: ""
- os: freebsd
arch: x86_64
target: x86_64-unknown-freebsd
ext: ""
steps:
- uses: actions/checkout@v5
- name: Setup Python 3.11
id: setup-python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Verify tag matches Cargo.toml
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME#v}"
export CARGO_TOML_PATH="${CARGO_TOML_PATH:-Cargo.toml}"
python_script="import os, pathlib, tomllib; print(tomllib.loads(pathlib.Path(os.environ['CARGO_TOML_PATH']).read_text(encoding='utf-8'))['package']['version'])"
cargo_version="$(echo "${python_script}" | "${{ steps.setup-python.outputs.python-path }}")"
if [ -z "${cargo_version:-}" ]; then
echo "::error title=Cargo.toml parse failure::Could not read package.version from ${toml_path}. Ensure Python ≥3.11 (tomllib available) and that the manifest contains [package], or set CARGO_TOML_PATH to the crate's Cargo.toml."
exit 1
fi
if [ "$tag" != "$cargo_version" ]; then
echo "::error title=Tag/Cargo.toml mismatch::Tag version $tag does not match Cargo.toml version $cargo_version"
exit 1
fi
echo "Release tag $tag matches Cargo.toml version."
- name: Setup Rust
uses: leynos/shared-actions/.github/actions/setup-rust@f9f1c863c8a5bef64aa6779caa746e1a4a6c1ad4
- name: Cache cross binary
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cross
key: cross-v0.2.5-${{ runner.os }}
- name: Install cross
env:
RUSTFLAGS: ""
run: cargo install cross --git https://github.com/cross-rs/cross --tag v0.2.5
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Add release target
run: rustup target add ${{ matrix.target }}
- name: Build release binary
run: cross +stable build --release --target ${{ matrix.target }}
- name: Prepare artifact
run: |
mkdir -p artifacts/${{ matrix.os }}-${{ matrix.arch }}
cp target/${{ matrix.target }}/release/${{ env.REPO_NAME }}${{ matrix.ext }} \
artifacts/${{ matrix.os }}-${{ matrix.arch }}/${{ env.REPO_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}
sha256sum artifacts/${{ matrix.os }}-${{ matrix.arch }}/${{ env.REPO_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} > \
artifacts/${{ matrix.os }}-${{ matrix.arch }}/${{ env.REPO_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}.sha256
- name: Upload release artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.REPO_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
path: artifacts/${{ matrix.os }}-${{ matrix.arch }}
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
- uses: actions/download-artifact@v4
with:
path: artifacts
- run: |
for dir in artifacts/${{ env.REPO_NAME }}-*; do
for file in "$dir"/*; do
gh release upload "${{ github.ref_name }}" "$file"
done
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}