name: Performance for Push
on:
  push:
    branches: [ master ]

permissions:
  # deployments permission to deploy GitHub pages website
  deployments: write
  # contents permission to update benchmark contents in gh-pages branch
  contents: write

jobs:
  benchmark:
    name: Performance regression check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
      # Run benchmark with `go test -bench` and stores the output to a file
      - name: Run benchmark
        run: go test -bench '.' -benchtime=2s -benchmem ./... | tee output.txt
      # Run `github-action-benchmark` action
      - name: Store benchmark result
        uses: benchmark-action/github-action-benchmark@v1
        with:
          tool: 'go'
          output-file-path: output.txt
          benchmark-data-dir-path: benchmark-monitoring
          save-data-file: false
          fail-on-alert: true
          alert-threshold: '110%'
          fail-threshold: '200%'
          # GitHub API token to make a commit comment
          github-token: ${{ secrets.GITHUB_TOKEN }}
          # Enable alert commit comment
          comment-on-alert: true
          comment-always: true
          gh-pages-branch: gh-pages
          # alert-comment-cc-users: '@XXX'
          auto-push: true