broll 0.3.2

Terminal session recorder with searchable, timestamped output
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always
  # Pinned for reproducible releases. Keep in sync with ci.yml.
  RUST_TOOLCHAIN: "1.96.0"

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ env.RUST_TOOLCHAIN }}
          components: clippy

      - uses: Swatinem/rust-cache@v2

      - name: Run clippy
        run: cargo clippy --all-targets -- -D warnings

      - name: Run tests
        run: cargo test

  publish:
    name: Publish to crates.io
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ env.RUST_TOOLCHAIN }}

      - uses: Swatinem/rust-cache@v2

      - name: Verify tag matches Cargo.toml version
        run: |
          CARGO_VERSION="v$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')"
          TAG="${GITHUB_REF#refs/tags/}"
          if [ "$CARGO_VERSION" != "$TAG" ]; then
            echo "ERROR: Tag $TAG does not match Cargo.toml version $CARGO_VERSION"
            exit 1
          fi

      - name: Publish (skip if already on crates.io)
        run: |
          VERSION="$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')"
          if curl -sf "https://crates.io/api/v1/crates/broll/${VERSION}" > /dev/null; then
            echo "broll ${VERSION} is already published, skipping publish."
          else
            cargo publish
          fi
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  github-release:
    name: GitHub Release
    needs: publish
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true