name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
jobs:
build-and-release:
name: Build and Release
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
binary-suffix: ""
archive-suffix: tar.gz
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
binary-suffix: ""
archive-suffix: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
binary-suffix: .exe
archive-suffix: zip
- os: macos-latest
target: x86_64-apple-darwin
binary-suffix: ""
archive-suffix: tar.gz
- os: macos-latest
target: aarch64-apple-darwin
binary-suffix: ""
archive-suffix: tar.gz
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl-tools (for musl target)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build binary
run: |
cargo build --release --target ${{ matrix.target }} --features cli
- name: Create archive name
id: archive
shell: bash
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
echo "name=lx-rs-${{ matrix.target }}" >> $GITHUB_OUTPUT
echo "file=lx-rs-${{ matrix.target }}.zip" >> $GITHUB_OUTPUT
else
echo "name=lx-rs-${{ matrix.target }}" >> $GITHUB_OUTPUT
echo "file=lx-rs-${{ matrix.target }}.tar.gz" >> $GITHUB_OUTPUT
fi
- name: Create archive (Unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar -czf ../../../${{ steps.archive.outputs.file }} lx-rs${{ matrix.binary-suffix }}
- name: Create archive (Windows)
if: matrix.os == 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
7z a ../../../${{ steps.archive.outputs.file }} lx-rs${{ matrix.binary-suffix }}
- name: Upload binary to release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: ${{ steps.archive.outputs.file }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-crates:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: build-and-release
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CRATES_TOKEN }}