name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
permissions:
contents: write
env:
BINARY_NAME: oflow
jobs:
build:
name: Build ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
use-cross: false
extra-apt: musl-tools
- name: linux-aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use-cross: true
extra-apt: ""
- name: windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
use-cross: false
extra-apt: ""
- name: macos-x86_64
os: macos-latest
target: x86_64-apple-darwin
use-cross: false
extra-apt: ""
- name: macos-aarch64
os: macos-latest
target: aarch64-apple-darwin
use-cross: false
extra-apt: ""
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install system dependencies
if: matrix.extra-apt != ''
run: sudo apt-get update && sudo apt-get install -y ${{ matrix.extra-apt }}
- name: Install cross
if: matrix.use-cross == true
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build (cross)
if: matrix.use-cross == true
run: cross build --release --locked --target ${{ matrix.target }}
- name: Build (cargo)
if: matrix.use-cross == false
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Get version
shell: bash
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
- name: Package (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
ARCHIVE="${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.name }}.tar.gz"
cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} .
tar -czf "$ARCHIVE" "${{ env.BINARY_NAME }}" README.md LICENSE
echo "ASSET=$ARCHIVE" >> $GITHUB_ENV
- name: Package (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$ARCHIVE = "${{ env.BINARY_NAME }}-v${{ env.VERSION }}-${{ matrix.name }}.zip"
Copy-Item "target\${{ matrix.target }}\release\${{ env.BINARY_NAME }}.exe" .
Compress-Archive -Path "${{ env.BINARY_NAME }}.exe", "README.md", "LICENSE" -DestinationPath $ARCHIVE
echo "ASSET=$ARCHIVE" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ env.ASSET }}
retention-days: 1
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create Release and upload assets
uses: softprops/action-gh-release@v2
with:
files: artifacts/**
generate_release_notes: true draft: false
prerelease: ${{ contains(github.ref_name, '-') }}