peat-mesh 0.8.2

Peat mesh networking library with CRDT sync, transport security, and topology management
Documentation
name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: read
  checks: write

env:
  CARGO_TERM_COLOR: always

jobs:
  ci:
    name: CI
    uses: ./.github/workflows/ci.yml

  publish:
    name: Publish to crates.io
    needs: ci
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Validate tag matches Cargo.toml version
        run: |
          TAG="${GITHUB_REF#refs/tags/v}"
          VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')
          if [ "$TAG" != "$VERSION" ]; then
            echo "::error::Tag v$TAG does not match Cargo.toml version $VERSION"
            exit 1
          fi
      - name: Publish
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  release:
    name: GitHub Release
    needs: publish
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - name: Extract changelog for this version
        id: changelog
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          # Extract the section between this version's header and the next version header
          NOTES=$(awk "/^## \[${VERSION}\]/{found=1; next} /^## \[/{if(found) exit} found{print}" CHANGELOG.md)
          if [ -z "$NOTES" ]; then
            echo "::warning::No CHANGELOG.md entry found for $VERSION, falling back to auto-generated notes"
            echo "fallback=true" >> "$GITHUB_OUTPUT"
          else
            # Write to file to preserve newlines
            echo "$NOTES" > /tmp/release-notes.md
            echo "fallback=false" >> "$GITHUB_OUTPUT"
          fi
      - name: Create GitHub Release
        run: |
          if [ "${{ steps.changelog.outputs.fallback }}" = "true" ]; then
            gh release create "$GITHUB_REF_NAME" --generate-notes
          else
            gh release create "$GITHUB_REF_NAME" --notes-file /tmp/release-notes.md
          fi
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}