name: Release
on:
pull_request:
types: [closed]
branches: [master]
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
id-token: write
jobs:
build-artifacts:
if: github.head_ref == 'release' && github.event.pull_request.merged == true
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use-cross: false
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
use-cross: true
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use-cross: true
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
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:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install cross
if: matrix.use-cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build binary
run: |
if [ "${{ matrix.use-cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
shell: bash
- name: Strip binary
if: matrix.os != 'windows-latest' && !matrix.use-cross
run: strip target/${{ matrix.target }}/release/lineguard
- name: Create archive (unix)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../lineguard-${{ matrix.target }}.tar.gz lineguard
cd ../../..
- name: Create archive (windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Compress-Archive -Path "target/${{ matrix.target }}/release/lineguard.exe" -DestinationPath "lineguard-${{ matrix.target }}.zip"
- name: Generate checksum
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
certutil -hashfile lineguard-${{ matrix.target }}.* SHA256 > lineguard-${{ matrix.target }}.sha256
else
shasum -a 256 lineguard-${{ matrix.target }}.tar.gz > lineguard-${{ matrix.target }}.tar.gz.sha256
fi
shell: bash
- uses: actions/upload-artifact@v6
with:
name: ${{ matrix.target }}
path: lineguard-${{ matrix.target }}.*
publish-crate:
needs: build-artifacts
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- name: Authenticate with crates.io
id: crates-io-auth
uses: rust-lang/crates-io-auth-action@v1
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
release:
needs: [build-artifacts, publish-crate]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
- uses: actions/download-artifact@v7
with:
path: artifacts
merge-multiple: true
- uses: knope-dev/action@v2.1.0
with:
version: 0.22.2
- run: knope release --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}