name: Benchmark Tags

on:
  workflow_dispatch:

jobs:
  sdk-benchmark:
    name: Benchmark SDK
    runs-on: self-hosted
    timeout-minutes: 10
    strategy:
      fail-fast: false
      matrix:
        tag-version:
          - v1.6.0
          - v1.7.0
          - v1.7.1
          - v1.10.0
          - v1.10.1
          - v1.11.0
          - v1.12.0
          - v1.13.0
          - v1.14.0
          - v1.15.0
          - v1.16.0
          - v1.17.0
          - v1.18.0
          - v1.19.0
          - v1.21.0
          - v1.22.0
          - v1.23.0
          - v1.23.1
          - v1.24.0
          - v1.25.0
          - v1.26.0
          - v1.27.0
          - v1.28.0
          - v1.29.0
          - v1.30.0
          - v1.30.1
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ matrix.tag-version }}

      - id: setup-java
        name: Set up Java for build
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17

      - name: Set up gradle
        uses: gradle/actions/setup-gradle@v4
      - name: Run jmh
        run: ./gradlew jmhJar

      - name: Run Benchmark
        run: |
          cd sdk/trace/build
          java -jar libs/opentelemetry-sdk-trace-*-jmh.jar -rf json SpanBenchmark SpanPipelineBenchmark ExporterBenchmark

      - name: Store benchmark results
        uses: benchmark-action/github-action-benchmark@v1
        with:
          tool: 'jmh'
          output-file-path: sdk/trace/build/jmh-result.json
          gh-pages-branch: benchmarks
          github-token: ${{ secrets.GITHUB_TOKEN }}
          benchmark-data-dir-path: "benchmarks"
          auto-push: true
          ref: ${{ matrix.tag-version }}
