name: Benchmarks
on:
  - push
  - pull_request

permissions:
  contents: read

jobs:
  benchmark_current:
    name: benchmark current
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
        with:
          persist-credentials: false
          ref: ${{ github.base_ref }}
      - name: Setup Node
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: lts/*
      - name: Install Modules for undici
        run: npm i --ignore-scripts --omit=dev
      - name: Install Modules for Benchmarks
        run: npm i
        working-directory: ./benchmarks
      - name: Run Benchmark
        run: npm run bench
        working-directory: ./benchmarks

  benchmark_branch:
    name: benchmark branch
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
        with:
          persist-credentials: false
      - name: Setup Node
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: lts/*
      - name: Install Modules for undici
        run: npm i --ignore-scripts --omit=dev
      - name: Install Modules for Benchmarks
        run: npm i
        working-directory: ./benchmarks
      - name: Run Benchmark
        run: npm run bench
        working-directory: ./benchmarks

  benchmark_post_current:
    name: benchmark (sending data) current
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
        with:
          persist-credentials: false
          ref: ${{ github.base_ref }}
      - name: Setup Node
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: lts/*
      - name: Install Modules for undici
        run: npm i --ignore-scripts --omit=dev
      - name: Install Modules for Benchmarks
        run: npm i
        working-directory: ./benchmarks
      - name: Run Benchmark
        run: npm run bench-post
        working-directory: ./benchmarks

  benchmark_post_branch:
    name: benchmark (sending data) branch
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
        with:
          persist-credentials: false
      - name: Setup Node
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: lts/*
      - name: Install Modules for undici
        run: npm i --ignore-scripts --omit=dev
      - name: Install Modules for Benchmarks
        run: npm i
        working-directory: ./benchmarks
      - name: Run Benchmark
        run: npm run bench-post
        working-directory: ./benchmarks

  benchmark_current_h2:
    name: benchmark current h2
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
        with:
          persist-credentials: false
          ref: ${{ github.base_ref }}
      - name: Setup Node
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: lts/*
      - name: Install Modules for undici
        run: npm i --ignore-scripts --omit=dev
      - name: Install Modules for Benchmarks
        run: npm i
        working-directory: ./benchmarks
      - name: Run Benchmark
        run: npm run bench:h2
        working-directory: ./benchmarks

  benchmark_branch_h2:
    name: benchmark branch h2
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
        with:
          persist-credentials: false
      - name: Setup Node
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: lts/*
      - name: Install Modules for undici
        run: npm i --ignore-scripts --omit=dev
      - name: Install Modules for Benchmarks
        run: npm i
        working-directory: ./benchmarks
      - name: Run Benchmark
        run: npm run bench:h2
        working-directory: ./benchmarks
