name: Release
on:
release:
types: [published]
permissions:
contents: write
packages: write
env:
CARGO_TERM_COLOR: always
jobs:
publish-crate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Set version from tag
run: |
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
sed -i "0,/^version = .*/s/^version = .*/version = \"$VERSION\"/" Cargo.toml
echo "Version set to $VERSION"
- run: cargo test
- run: cargo publish --allow-dirty --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
build-binaries:
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: npcrs-linux-x64
- os: macos-latest
target: aarch64-apple-darwin
artifact: npcrs-macos-arm64
- os: macos-13
target: x86_64-apple-darwin
artifact: npcrs-macos-x64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact: npcrs-windows-x64.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Set version from tag
shell: bash
run: |
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
sed -i.bak "0,/^version = .*/s/^version = .*/version = \"$VERSION\"/" Cargo.toml
echo "Version set to $VERSION"
- name: Install Linux deps
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libsqlite3-dev libssl-dev libclang-dev
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Rename binary
shell: bash
run: |
SRC="target/${{ matrix.target }}/release/npcrs"
if [ "${{ runner.os }}" = "Windows" ]; then
SRC="${SRC}.exe"
fi
cp "$SRC" "${{ matrix.artifact }}"
- name: Upload binary to release
uses: softprops/action-gh-release@v2
with:
files: ${{ matrix.artifact }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}