Skip to content

Commit 36bbff7

Browse files
committed
tools: add benchmark runner to test-shared
1 parent 3972af9 commit 36bbff7

File tree

1 file changed

+146
-3
lines changed

1 file changed

+146
-3
lines changed

.github/workflows/test-shared.yml

Lines changed: 146 additions & 3 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 }}
@@ -52,9 +76,26 @@ jobs:
5276
runs-on: ${{ matrix.runner }}
5377
steps:
5478
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
79+
if: ${{ github.event_name != 'workflow_dispatch' }}
5580
with:
5681
persist-credentials: false
5782

83+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
84+
if: ${{ github.event_name == 'workflow_dispatch' }}
85+
with:
86+
repository: ${{ inputs.repo || github.repository }}
87+
ref: refs/pull/${{ inputs.pr_id }}/merge
88+
persist-credentials: false
89+
fetch-depth: 2
90+
91+
- name: Validate PR head and roll back to base commit
92+
if: ${{ github.event_name == 'workflow_dispatch' }}
93+
run: |
94+
[ "$(git rev-parse HEAD^2)" = "$EXPECTED_SHA" ]
95+
git reset HEAD^ --hard
96+
env:
97+
EXPECTED_SHA: ${{ inputs.commit }}
98+
5899
- uses: cachix/install-nix-action@7be5dee1421f63d07e71ce6e0a9f8a4b07c2a487 # v31.6.1
59100
with:
60101
extra_nix_config: sandbox = true
@@ -68,7 +109,13 @@ jobs:
68109
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
69110
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
70111
71-
- name: Build Node.js and run tests
112+
- name: Load shell.nix
113+
if: github.event_name == 'workflow_dispatch'
114+
run: |
115+
[ -f shell.nix ] || curl -fsLSO https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/shell.nix
116+
[ -f nixpkgs.nix ] || curl -fsLSO https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/nixpkgs.nix
117+
118+
- name: Build Node.js ${{ github.event_name == 'workflow_dispatch' && 'on the base commit' || 'and run tests' }}
72119
run: |
73120
nix-shell \
74121
-I nixpkgs=./nixpkgs.nix \
@@ -79,5 +126,101 @@ jobs:
79126
--arg devTools '[]' \
80127
--arg benchmarkTools '[]' \
81128
--run '
82-
make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
129+
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"
130+
'
131+
132+
- name: Re-build Node.js on the merge commit
133+
# ccache is disabled here to avoid polluting the cache. Local build outputs should make this build relatively quick anyway.
134+
if: ${{ github.event_name == 'workflow_dispatch' }}
135+
run: |
136+
mv out/Release/node base_node
137+
git reset FETCH_HEAD --hard
138+
nix-shell \
139+
-I nixpkgs=./nixpkgs.nix \
140+
--pure \
141+
--arg loadJSBuiltinsDynamically false \
142+
--arg ccache 'null' \
143+
--arg devTools '[]' \
144+
--arg benchmarkTools '[]' \
145+
--run '
146+
make -j4 V=1
83147
'
148+
149+
- name: Run benchmark
150+
if: ${{ github.event_name == 'workflow_dispatch' }}
151+
run: |
152+
nix-shell \
153+
-I nixpkgs=./nixpkgs.nix \
154+
--pure --keep FILTER \
155+
--arg loadJSBuiltinsDynamically false \
156+
--arg ccache 'null' \
157+
--arg icu 'null' \
158+
--arg sharedLibDeps '{}' \
159+
--arg devTools '[]' \
160+
--run '
161+
set -o pipefail
162+
./base_node benchmark/compare.js \
163+
--filter "$FILTER" \
164+
--runs ${{ inputs.runs }} \
165+
--old ./base_node --new ./node \
166+
-- ${{ inputs.category }} \
167+
| tee /dev/stderr \
168+
> ${{ matrix.system }}.csv
169+
echo "Benchmark results:"
170+
echo
171+
echo '"'"'```'"'"'
172+
Rscript benchmark/compare.R < ${{ matrix.system }}.csv
173+
echo '"'"'```'"'"'
174+
' | tee /dev/stderr >> "$GITHUB_STEP_SUMMARY"
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+
aggregate-benchmark-results:
186+
needs: build
187+
name: Aggregate benchmark results
188+
if: ${{ github.event_name == 'workflow_dispatch' }}
189+
runs-on: ubuntu-latest
190+
steps:
191+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
192+
with:
193+
persist-credentials: false
194+
sparse-checkout: |
195+
benchmark/*.R
196+
*.nix
197+
sparse-checkout-cone-mode: false
198+
199+
- name: Download benchmark raw results
200+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
201+
with:
202+
pattern: csv-*
203+
merge-multiple: true
204+
path: raw-results
205+
206+
- uses: cachix/install-nix-action@7be5dee1421f63d07e71ce6e0a9f8a4b07c2a487 # v31.6.1
207+
with:
208+
extra_nix_config: sandbox = true
209+
210+
- name: Benchmark results
211+
run: |
212+
nix-shell \
213+
-I nixpkgs=./nixpkgs.nix \
214+
--pure \
215+
--arg loadJSBuiltinsDynamically false \
216+
--arg ccache 'null' \
217+
--arg icu 'null' \
218+
--arg sharedLibDeps '{}' \
219+
--arg devTools '[]' \
220+
--run '
221+
echo "Benchmark results:"
222+
echo
223+
echo '"'"'```'"'"'
224+
awk "FNR==1 && NR!=1{next;}{print}" raw-results/*.csv | Rscript benchmark/compare.R
225+
echo '"'"'```'"'"'
226+
' | tee /dev/stderr >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)