name: Release
on:
release:
types: [published]
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
packages: write
jobs:
verify-version:
name: Verify version match
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get version from Cargo.toml
id: cargo
run: |
version=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
echo "version=$version" >> $GITHUB_OUTPUT
- name: Get version from tag
id: tag
run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
- name: Verify versions match
run: |
echo "Cargo.toml version: ${{ steps.cargo.outputs.version }}"
echo "Tag version: ${{ steps.tag.outputs.version }}"
if [ "${{ steps.cargo.outputs.version }}" != "${{ steps.tag.outputs.version }}" ]; then
echo "::error::Version mismatch! Cargo.toml has ${{ steps.cargo.outputs.version }} but tag is ${{ steps.tag.outputs.version }}"
exit 1
fi
echo "✓ Versions match"
build:
name: Build ${{ matrix.target }}
needs: verify-version
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
cross: true
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross (for cross-compilation)
if: matrix.cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ matrix.target }}-cargo-
- name: Build release binary
run: |
if [ "${{ matrix.cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
shell: bash
- name: Get version from tag
id: version
run: echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
shell: bash
- name: Prepare archive (Unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar czvf ../../../ivoryvalley-${{ steps.version.outputs.version }}-${{ matrix.target }}.tar.gz ivoryvalley
cd ../../..
- name: Prepare archive (Windows)
if: matrix.os == 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
7z a ../../../ivoryvalley-${{ steps.version.outputs.version }}-${{ matrix.target }}.zip ivoryvalley.exe
cd ../../..
shell: bash
- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
files: |
ivoryvalley-${{ steps.version.outputs.version }}-${{ matrix.target }}.${{ matrix.archive }}
- name: Upload binary artifact (Linux only)
if: contains(matrix.target, 'linux')
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.target }}
path: target/${{ matrix.target }}/release/ivoryvalley
retention-days: 1
publish-crates:
name: Publish to crates.io
needs: build
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Authenticate with crates.io
id: crates-io-auth
uses: rust-lang/crates-io-auth-action@v1
- name: Publish to crates.io
run: cargo publish --no-verify --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
docker:
name: Build Docker image
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download Linux amd64 binary
uses: actions/download-artifact@v4
with:
name: binary-x86_64-unknown-linux-gnu
path: binaries/linux/amd64
- name: Download Linux arm64 binary
uses: actions/download-artifact@v4
with:
name: binary-aarch64-unknown-linux-gnu
path: binaries/linux/arm64
- name: Make binaries executable
run: chmod +x binaries/linux/*/ivoryvalley
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.release
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max