name: Release
on:
release:
types: [published]
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
jobs:
verify:
name: Verify (re-run CI before publishing)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
targets: thumbv7em-none-eabihf, riscv32imc-unknown-none-elf
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all -- --check
- run: cargo clippy --all-targets --all-features -- -D warnings
- run: cargo test --all-features
- name: build for thumbv7em-none-eabihf
run: cargo build --lib --target thumbv7em-none-eabihf
- name: build for thumbv7em-none-eabihf (defmt)
run: cargo build --lib --target thumbv7em-none-eabihf --features defmt
- name: build for riscv32imc-unknown-none-elf
run: cargo build --lib --target riscv32imc-unknown-none-elf
- name: build for riscv32imc-unknown-none-elf (defmt)
run: cargo build --lib --target riscv32imc-unknown-none-elf --features defmt
- run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: "-D warnings"
verify-version:
name: Verify tag matches Cargo.toml version
runs-on: ubuntu-latest
needs: verify
steps:
- uses: actions/checkout@v6
- name: Extract versions
id: versions
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed -E 's/version *= *"([^"]+)".*/\1/')
echo "tag=$TAG_VERSION" >> "$GITHUB_OUTPUT"
echo "cargo=$CARGO_VERSION" >> "$GITHUB_OUTPUT"
echo "Tag version: $TAG_VERSION"
echo "Cargo version: $CARGO_VERSION"
- name: Fail if mismatch
if: steps.versions.outputs.tag != steps.versions.outputs.cargo
run: |
echo "::error::Tag ${{ steps.versions.outputs.tag }} does not match Cargo.toml version ${{ steps.versions.outputs.cargo }}"
exit 1
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [verify, verify-version]
environment: crates-io
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: cargo publish
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}