name: CI
on:
push:
branches:
- '**'
tags:
- 'v*'
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux
os: ubuntu-latest
artifact: aodv-linux-x86_64
- name: macOS
os: macos-latest
artifact: aodv-macos
- name: Windows
os: windows-latest
artifact: aodv-windows
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Check format
run: cargo fmt --check
- name: Check
run: cargo check --all-targets --all-features
- name: Lint
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Test
run: cargo test --all-targets --all-features
- name: Build release
run: cargo build --release --all-features
- name: Upload release binary
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: |
target/release/aodv
target/release/aodv.exe
if-no-files-found: error
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Verify tag matches crate version
run: |
version="$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')"
tag="${GITHUB_REF_NAME#v}"
test "$version" = "$tag"
- name: Verify package
run: cargo package --locked
- name: Publish crate
run: cargo publish --locked --token "$CARGO_REGISTRY_TOKEN"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}