name: Publish to crates.io
on:
push:
tags:
- "v*"
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Pre-publish tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --verbose
- run: cargo clippy --all-targets -- -D warnings
publish:
name: Publish
needs: test
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#v}"
sed -i "s/^version = .*/version = \"$VERSION\"/" Cargo.toml
echo "Publishing version $VERSION"
- name: Verify package
run: cargo package --allow-dirty
- name: Publish to crates.io
run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
release:
name: GitHub Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
build-binaries:
name: Build ${{ matrix.target }}
needs: publish
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
binary: oxicop
- target: x86_64-apple-darwin
os: macos-latest
binary: oxicop
- target: aarch64-apple-darwin
os: macos-latest
binary: oxicop
- target: x86_64-pc-windows-msvc
os: windows-latest
binary: oxicop.exe
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Package (unix)
if: runner.os != 'Windows'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../oxicop-${{ github.ref_name }}-${{ matrix.target }}.tar.gz ${{ matrix.binary }}
- name: Package (windows)
if: runner.os == 'Windows'
run: |
cd target/${{ matrix.target }}/release
7z a ../../../oxicop-${{ github.ref_name }}-${{ matrix.target }}.zip ${{ matrix.binary }}
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
oxicop-*.tar.gz
oxicop-*.zip