cargo-samply 0.4.2

A cargo subcommand to automate the process of running samply for project binaries
Documentation
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: read

concurrency:
  group: release-${{ github.ref }}
  cancel-in-progress: false

jobs:
  verify-tag:
    name: Verify tag version
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Verify tag matches Cargo.toml
        shell: bash
        run: |
          tag_version="${GITHUB_REF_NAME#v}"
          cargo_version="$(awk -F '"' '
            /^\[package\]$/ { in_package = 1; next }
            /^\[/ { in_package = 0 }
            in_package && /^version = / { print $2; exit }
          ' Cargo.toml)"

          if [ -z "$cargo_version" ]; then
            echo "Could not determine package version from Cargo.toml" >&2
            exit 1
          fi

          if [ "$tag_version" != "$cargo_version" ]; then
            echo "Tag version '$tag_version' does not match Cargo.toml version '$cargo_version'" >&2
            exit 1
          fi

  lint:
    name: Lint
    runs-on: ubuntu-latest
    needs: verify-tag
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Check formatting
        run: cargo fmt --all -- --check

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

  build:
    name: Build package
    runs-on: ubuntu-latest
    needs: verify-tag
    steps:
      - uses: actions/checkout@v6

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

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Build crate
        run: cargo build --release --locked

      - name: Verify package contents
        run: cargo package --locked

  test:
    name: Test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    needs: verify-tag
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v6

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

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Run tests
        run: cargo test --release
        env:
          NO_COLOR: 1
          TERM: dumb
          CARGO_TERM_COLOR: never

  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: [lint, build, test]
    steps:
      - uses: actions/checkout@v6

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

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Publish crate
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --locked

  github-release:
    name: Create GitHub release
    runs-on: ubuntu-latest
    needs: publish
    permissions:
      contents: write
    steps:
      - name: Create GitHub release
        env:
          GH_TOKEN: ${{ github.token }}
        run: gh release create "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" --generate-notes --verify-tag