name: Release
on:
push:
tags: ['v[0-9]*']
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
verify:
name: Verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --check
- run: cargo clippy -- -D warnings
- run: cargo test
- name: Check version matches tag
run: |
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
TAG_VERSION="${GITHUB_REF_NAME#v}"
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "Version mismatch: Cargo.toml has $CARGO_VERSION but tag is $GITHUB_REF_NAME"
exit 1
fi
build:
name: Build (${{ matrix.target }})
needs: verify
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
archive: zip
- os: windows-latest
target: aarch64-pc-windows-msvc
archive: zip
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package (Unix)
if: matrix.archive == 'tar.gz'
run: |
NAME="ark-${{ github.ref_name }}-${{ matrix.target }}"
mkdir dist
cp target/${{ matrix.target }}/release/ark dist/ark
tar -czf "dist/$NAME.tar.gz" -C dist ark
sha256sum "dist/$NAME.tar.gz" > "dist/$NAME.tar.gz.sha256"
- name: Package (Windows)
if: matrix.archive == 'zip'
shell: pwsh
run: |
$name = "ark-${{ github.ref_name }}-${{ matrix.target }}"
New-Item -ItemType Directory -Path dist | Out-Null
Copy-Item "target/${{ matrix.target }}/release/ark.exe" dist/ark.exe
Compress-Archive -Path dist/ark.exe -DestinationPath "dist/$name.zip"
$hash = (Get-FileHash "dist/$name.zip" -Algorithm SHA256).Hash.ToLower()
"$hash $name.zip" | Out-File -Encoding ascii "dist/$name.zip.sha256"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: dist/
publish:
name: Publish to crates.io
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
release:
name: GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create release
run: |
gh release create "${{ github.ref_name }}" artifacts/** \
--title "${{ github.ref_name }}" \
--generate-notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}