name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
env:
BIN_NAME: orchid
CARGO_TERM_COLOR: always
jobs:
verify:
name: Verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Restore Rust cache
uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --locked --all-targets -- -D warnings
- name: Run tests
run: cargo test --locked --all-targets
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
exe: ""
- os: macos-latest
target: x86_64-apple-darwin
exe: ""
- os: macos-latest
target: aarch64-apple-darwin
exe: ""
- os: windows-latest
target: x86_64-pc-windows-msvc
exe: ".exe"
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Restore Rust cache
uses: Swatinem/rust-cache@v2
with:
shared-key: release-${{ matrix.target }}
- name: Resolve version
id: version
shell: bash
run: |
set -euo pipefail
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
echo "version=${version}" >> "${GITHUB_OUTPUT}"
if [[ "${GITHUB_REF_TYPE:-}" == "tag" && "${GITHUB_REF_NAME}" != "v${version}" ]]; then
echo "tag ${GITHUB_REF_NAME} does not match Cargo.toml version ${version}" >&2
exit 1
fi
- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package Unix
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
archive="${BIN_NAME}-${{ steps.version.outputs.version }}-${{ matrix.target }}"
mkdir -p "dist" "${archive}"
cp "target/${{ matrix.target }}/release/${BIN_NAME}" "${archive}/"
cp README.md LICENSE CHANGELOG.md "${archive}/"
tar -czf "dist/${archive}.tar.gz" "${archive}"
- name: Package Windows
if: runner.os == 'Windows'
shell: pwsh
run: |
$archive = "${env:BIN_NAME}-${{ steps.version.outputs.version }}-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path dist, $archive | Out-Null
Copy-Item "target/${{ matrix.target }}/release/${env:BIN_NAME}${{ matrix.exe }}" $archive
Copy-Item README.md, LICENSE, CHANGELOG.md $archive
Compress-Archive -Path "$archive/*" -DestinationPath "dist/$archive.zip"
- name: Upload workflow artifacts
uses: actions/upload-artifact@v7
with:
name: dist-${{ matrix.target }}
path: dist/*
- name: Upload GitHub Release assets
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v3
with:
files: dist/*