name: Release
on:
release:
types: [created]
permissions:
contents: write
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: x86_64-apple-darwin
os: macos-latest
use_cross: false
- target: aarch64-apple-darwin
os: macos-latest
use_cross: false
- target: x86_64-pc-windows-msvc
os: windows-latest
use_cross: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Cargo registry & build artefacts
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Install cross (Linux ARM64 only)
if: matrix.use_cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build release binary
run: |
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
shell: bash
- name: Package — Unix (tar.gz)
if: runner.os != 'Windows'
run: |
BINARY=target/${{ matrix.target }}/release/iwatchr
ARCHIVE=iwatchr-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
tar -czf "$ARCHIVE" -C "$(dirname $BINARY)" "$(basename $BINARY)"
echo "ASSET=$ARCHIVE" >> "$GITHUB_ENV"
shell: bash
- name: Package — Windows (zip)
if: runner.os == 'Windows'
run: |
$binary = "target\${{ matrix.target }}\release\iwatchr.exe"
$archive = "iwatchr-${{ github.ref_name }}-${{ matrix.target }}.zip"
Compress-Archive -Path $binary -DestinationPath $archive
"ASSET=$archive" | Out-File -FilePath $env:GITHUB_ENV -Append
shell: pwsh
- name: Upload release asset
uses: softprops/action-gh-release@v2
with:
files: ${{ env.ASSET }}
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Publish
run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }}