name: Release
on:
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -Dwarnings
permissions:
contents: write
id-token: write
jobs:
validate:
name: Validate
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Read version and check tag
id: version
run: |
version=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
tag="v${version}"
if git rev-parse "$tag" >/dev/null 2>&1; then
echo "::error::Tag $tag already exists. Bump the version in Cargo.toml first."
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets
- run: cargo test
build:
name: Build (${{ matrix.target }})
needs: validate
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
- target: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
- target: aarch64-apple-darwin
runner: macos-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Tag for version string
run: git tag "v${{ needs.validate.outputs.version }}"
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package
run: |
dir="mlux-v${{ needs.validate.outputs.version }}-${{ matrix.target }}"
mkdir "$dir"
cp "target/${{ matrix.target }}/release/mlux" "$dir/"
cp LICENSE "$dir/"
cp fonts/OFL-NotoSansJP.txt "$dir/"
cp fonts/OFL-STIXTwoMath.txt "$dir/"
tar czf "$dir.tar.gz" "$dir"
- uses: actions/upload-artifact@v7
with:
name: mlux-v${{ needs.validate.outputs.version }}-${{ matrix.target }}
path: mlux-v${{ needs.validate.outputs.version }}-${{ matrix.target }}.tar.gz
release:
name: GitHub Release
needs: [validate, publish]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Create tag
run: |
git tag "${{ needs.validate.outputs.tag }}"
git push origin "${{ needs.validate.outputs.tag }}"
- uses: actions/download-artifact@v8
with:
path: artifacts
merge-multiple: true
- name: Create release
run: gh release create "${{ needs.validate.outputs.tag }}" --generate-notes artifacts/*.tar.gz
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: Publish to crates.io
needs: [validate, build]
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}