name: Comment benchmark results

on:
  workflow_run:
    workflows: ["Benchmark PR"]
    types: [completed]

jobs:
  comment:
    if: >-
      github.event.workflow_run.event == 'pull_request' &&
      github.event.workflow_run.conclusion == 'success'
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      issues: write
      actions: read

    steps:
      - name: Download benchmark results
        uses: actions/download-artifact@v4
        with:
          name: benchmark-results
          path: results/
          run-id: ${{ github.event.workflow_run.id }}
          github-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Post benchmark comment
        uses: HaoZeke/asv-perch@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          comparison-text-file: results/comparison.txt
          metadata-file: results/metadata.txt
          regression-threshold: '10'
          auto-draft-on-regression: 'true'
          label-before: main
          label-after: pr
          runner-info: ubuntu-22.04
