Skip to content

Commit 2093f68

Browse files
committed
tools: add benchmark runner to test-shared
1 parent a388eb6 commit 2093f68

File tree

2 files changed

+140
-5
lines changed

2 files changed

+140
-5
lines changed

.github/workflows/test-shared.yml

Lines changed: 140 additions & 4 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:
@@ -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,9 +74,26 @@ jobs:
5074
runs-on: ${{ matrix.runner }}
5175
steps:
5276
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
77+
if: ${{ github.event_name != 'workflow_dispatch' }}
5378
with:
5479
persist-credentials: false
5580

81+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
82+
if: ${{ github.event_name == 'workflow_dispatch' }}
83+
with:
84+
repository: ${{ inputs.repo || github.repository }}
85+
ref: refs/pull/${{ inputs.pr_id }}/merge
86+
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 }}
96+
5697
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
5798
with:
5899
extra_nix_config: sandbox = true
@@ -73,10 +114,15 @@ jobs:
73114
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
74115
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
75116
76-
- name: Patch npm gyp
117+
- name: Patch npm gyp (to be able to build addons for the tests)
118+
if: ${{ github.event_name != 'workflow_dispatch' }}
77119
run: curl -L https://github.com/npm/cli/pull/8531.diff | git apply --directory=deps/npm --exclude=deps/npm/package-lock.json
120+
121+
- name: Load shell.nix
122+
if: ${{ github.event_name == 'workflow_dispatch' }}
123+
run: curl -fsLSO https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/shell.nix
78124

79-
- name: Build Node.js and run tests
125+
- name: Build Node.js ${{ github.event_name == 'workflow_dispatch' && 'on the base commit' || 'and run tests' }}
80126
run: |
81127
nix-shell \
82128
--pure --keep FLAKY_TESTS \
@@ -86,5 +132,95 @@ jobs:
86132
--arg devTools '[]' \
87133
--arg benchmarkTools '[]' \
88134
--run '
89-
make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
135+
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"
136+
'
137+
138+
- name: Re-build Node.js on the merge commit
139+
# ccache is disabled here to avoid polluting the cache. Local build outputs should make this build relatively quick anyway.
140+
if: ${{ github.event_name == 'workflow_dispatch' }}
141+
run: |
142+
mv out/Release/node base_node
143+
git reset FETCH_HEAD --hard
144+
nix-shell \
145+
--pure \
146+
--arg loadJSBuiltinsDynamically false \
147+
--arg ccache 'null' \
148+
--arg devTools '[]' \
149+
--arg benchmarkTools '[]' \
150+
--run '
151+
make -j4 V=1
152+
'
153+
154+
- name: Run benchmark
155+
if: ${{ github.event_name == 'workflow_dispatch' }}
156+
run: |
157+
nix-shell \
158+
--pure --keep FILTER \
159+
--arg loadJSBuiltinsDynamically false \
160+
--arg ccache 'null' \
161+
--arg icu 'null' \
162+
--arg sharedLibDeps '{}' \
163+
--arg devTools '[]' \
164+
--run '
165+
set -o pipefail
166+
./base_node benchmark/compare.js \
167+
--filter "$FILTER" \
168+
--runs ${{ inputs.runs }} \
169+
--old ./base_node --new ./node \
170+
-- ${{ inputs.category }} \
171+
| tee /dev/stderr \
172+
> ${{ matrix.system }}.csv
173+
Rscript benchmark/compare.R < ${{ matrix.system }}.csv
174+
'
175+
env:
176+
FILTER: ${{ inputs.filter }}
177+
178+
- name: Upload raw benchmark results
179+
if: ${{ github.event_name == 'workflow_dispatch' }}
180+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
181+
with:
182+
name: csv-${{ matrix.system }}
183+
path: ${{ matrix.system }}.csv
184+
185+
186+
aggregate-benchmark-results:
187+
needs: build
188+
name: Aggregate benchmark results
189+
if: ${{ github.event_name == 'workflow_dispatch' }}
190+
runs-on: ubuntu-latest
191+
steps:
192+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
193+
with:
194+
persist-credentials: false
195+
sparse-checkout: benchmark
196+
197+
- name: Download benchmark raw results
198+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
199+
with:
200+
pattern: csv-*
201+
merge-multiple: true
202+
path: raw-results
203+
204+
- uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
205+
with:
206+
extra_nix_config: sandbox = true
207+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
208+
nix_path: nixpkgs=${{ env.NIXPKGS_REPO }}/archive/${{ env.NIXPKGS_PIN }}.tar.gz
209+
210+
- uses: cachix/cachix-action@0fc020193b5a1fa3ac4575aa3a7d3aa6a35435ad # v16
211+
with:
212+
name: nodejs
213+
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
214+
215+
- name: Benchmark results
216+
run: |
217+
nix-shell \
218+
--pure \
219+
--arg loadJSBuiltinsDynamically false \
220+
--arg ccache 'null' \
221+
--arg icu 'null' \
222+
--arg sharedLibDeps '{}' \
223+
--arg devTools '[]' \
224+
--run '
225+
awk "FNR==1 && NR!=1{next;}{print}" raw-results/*.csv | Rscript benchmark/compare.R
90226
'

shell.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pkgs.mkShell {
7575
shellHook = if (ccache != null) then ''
7676
export CC="${pkgs.lib.getExe ccache} $CC"
7777
export CXX="${pkgs.lib.getExe ccache} $CXX"
78-
ls "${pkgs.lib.getLib sharedLibDeps.uvwasi}"
7978
'' else "";
8079

8180
BUILD_WITH = if (ninja != null) then "ninja" else "make";

0 commit comments

Comments
 (0)