name: Benchmark Ree.js

on:
  schedule:
    - cron: '0 0 * * *'
  pull_request:
  push:
    branches:
      - main

jobs:
  benchmark:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout (on Github Actions)
        if: ${{ !env.ACT }}
        uses: actions/checkout@v3
        with:
          # Make sure the actual branch is checked out when running on pull requests
          ref: ${{ github.head_ref }}

      - name: Checkout (Locally)
        if: ${{ env.ACT }}
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "18"

      - name: Setup Ree.js
        if: ${{ !contains(github.event.head_commit.message, '[publish]') }}
        run: |
          npm install
          npm run write-version
          npm link .
          npx -v
          reejs doctor
          npm i -g giget

      - name: Hyperfine
        if: ${{ !contains(github.event.head_commit.message, '[publish]') }}
        uses: renhiyama/hyperfine-action@patch-2
        with:
          # Configuration file to use
          benchmark-config: ".hyperfine.json"
          # Number of benchmarks to keep
          count: 100
          # Branch to use for benchmarks output/benchmark.json
          benchmark-branch: "benchmark-results"
          # Where to store the output of the benchmarks
          benchmark-output: "benchmarks.json"
          # benchmark html file to view the benchmarks
          benchmark-html: "benchmarks.html"
          # Branch to use as the main or master for comparision
          master-branch: "main"
          # configuration token
          github-token: ${{ github.token }}
