pd200x 0.2.0

Rust driver for the Maono PD200X USB microphone
Documentation
name: Release

on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"

jobs:
  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    # Only publish from the upstream repo, not forks
    if: github.repository == 'advnpzn/pd200x'
    steps:
      - uses: actions/checkout@v4

      - name: Install libudev-dev
        run: sudo apt-get update -q && sudo apt-get install -y libudev-dev

      - uses: dtolnay/rust-toolchain@stable

      - uses: Swatinem/rust-cache@v2

      - name: Verify crate version matches tag
        run: |
          CARGO_VERSION="v$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
          GIT_TAG="${GITHUB_REF_NAME}"
          if [ "$CARGO_VERSION" != "$GIT_TAG" ]; then
            echo "Version mismatch: Cargo.toml has $CARGO_VERSION but tag is $GIT_TAG"
            exit 1
          fi

      - name: Publish to crates.io
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Extract release notes from CHANGELOG
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          awk "/^## \[$VERSION\]/{found=1; next} found && /^## \[/{exit} found{print}" CHANGELOG.md \
            > release_notes.md

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          body_path: release_notes.md