name: Release
on:
push:
tags: [ "v*" ]
env:
CARGO_TERM_COLOR: always
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
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
use_cross: true
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Install cross (aarch64-linux only)
if: ${{ matrix.use_cross == true }}
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Build (native)
if: ${{ !matrix.use_cross }}
run: cargo build --release --target ${{ matrix.target }}
- name: Build (cross)
if: ${{ matrix.use_cross == true }}
run: cross build --release --target ${{ matrix.target }}
- name: Package (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
BIN="target/${{ matrix.target }}/release/cargo-crap"
ARCHIVE="cargo-crap-${{ matrix.target }}.tar.gz"
tar czf "$ARCHIVE" -C "$(dirname "$BIN")" "$(basename "$BIN")"
echo "ARCHIVE=$ARCHIVE" >> "$GITHUB_ENV"
- name: Package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$bin = "target\${{ matrix.target }}\release\cargo-crap.exe"
$archive = "cargo-crap-${{ matrix.target }}.zip"
Compress-Archive -Path $bin -DestinationPath $archive
"ARCHIVE=$archive" | Out-File -FilePath $env:GITHUB_ENV -Append
- uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.target }}
path: ${{ env.ARCHIVE }}
release:
name: GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: binary-*
merge-multiple: true
path: artifacts
- uses: softprops/action-gh-release@v2
with:
files: artifacts/*
generate_release_notes: true
publish:
name: Publish to crates.io
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Publish
run: cargo publish --no-verify
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}