atm90e32-async 0.2.2

Async no_std driver for the ATM90E32 3-phase SPI power metering IC
Documentation
name: Release

# Triggered when a GitHub Release is published. Publishing a Release
# (via the Releases UI) creates the git tag, which fires this workflow.
#
# Flow:
#   1. Verify: re-run the full CI matrix as a gate (fmt/clippy/test/
#      multi-target build/doc). No green → no publish.
#   2. Verify version: ensure the tag matches Cargo.toml version.
#   3. Publish to crates.io via CARGO_REGISTRY_TOKEN repo secret.
#
# The draft Release itself is kept up-to-date by release-drafter.yml:
# every merged PR bumps the draft's minor version and appends the PR
# body to the release notes. A human edits and publishes the draft
# when ready.

on:
  release:
    types: [published]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-D warnings"

jobs:
  # Re-run the full CI matrix as a gate before publishing. This is
  # intentional duplication with ci.yml — Release publication does not
  # automatically guarantee the target commit is CI-green, so we re-
  # verify here to be safe.
  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"

  # Confirm the tag matches the Cargo.toml version before publishing.
  # Prevents "pushed v0.1.0 but Cargo.toml still says 0.0.9" mistakes.
  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]
    # Optional: create a `crates-io` environment in repo settings with
    # required reviewers to gate publication behind manual approval.
    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 }}