Skip to content

Commit 8fc7899

Browse files
committed
tools: add benchmark runner to test-shared
1 parent 05f8772 commit 8fc7899

File tree

2 files changed

+153
-3
lines changed

2 files changed

+153
-3
lines changed

.github/workflows/test-shared.yml

Lines changed: 152 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This action uses the following secrets:
22
# CACHIX_AUTH_TOKEN: Write access to nodejs.cachix.org – without it, the cache is read-only.
3-
name: Test Shared libraries
3+
name: Benchmark and shared libraries
44

55
on:
66
pull_request:
@@ -89,6 +89,30 @@ on:
8989
- vcbuild.bat
9090
- .**
9191
- '!.github/workflows/test-shared.yml'
92+
workflow_dispatch:
93+
inputs:
94+
repo:
95+
type: string
96+
description: GitHub repository to fetch from (default to the current repo)
97+
pr_id:
98+
type: number
99+
required: true
100+
description: The PR to test
101+
commit:
102+
required: true
103+
type: string
104+
description: The expect HEAD of the PR
105+
category:
106+
required: true
107+
type: string
108+
description: The category (or categories) of tests to run, for example buffers, cluster etc. Maps to a folders in node/benchmark
109+
filter:
110+
type: string
111+
description: A substring to restrict the benchmarks to run in a category. e.g. `net-c2c`
112+
runs:
113+
type: number
114+
default: 30
115+
description: How many times to repeat each benchmark
92116

93117
concurrency:
94118
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -157,6 +181,22 @@ jobs:
157181
tar xzf tarballs/*.tar.gz -C "$RUNNER_TEMP"
158182
echo "TAR_DIR=$RUNNER_TEMP/$(basename tarballs/*.tar.gz .tar.gz)" >> "$GITHUB_ENV"
159183
184+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
185+
if: ${{ github.event_name == 'workflow_dispatch' }}
186+
with:
187+
repository: ${{ inputs.repo || github.repository }}
188+
ref: refs/pull/${{ inputs.pr_id }}/merge
189+
persist-credentials: false
190+
fetch-depth: 2
191+
192+
- name: Validate PR head and roll back to base commit
193+
if: ${{ github.event_name == 'workflow_dispatch' }}
194+
run: |
195+
[ "$(git rev-parse HEAD^2)" = "$EXPECTED_SHA" ]
196+
git reset HEAD^ --hard
197+
env:
198+
EXPECTED_SHA: ${{ inputs.commit }}
199+
160200
- uses: cachix/install-nix-action@0b0e072294b088b73964f1d72dfdac0951439dbd # v31.8.4
161201
with:
162202
extra_nix_config: sandbox = true
@@ -182,7 +222,7 @@ jobs:
182222
mkdir tools
183223
mv "$TAR_DIR"/tools/nix tools/.
184224
185-
- name: Build Node.js and run tests
225+
- name: Build Node.js ${{ github.event_name == 'workflow_dispatch' && 'on the base commit' || 'and run tests' }}
186226
run: |
187227
nix-shell \
188228
-I nixpkgs=./tools/nix/pkgs.nix \
@@ -194,5 +234,114 @@ jobs:
194234
--arg benchmarkTools '[]' \
195235
${{ endsWith(matrix.system, '-darwin') && '--arg withAmaro false --arg withSQLite false --arg extraConfigFlags ''["--without-inspector" "--without-node-options"]'' \' || '\' }}
196236
--run '
197-
make -C "$TAR_DIR" run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
237+
make ${{ github.event_name == 'workflow_dispatch' && 'build' || '-C "$TAR_DIR" run' }}-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
198238
'
239+
240+
- name: Re-build Node.js on the merge commit
241+
# ccache is disabled here to avoid polluting the cache. Local build outputs should make this build relatively quick anyway.
242+
if: ${{ github.event_name == 'workflow_dispatch' }}
243+
run: |
244+
mv out/Release/node base_node
245+
git reset FETCH_HEAD --hard
246+
nix-shell \
247+
-I nixpkgs=./tools/nix/pkgs.nix \
248+
--pure \
249+
--arg loadJSBuiltinsDynamically false \
250+
--arg ccache 'null' \
251+
--arg devTools '[]' \
252+
--arg benchmarkTools '[]' \
253+
--run '
254+
make -j4 V=1
255+
'
256+
257+
- name: Run benchmark
258+
if: ${{ github.event_name == 'workflow_dispatch' }}
259+
run: |
260+
nix-shell \
261+
-I nixpkgs=./tools/nix/pkgs.nix \
262+
--pure --keep FILTER --keep LC_ALL --keep LANG \
263+
--arg loadJSBuiltinsDynamically false \
264+
--arg ccache 'null' \
265+
--arg icu 'null' \
266+
--arg sharedLibDeps '{}' \
267+
--arg devTools '[]' \
268+
--run '
269+
set -o pipefail
270+
./base_node benchmark/compare.js \
271+
--filter "$FILTER" \
272+
--runs ${{ inputs.runs }} \
273+
--old ./base_node --new ./node \
274+
-- ${{ inputs.category }} \
275+
| tee /dev/stderr \
276+
> ${{ matrix.system }}.csv
277+
echo "Warning: do not take GHA benchmark results as face value, always confirm them"
278+
echo "using a dedicated machine, e.g. Jenkins CI."
279+
echo
280+
echo "Benchmark results:"
281+
echo
282+
echo '"'"'```'"'"'
283+
Rscript benchmark/compare.R < ${{ matrix.system }}.csv
284+
echo '"'"'```'"'"'
285+
echo
286+
echo "Warning: do not take GHA benchmark results as face value, always confirm them"
287+
echo "using a dedicated machine, e.g. Jenkins CI."
288+
' | tee /dev/stderr >> "$GITHUB_STEP_SUMMARY"
289+
env:
290+
FILTER: ${{ inputs.filter }}
291+
292+
- name: Upload raw benchmark results
293+
if: ${{ github.event_name == 'workflow_dispatch' }}
294+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
295+
with:
296+
name: csv-${{ matrix.system }}
297+
path: ${{ matrix.system }}.csv
298+
299+
aggregate-benchmark-results:
300+
needs: build
301+
name: Aggregate benchmark results
302+
if: ${{ github.event_name == 'workflow_dispatch' }}
303+
runs-on: ubuntu-latest
304+
steps:
305+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
306+
with:
307+
persist-credentials: false
308+
sparse-checkout: |
309+
benchmark/*.R
310+
tools/nix/*.nix
311+
*.nix
312+
sparse-checkout-cone-mode: false
313+
314+
- name: Download benchmark raw results
315+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
316+
with:
317+
pattern: csv-*
318+
merge-multiple: true
319+
path: raw-results
320+
321+
- uses: cachix/install-nix-action@7be5dee1421f63d07e71ce6e0a9f8a4b07c2a487 # v31.6.1
322+
with:
323+
extra_nix_config: sandbox = true
324+
325+
- name: Benchmark results
326+
run: |
327+
nix-shell \
328+
-I nixpkgs=./tools/nix/pkgs.nix \
329+
--pure --keep LC_ALL --keep LANG \
330+
--arg loadJSBuiltinsDynamically false \
331+
--arg ccache 'null' \
332+
--arg icu 'null' \
333+
--arg sharedLibDeps '{}' \
334+
--arg devTools '[]' \
335+
--run '
336+
echo "Warning: do not take GHA benchmark results as face value, always confirm them"
337+
echo "using a dedicated machine, e.g. Jenkins CI."
338+
echo
339+
echo "Benchmark results:"
340+
echo
341+
echo '"'"'```'"'"'
342+
awk "FNR==1 && NR!=1{next;}{print}" raw-results/*.csv | Rscript benchmark/compare.R
343+
echo '"'"'```'"'"'
344+
echo
345+
echo "Warning: do not take GHA benchmark results as face value, always confirm them"
346+
echo "using a dedicated machine, e.g. Jenkins CI."
347+
' | tee /dev/stderr >> "$GITHUB_STEP_SUMMARY"

tools/nix/benchmarkTools.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
pkgs.rPackages.plyr
88
pkgs.wrk
99
]
10+
++ pkgs.lib.optional pkgs.stdenv.buildPlatform.isLinux pkgs.glibcLocales

0 commit comments

Comments
 (0)