on:
push:
tags:
- "v[0-9]*" - "v[0-9]*-rc*"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: 🚀 Release 🚀
jobs:
build-binaries:
name: 📦 Build (${{ matrix.target }}) 📦
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use-cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use-cross: true
- os: macos-latest
target: x86_64-apple-darwin
use-cross: false
- os: macos-latest
target: aarch64-apple-darwin
use-cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
use-cross: false
steps:
- name: ✅ Checkout ✅
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- name: 🦀 Install Rust toolchain 🦀
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: 📦 Install cargo-binstall 📦
uses: cargo-bins/cargo-binstall@aaa84a43aec4955a42c5ffc65d258961e39f276e
- name: 🔧 Install cross 🔧
if: matrix.use-cross
run: cargo binstall --no-confirm --maximum-resolution-timeout 20 cross
- name: 🏗️ Build 🏗️
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) 📁
if: runner.os != 'Windows'
run: |
VERSION="${GITHUB_REF_NAME#v}"
ARCHIVE="cargo-matrix-${{ matrix.target }}-v${VERSION}.tar.gz"
cp "target/${{ matrix.target }}/release/cargo-matrix" ./cargo-matrix
tar czf "$ARCHIVE" cargo-matrix
echo "ASSET=$ARCHIVE" >> "$GITHUB_ENV"
shell: bash
- name: 📁 Package (Windows) 📁
if: runner.os == 'Windows'
run: |
$VERSION = $env:GITHUB_REF_NAME -replace '^v', ''
$ARCHIVE = "cargo-matrix-${{ matrix.target }}-v${VERSION}.zip"
Copy-Item "target\${{ matrix.target }}\release\cargo-matrix.exe" "cargo-matrix.exe"
Compress-Archive -Path cargo-matrix.exe -DestinationPath $ARCHIVE
"ASSET=$ARCHIVE" | Out-File -FilePath $env:GITHUB_ENV -Append
shell: pwsh
- name: ⬆️ Upload artifact ⬆️
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: binary-${{ matrix.target }}
path: ${{ env.ASSET }}
if-no-files-found: error
release:
name: 📝 Create GitHub Release 📝
needs: build-binaries
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: ✅ Checkout ✅
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- name: 🦀 Install Rust toolchain 🦀
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
with:
toolchain: stable
- name: 📦 Publish to crates.io 📦
if: ${{ !contains(github.ref_name, '-rc') }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish
- name: ⬇️ Download artifacts ⬇️
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
with:
pattern: binary-*
path: dist
merge-multiple: true
- name: 🚀 Create GitHub Release 🚀
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda
with:
tag_name: ${{ github.ref_name }}
generate_release_notes: true
prerelease: ${{ contains(github.ref_name, '-rc') }}
files: dist/*