name: Release
on:
push:
tags: ["v*"]
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
packages: musl-tools
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v5
- name: Verify the tag matches the crate version
shell: bash
run: |
# A prerelease tag such as v0.1.0-rc.1 is allowed to carry a suffix
# the manifest does not; compare the release version itself.
tag="${GITHUB_REF_NAME#v}"
tag="${tag%%-*}"
crate=$(cargo metadata --no-deps --format-version 1 \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["packages"][0]["version"])')
if [ "$tag" != "$crate" ]; then
echo "tag $GITHUB_REF_NAME does not match Cargo.toml version $crate" >&2
exit 1
fi
- name: Install cross-compilation packages
if: matrix.packages != ''
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends ${{ matrix.packages }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
name="diffier-${version}-${{ matrix.target }}"
mkdir -p "dist/$name"
cp "target/${{ matrix.target }}/release/diffier" "dist/$name/"
cp README.md LICENSE "dist/$name/"
tar -C dist -czf "dist/$name.tar.gz" "$name"
cd dist
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$name.tar.gz" > "$name.tar.gz.sha256"
else
shasum -a 256 "$name.tar.gz" > "$name.tar.gz.sha256"
fi
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: |
dist/*.tar.gz
dist/*.tar.gz.sha256
if-no-files-found: error
retention-days: 7
release:
name: Publish release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create the GitHub release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
ls -l artifacts
# A tag such as v0.1.0-rc.1 carries a hyphen; ship it as a prerelease.
prerelease=""
case "$GITHUB_REF_NAME" in
*-*) prerelease="--prerelease" ;;
esac
gh release create "$GITHUB_REF_NAME" \
--verify-tag \
--generate-notes \
$prerelease \
artifacts/*