name: icount bench
on: [pull_request]

jobs:
  icount-benchmarks:
    name: Run icount benchmarks
    runs-on: ubuntu-22.04
    steps:
      - name: Install valgrind
        run: |
          sudo apt update
          sudo apt install -y valgrind
          valgrind --version

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

      - name: Checkout PR
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Run icount benchmarks for PR
        run: cd ci-bench && cargo run --locked --release -- run-all --output-dir ${{ runner.temp }}/pr

      - name: Checkout ${{ github.base_ref }}
        uses: actions/checkout@v4
        with:
          clean: false
          ref: ${{ github.base_ref }}
          persist-credentials: false

      - name: Run icount benchmarks for ${{ github.base_ref }}
        run: cd ci-bench && cargo run --locked --release -- run-all --output-dir ${{ runner.temp }}/base

      - name: Compare results
        run: cd ci-bench && cargo run --locked --release -- compare ${{ runner.temp }}/base ${{ runner.temp }}/pr > $GITHUB_STEP_SUMMARY
