Skip to content

Commit 601310b

Browse files
committed
tools: add benchmark runner to test-shared
1 parent f92b376 commit 601310b

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

.github/workflows/test-shared.yml

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@ on:
1919
- README.md
2020
- .github/**
2121
- '!.github/workflows/test-shared.yml'
22+
workflow_dispatch:
23+
inputs:
24+
repo:
25+
type: string
26+
description: 'GitHub repository to fetch from (default to the current repo)'
27+
pr_id:
28+
type: number
29+
required: true
30+
description: 'The PR to test'
31+
commit:
32+
required: true
33+
type: string
34+
description: 'The expect HEAD of the PR'
35+
category:
36+
required: true
37+
type: string
38+
description: The category (or categories) of tests to run, for example buffers, cluster etc. Maps to a folders in node/benchmark
39+
filter:
40+
type: string
41+
description: A substring to restrict the benchmarks to run in a category. e.g. `net-c2c`
42+
runs:
43+
type: number
44+
default: 30
45+
description: How many times to repeat each benchmark
2246

2347
concurrency:
2448
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -50,6 +74,22 @@ jobs:
5074
runs-on: ${{ matrix.runner }}
5175
steps:
5276
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
77+
if: ${{ github.event_name != 'workflow_dispatch' }}
78+
79+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
80+
if: ${{ github.event_name == 'workflow_dispatch' }}
81+
with:
82+
repository: ${{ inputs.repo || github.repository }}
83+
ref: refs/pull/${{ inputs.pr_id }}/merge
84+
fetch-depth: 2
85+
86+
- name: Validate PR head and roll back to base commit
87+
if: ${{ github.event_name == 'workflow_dispatch' }}
88+
run: |
89+
[ "$(git rev-parse HEAD^2)" = "$EXPECTED_SHA" ]
90+
git reset HEAD^ --hard
91+
env:
92+
EXPECTED_SHA: ${{ inputs.commit }}
5393

5494
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
5595
with:
@@ -73,8 +113,12 @@ jobs:
73113
74114
- name: Patch npm gyp
75115
run: curl -L https://github.com/npm/cli/pull/8531.diff | git apply --directory=deps/npm --exclude=deps/npm/package-lock.json
116+
117+
- name: Load shell.nix
118+
if: ${{ github.event_name == 'workflow_dispatch' }}
119+
run: curl -fsLSO https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/shell.nix
76120

77-
- name: Build Node.js and run tests
121+
- name: Build Node.js ${{ github.event_name == 'workflow_dispatch' && 'on the base commit' || 'and run tests' }}
78122
run: |
79123
nix-shell \
80124
--pure --keep FLAKY_TESTS \
@@ -84,5 +128,42 @@ jobs:
84128
--arg devTools '[]' \
85129
--arg benchmarkTools '[]' \
86130
--run '
87-
make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
131+
make ${{ github.event_name == 'workflow_dispatch' && 'build' || 'run' }}-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
132+
'
133+
134+
- name: Re-build Node.js on the merge commit
135+
# ccache is disabled here to avoid polluting the cache. Local build outputs should make this build relatively quick anyway.
136+
if: ${{ github.event_name == 'workflow_dispatch' }}
137+
run: |
138+
mv out/Release/node base_node
139+
git reset FETCH_HEAD --hard
140+
nix-shell \
141+
--pure \
142+
--arg loadJSBuiltinsDynamically false \
143+
--arg ccache 'null' \
144+
--arg devTools '[]' \
145+
--arg benchmarkTools '[]' \
146+
--run '
147+
make -j4 V=1
148+
'
149+
150+
- name: Run benchmark
151+
if: ${{ github.event_name == 'workflow_dispatch' }}
152+
run: |
153+
nix-shell \
154+
--pure --keep FILTER \
155+
--arg loadJSBuiltinsDynamically false \
156+
--arg ccache 'null' \
157+
--arg devTools '[]' \
158+
--run '
159+
./base_node benchmark/compare.js \
160+
--filter "$FILTER" \
161+
--runs ${{ inputs.runs }} \
162+
--old ./base_node --new ./node \
163+
-- ${{ inputs.category }} \
164+
| Rscript benchmark/compare.R
88165
'
166+
env:
167+
FILTER: ${{ inputs.filter }}
168+
169+

0 commit comments

Comments
 (0)