name: Deploy to crates.io
on:
push:
tags:
- '*'
permissions:
contents: write
packages: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Format check
run: cargo fmt --all -- --check
- name: Clippy check
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run tests
run: cargo test --all
- name: Build release
run: cargo build --release
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CRATES_IO }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO }}
- name: Generate documentation
run: cargo doc --no-deps --all-features
- name: GitHub Release
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: false
tag_name: ${{ github.ref_name }}
name: Release v${{ github.ref_name }}
body: |
## What's Changed
See [CHANGELOG.md](CHANGELOG.md) for detailed changes.
## Installation
```bash
cargo install snipren --version ${{ github.ref_name }}
```
Or download the binaries from the assets below.
generate_release_notes: true
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-binaries:
runs-on: ${{ matrix.os }}
needs: deploy
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact-name: rn-linux-x86_64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact-name: rn-windows-x86_64.exe
- os: macos-latest
target: x86_64-apple-darwin
artifact-name: rn-macos-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact-name: rn-macos-aarch64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true
- name: Install target
run: rustup target add ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare binary (Unix)
if: matrix.os != 'windows-latest'
run: |
cp target/${{ matrix.target }}/release/rn ${{ matrix.artifact-name }}
strip ${{ matrix.artifact-name }}
- name: Prepare binary (Windows)
if: matrix.os == 'windows-latest'
run: |
Copy-Item target/${{ matrix.target }}/release/rn.exe ${{ matrix.artifact-name }}
- name: Upload release assets
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
files: ${{ matrix.artifact-name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}