Skip to content

Commit 2002430

Browse files
committed
tools: add benchmark runner to test-shared
1 parent 16fadbd commit 2002430

File tree

1 file changed

+137
-7
lines changed

1 file changed

+137
-7
lines changed

.github/workflows/test-shared.yml

Lines changed: 137 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test Shared librairies
1+
name: Benchmark and shared librairies
22

33
on:
44
pull_request:
@@ -23,6 +23,30 @@ on:
2323
- doc/**
2424
- .github/**
2525
- '!.github/workflows/test-shared.yml'
26+
workflow_dispatch:
27+
inputs:
28+
repo:
29+
type: string
30+
description: GitHub repository to fetch from (default to the current repo)
31+
pr_id:
32+
type: number
33+
required: true
34+
description: The PR to test
35+
commit:
36+
required: true
37+
type: string
38+
description: The expect HEAD of the PR
39+
category:
40+
required: true
41+
type: string
42+
description: The category (or categories) of tests to run, for example buffers, cluster etc. Maps to a folders in node/benchmark
43+
filter:
44+
type: string
45+
description: A substring to restrict the benchmarks to run in a category. e.g. `net-c2c`
46+
runs:
47+
type: number
48+
default: 30
49+
description: How many times to repeat each benchmark
2650

2751
concurrency:
2852
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -51,9 +75,24 @@ jobs:
5175
name: '${{ matrix.system }}: with shared libraries'
5276
runs-on: ${{ matrix.runner }}
5377
steps:
54-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
78+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
79+
if: ${{ github.event_name != 'workflow_dispatch' }}
80+
81+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
82+
if: ${{ github.event_name == 'workflow_dispatch' }}
5583
with:
84+
repository: ${{ inputs.repo || github.repository }}
85+
ref: refs/pull/${{ inputs.pr_id }}/merge
5686
persist-credentials: false
87+
fetch-depth: 2
88+
89+
- name: Validate PR head and roll back to base commit
90+
if: ${{ github.event_name == 'workflow_dispatch' }}
91+
run: |
92+
[ "$(git rev-parse HEAD^2)" = "$EXPECTED_SHA" ]
93+
git reset HEAD^ --hard
94+
env:
95+
EXPECTED_SHA: ${{ inputs.commit }}
5796

5897
- uses: cachix/install-nix-action@7be5dee1421f63d07e71ce6e0a9f8a4b07c2a487 # v31.6.1
5998
with:
@@ -68,19 +107,110 @@ jobs:
68107
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
69108
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
70109
71-
- name: Patch npm gyp
72-
run: curl -L https://github.com/npm/cli/pull/8531.diff | git apply --directory=deps/npm --exclude=deps/npm/package-lock.json
110+
- name: Load shell.nix
111+
if: github.event_name == 'workflow_dispatch'
112+
run: |
113+
[ -f shell.nix ] || curl -fsLSO https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/shell.nix
114+
[ -f nixpkgs.nix ] || curl -fsLSO https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/nixpkgs.nix
73115
74-
- name: Build Node.js and run tests
116+
- name: Build Node.js ${{ github.event_name == 'workflow_dispatch' && 'on the base commit' || 'and run tests' }}
75117
run: |
76118
nix-shell \
77-
-I nixpkgs=./nixpkgs.nix
119+
-I nixpkgs=./nixpkgs.nix \
78120
--pure --keep FLAKY_TESTS \
79121
--keep SCCACHE_GHA_VERSION --keep ACTIONS_CACHE_SERVICE_V2 --keep ACTIONS_RESULTS_URL --keep ACTIONS_RUNTIME_TOKEN \
80122
--arg loadJSBuiltinsDynamically false \
81123
--arg ccache '(import "${./nixpkgs.nix}" {}).sccache' \
82124
--arg devTools '[]' \
83125
--arg benchmarkTools '[]' \
84126
--run '
85-
make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
127+
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"
128+
'
129+
130+
- name: Re-build Node.js on the merge commit
131+
# ccache is disabled here to avoid polluting the cache. Local build outputs should make this build relatively quick anyway.
132+
if: ${{ github.event_name == 'workflow_dispatch' }}
133+
run: |
134+
mv out/Release/node base_node
135+
git reset FETCH_HEAD --hard
136+
nix-shell \
137+
-I nixpkgs=./nixpkgs.nix \
138+
--pure \
139+
--arg loadJSBuiltinsDynamically false \
140+
--arg ccache 'null' \
141+
--arg devTools '[]' \
142+
--arg benchmarkTools '[]' \
143+
--run '
144+
make -j4 V=1
145+
'
146+
147+
- name: Run benchmark
148+
if: ${{ github.event_name == 'workflow_dispatch' }}
149+
run: |
150+
nix-shell \
151+
-I nixpkgs=./nixpkgs.nix \
152+
--pure --keep FILTER \
153+
--arg loadJSBuiltinsDynamically false \
154+
--arg ccache 'null' \
155+
--arg icu 'null' \
156+
--arg sharedLibDeps '{}' \
157+
--arg devTools '[]' \
158+
--run '
159+
set -o pipefail
160+
./base_node benchmark/compare.js \
161+
--filter "$FILTER" \
162+
--runs ${{ inputs.runs }} \
163+
--old ./base_node --new ./node \
164+
-- ${{ inputs.category }} \
165+
| tee /dev/stderr \
166+
> ${{ matrix.system }}.csv
167+
Rscript benchmark/compare.R < ${{ matrix.system }}.csv
168+
'
169+
env:
170+
FILTER: ${{ inputs.filter }}
171+
172+
- name: Upload raw benchmark results
173+
if: ${{ github.event_name == 'workflow_dispatch' }}
174+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
175+
with:
176+
name: csv-${{ matrix.system }}
177+
path: ${{ matrix.system }}.csv
178+
179+
aggregate-benchmark-results:
180+
needs: build
181+
name: Aggregate benchmark results
182+
if: ${{ github.event_name == 'workflow_dispatch' }}
183+
runs-on: ubuntu-latest
184+
steps:
185+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
186+
with:
187+
persist-credentials: false
188+
sparse-checkout: |
189+
benchmark/*.R
190+
*.nix
191+
sparse-checkout-cone-mode: false
192+
193+
- name: Download benchmark raw results
194+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
195+
with:
196+
pattern: csv-*
197+
merge-multiple: true
198+
path: raw-results
199+
200+
- uses: cachix/install-nix-action@7be5dee1421f63d07e71ce6e0a9f8a4b07c2a487 # v31.6.1
201+
with:
202+
extra_nix_config: sandbox = true
203+
204+
- name: Benchmark results
205+
run: |
206+
nix-shell \
207+
-I nixpkgs=./nixpkgs.nix \
208+
--pure \
209+
--arg loadJSBuiltinsDynamically false \
210+
--arg ccache 'null' \
211+
--arg icu 'null' \
212+
--arg sharedLibDeps '{}' \
213+
--arg devTools '[]' \
214+
--run '
215+
awk "FNR==1 && NR!=1{next;}{print}" raw-results/*.csv | Rscript benchmark/compare.R
86216
'

0 commit comments

Comments
 (0)