piano 0.15.0

Automatic instrumentation-based profiler for Rust. Measures self-time, call counts, and heap allocations per function.
Documentation
name: CI

on:
  push:
    branches: [main]
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs:
  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          components: rustfmt
      - run: cargo fmt --check

  clippy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy --workspace --all-targets -- -D warnings

  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@v2
      - name: Install glibc headers (signal enumeration test)
        if: runner.os == 'Linux'
        run: sudo apt-get install -y libc6-dev
      - run: cargo install cargo-show-asm --locked
      - run: cargo test --workspace

  msrv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: "1.88.0"
      - uses: Swatinem/rust-cache@v2
      - run: sudo apt-get install -y libc6-dev
      - name: Install Rust 1.59 for runtime MSRV test
        run: rustup toolchain install 1.59.0 --profile minimal
      - run: cargo install cargo-show-asm --locked
      - run: cargo test --workspace

  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
      - uses: taiki-e/install-action@cargo-llvm-cov
      - uses: Swatinem/rust-cache@v2
      - run: sudo apt-get install -y libc6-dev
      - run: cargo llvm-cov --workspace --lcov --output-path lcov.info
      - uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: lcov.info

  test-hygiene:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Reject unsafe env var mutation in runtime tests
        run: |
          # Tests must not use std::env::set_var / remove_var -- it causes
          # flaky failures by racing with parallel tests on process-global
          # state. Use flush_to(dir) or Command::env() instead.
          if grep -rn 'env::set_var\|env::remove_var' piano-runtime/src/ --include='*.rs'; then
            echo "::error::Found unsafe env var mutation in piano-runtime (see above)."
            echo "Use flush_to(dir) or Command::env() instead of std::env::set_var."
            exit 1
          fi

  doc:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo doc --workspace --no-deps
        env:
          RUSTDOCFLAGS: -D warnings

  mutants:
    continue-on-error: true
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
      - uses: Swatinem/rust-cache@v2
      - run: sudo apt-get install -y libc6-dev
      - name: Install cargo-show-asm and cargo-mutants
        run: |
          cargo install cargo-show-asm --locked
          cargo install cargo-mutants --locked
      - name: Run mutation testing on changed runtime files
        run: |
          if git diff origin/main --name-only -- piano-runtime/src/ | grep -q .; then
            set +e
            cargo mutants --package piano-runtime --in-diff <(git diff origin/main -- piano-runtime/src/) --jobs 4 --timeout 120 --features _test_internals
            rc=$?
            set -e
            # Exit 0 = all caught, 2 = unviable, 3 = timeouts (acceptable).
            # Exit 4 = missed mutants (real failure).
            if [ "$rc" -eq 4 ]; then
              echo "::error::Missed mutants detected (exit code 4)"
              exit 1
            fi
          else
            echo "No piano-runtime/src/ changes, skipping mutation testing"
          fi