clapfig 0.16.0

Rich, layered configuration for Rust CLI apps
Documentation
name: Release

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

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0

      - name: Extract version from tag
        id: version
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "Release version: $VERSION"

      - name: Verify Cargo.toml version matches tag
        run: |
          CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
          TAG_VERSION=${{ steps.version.outputs.version }}
          if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
            echo "ERROR: Cargo.toml version ($CARGO_VERSION) does not match tag (v$TAG_VERSION)"
            echo "Use 'cargo release' locally to bump version, tag, and push."
            exit 1
          fi

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Run tests
        run: cargo test --all

      - name: Extract release notes from CHANGELOG
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          awk '/^## \['"$VERSION"'\]/{found=1; next} /^## \[/{if(found) exit} found{print}' CHANGELOG.md > release-notes.md
          if [ ! -s release-notes.md ]; then
            echo "Release v$VERSION" > release-notes.md
          fi
          echo "=== Release Notes ==="
          cat release-notes.md

      - name: Publish to crates.io
        env:
          VERSION: ${{ steps.version.outputs.version }}
        run: |
          cargo publish --allow-dirty --token ${{ secrets.CRATES_IO_KEY }} 2>&1 || {
            if cargo search clapfig --limit 1 2>/dev/null | grep -q "clapfig.*\"$VERSION\""; then
              echo "clapfig@$VERSION already published, skipping"
            else
              echo "Failed to publish clapfig"
              exit 1
            fi
          }

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v3
        with:
          tag_name: v${{ steps.version.outputs.version }}
          name: v${{ steps.version.outputs.version }}
          body_path: release-notes.md