name: Run Benchmarks

on:
  workflow_call:
    inputs:
      publish:
        description: Whether to publish benchmark results
        required: true
        type: boolean
      publish_branch:
        description: Branch to publish results to
        required: false
        type: string
        default: ''

jobs:
  benchmarks:
    name: Benchmarks
    runs-on: ubuntu-24.04
    steps:
      - name: Check out code
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          path: opa
          persist-credentials: false
      - uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
        with:
          go-version-file: opa/.go-version
          cache-dependency-path: opa/go.sum
      - name: Run benchmarks
        run: go run go.bobheadxi.dev/gobenchdata@v1 action
        env:
          INPUT_GO_TEST_FLAGS: "-tags=opa_wasm -timeout=120m -run=^#"
          INPUT_GO_TEST_PKGS: ./...
          INPUT_SUBDIRECTORY: opa
          INPUT_PUBLISH: ${{ inputs.publish }}
          INPUT_PUBLISH_BRANCH: ${{ inputs.publish_branch }}
          INPUT_PRUNE_COUNT: 250
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        timeout-minutes: 120
