summaryrefslogtreecommitdiff
path: root/.github/workflows/benchmark.yml
blob: 0dcfd6105b5048af3fd831174586885743bdc22b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Benchmark

on:
  issue_comment:
    types: [created]

env:
  TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
  TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
  FORCE_COLOR: true

jobs:
  benchmark:
    if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench') }}
    runs-on: ubuntu-latest
    permissions:
      contents: read
    outputs:
      PR-BENCH: ${{ steps.benchmark-pr.outputs.BENCH_RESULT }}
      MAIN-BENCH: ${{ steps.benchmark-main.outputs.BENCH_RESULT }}
    steps:
      # https://github.com/actions/checkout/issues/331#issuecomment-1438220926
      - uses: actions/checkout@v3
        with:
          persist-credentials: false
          ref: refs/pull/${{ github.event.issue.number }}/head

      - name: Setup PNPM
        uses: pnpm/action-setup@v2

      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "pnpm"

      - name: Install dependencies
        run: pnpm install

      - name: Build Packages
        run: pnpm run build

      - name: Get bench command
        id: bench-command
        run: |
          benchcmd=$(echo "${{ github.event.comment.body }}" | grep '!bench' | awk -F ' ' '{print $2}')
          echo "bench=$benchcmd" >> $GITHUB_OUTPUT
        shell: bash

      - name: Run benchmark
        id: benchmark-pr
        run: |
          result=$(pnpm run --silent benchmark ${{ steps.bench-command.outputs.bench }})
          processed=$(node ./benchmark/ci-helper.js "$result")
          echo "BENCH_RESULT<<BENCHEOF" >> $GITHUB_OUTPUT
          echo "### PR Benchmark" >> $GITHUB_OUTPUT
          echo "$processed" >> $GITHUB_OUTPUT
          echo "BENCHEOF" >> $GITHUB_OUTPUT
        shell: bash

      # main benchmark
      - uses: actions/checkout@v3
        with:
          persist-credentials: false
          ref: "main"

      - name: Install
        run: |
          pnpm install

      - name: Build Packages
        run: pnpm run build

      - name: Run benchmark
        id: benchmark-main
        run: |
          result=$(pnpm run --silent benchmark ${{ steps.bench-command.outputs.bench }})
          processed=$(node ./benchmark/ci-helper.js "$result")
          echo "BENCH_RESULT<<BENCHEOF" >> $GITHUB_OUTPUT
          echo "### Main Benchmark" >> $GITHUB_OUTPUT
          echo "$processed" >> $GITHUB_OUTPUT
          echo "BENCHEOF" >> $GITHUB_OUTPUT
        shell: bash

  output-benchmark:
    if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!bench') }}
    needs: [benchmark]
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - name: Comment PR
        uses: thollander/actions-comment-pull-request@v1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          pr_number: ${{ github.event.issue.number }}
          message: |
            ${{ needs.benchmark.outputs.PR-BENCH }}

            ${{ needs.benchmark.outputs.MAIN-BENCH }}