name: Benchmarks

on:
  workflow_dispatch:
  schedule:
    - cron: '0 3 * * 1'
  push:
    branches:
      - main
    paths:
      - 'src/main/**'
      - 'src/jmh/**'
      - 'build.gradle'
      - 'gradle/**'
      - 'gradlew'
      - 'gradlew.bat'
      - '.github/workflows/benchmarks.yml'

jobs:
  jmh:
    runs-on: ubuntu-latest
    timeout-minutes: 30

    permissions:
      contents: read

    steps:
      - name: Check out sources
        uses: actions/checkout@v4

      - name: Set up JDK 21
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: '21'
          cache: gradle

      - name: Make Gradle executable
        run: chmod +x ./gradlew

      - name: Run JMH benchmarks
        run: ./gradlew clean jmh --no-daemon

      - name: Upload JMH reports
        uses: actions/upload-artifact@v4
        with:
          name: jmh-reports
          path: |
            build/reports/jmh/**
            build/results/jmh/**
          if-no-files-found: warn