Skip to content

Commit 66e427c

Browse files
committed
refactor to use a composite action
1 parent 7dcc129 commit 66e427c

File tree

2 files changed

+92
-90
lines changed

2 files changed

+92
-90
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 'Build Node.js (shared libraries)'
2+
description: >
3+
Downloads the slim tarball built by the `build-tarball` job, extracts it,
4+
installs Nix (+ cachix + sccache), then builds Node.js and runs the CI
5+
test suite inside the pinned nix-shell.
6+
7+
inputs:
8+
system:
9+
description: Target system triple (e.g. x86_64-linux, aarch64-darwin).
10+
required: true
11+
extra-nix-args:
12+
description: >
13+
Additional arguments to pass to nix-shell, one per line or space
14+
separated. Appended after the common arguments.
15+
required: false
16+
default: ''
17+
cachix-auth-token:
18+
description: Cachix auth token for write access to nodejs.cachix.org.
19+
required: false
20+
default: ''
21+
22+
runs:
23+
using: composite
24+
steps:
25+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
26+
if: ${{ github.event_name != 'workflow_dispatch' }}
27+
with:
28+
name: tarballs
29+
path: tarballs
30+
31+
- name: Extract tarball
32+
if: ${{ github.event_name != 'workflow_dispatch' }}
33+
shell: bash
34+
run: |
35+
tar xzf tarballs/*.tar.gz -C "$RUNNER_TEMP"
36+
echo "TAR_DIR=$RUNNER_TEMP/$(basename tarballs/*.tar.gz .tar.gz)" >> "$GITHUB_ENV"
37+
38+
- uses: cachix/install-nix-action@96951a368ba55167b55f1c916f7d416bac6505fe # v31.10.3
39+
with:
40+
extra_nix_config: sandbox = true
41+
42+
- uses: cachix/cachix-action@1eb2ef646ac0255473d23a5907ad7b04ce94065c # v17
43+
with:
44+
name: nodejs
45+
authToken: ${{ inputs.cachix-auth-token }}
46+
47+
- name: Configure sccache
48+
if: github.base_ref == 'main' || github.ref_name == 'main'
49+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
50+
with:
51+
script: |
52+
core.exportVariable('SCCACHE_GHA_ENABLED', 'on');
53+
core.exportVariable('ACTIONS_CACHE_SERVICE_V2', 'on');
54+
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
55+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
56+
core.exportVariable('NIX_SCCACHE', '(import <nixpkgs> {}).sccache');
57+
58+
- name: Build Node.js and run tests
59+
shell: bash
60+
run: |
61+
nix-shell \
62+
-I "nixpkgs=$TAR_DIR/tools/nix/pkgs.nix" \
63+
--pure --keep TAR_DIR --keep FLAKY_TESTS \
64+
--keep SCCACHE_GHA_ENABLED --keep ACTIONS_CACHE_SERVICE_V2 --keep ACTIONS_RESULTS_URL --keep ACTIONS_RUNTIME_TOKEN \
65+
--arg loadJSBuiltinsDynamically false \
66+
--arg useSeparateDerivationForV8 true \
67+
--arg ccache "${NIX_SCCACHE:-null}" \
68+
--arg devTools '[]' \
69+
--arg benchmarkTools '[]' \
70+
${{ endsWith(inputs.system, '-darwin') && '--arg withAmaro false --arg withLief false --arg withSQLite false --arg withFFI false --arg extraConfigFlags ''["--without-inspector" "--without-node-options"]'' \' || '\' }}
71+
${{ inputs.extra-nix-args }} \
72+
--run '
73+
make -C "$TAR_DIR" run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
74+
' "$TAR_DIR/shell.nix"

.github/workflows/test-shared.yml

Lines changed: 18 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ on:
4747
- vcbuild.bat
4848
- .**
4949
- '!.github/workflows/test-shared.yml'
50+
- '!.github/actions/build-shared/**'
5051
types: [opened, synchronize, reopened, ready_for_review]
5152
push:
5253
branches:
@@ -97,6 +98,7 @@ on:
9798
- vcbuild.bat
9899
- .**
99100
- '!.github/workflows/test-shared.yml'
101+
- '!.github/actions/build-shared/**'
100102

101103
concurrency:
102104
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -153,53 +155,16 @@ jobs:
153155
name: '${{ matrix.system }}: with shared libraries'
154156
runs-on: ${{ matrix.runner }}
155157
steps:
156-
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
158+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
157159
if: ${{ github.event_name != 'workflow_dispatch' }}
158160
with:
159-
name: tarballs
160-
path: tarballs
161-
162-
- name: Extract tarball
161+
persist-credentials: false
162+
sparse-checkout: .github/actions
163+
- uses: ./.github/actions/build-shared
163164
if: ${{ github.event_name != 'workflow_dispatch' }}
164-
run: |
165-
tar xzf tarballs/*.tar.gz -C "$RUNNER_TEMP"
166-
echo "TAR_DIR=$RUNNER_TEMP/$(basename tarballs/*.tar.gz .tar.gz)" >> "$GITHUB_ENV"
167-
168-
- uses: cachix/install-nix-action@96951a368ba55167b55f1c916f7d416bac6505fe # v31.10.3
169165
with:
170-
extra_nix_config: sandbox = true
171-
172-
- uses: cachix/cachix-action@1eb2ef646ac0255473d23a5907ad7b04ce94065c # v17
173-
with:
174-
name: nodejs
175-
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
176-
177-
- name: Configure sccache
178-
if: github.base_ref == 'main' || github.ref_name == 'main'
179-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
180-
with:
181-
script: |
182-
core.exportVariable('SCCACHE_GHA_ENABLED', 'on');
183-
core.exportVariable('ACTIONS_CACHE_SERVICE_V2', 'on');
184-
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
185-
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
186-
core.exportVariable('NIX_SCCACHE', '(import <nixpkgs> {}).sccache');
187-
188-
- name: Build Node.js and run tests
189-
run: |
190-
nix-shell \
191-
-I "nixpkgs=$TAR_DIR/tools/nix/pkgs.nix" \
192-
--pure --keep TAR_DIR --keep FLAKY_TESTS \
193-
--keep SCCACHE_GHA_ENABLED --keep ACTIONS_CACHE_SERVICE_V2 --keep ACTIONS_RESULTS_URL --keep ACTIONS_RUNTIME_TOKEN \
194-
--arg loadJSBuiltinsDynamically false \
195-
--arg useSeparateDerivationForV8 true \
196-
--arg ccache "${NIX_SCCACHE:-null}" \
197-
--arg devTools '[]' \
198-
--arg benchmarkTools '[]' \
199-
${{ endsWith(matrix.system, '-darwin') && '--arg withAmaro false --arg withLief false --arg withSQLite false --arg withFFI false --arg extraConfigFlags ''["--without-inspector" "--without-node-options"]'' \' || '\' }}
200-
--run '
201-
make -C "$TAR_DIR" run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
202-
' "$TAR_DIR/shell.nix"
166+
system: ${{ matrix.system }}
167+
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
203168

204169
# Builds the matrix for the `build-openssl` job. The logic lives in
205170
# tools/nix/collect-openssl-matrix.sh.
@@ -244,55 +209,18 @@ jobs:
244209
name: 'x86_64-linux: with shared ${{ matrix.openssl.attr }} (${{ matrix.openssl.version }})'
245210
runs-on: ubuntu-24.04
246211
continue-on-error: ${{ matrix.openssl['continue-on-error'] }}
212+
env:
213+
OPENSSL_ATTR: ${{ matrix.openssl.attr }}
247214
steps:
248-
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
249-
with:
250-
name: tarballs
251-
path: tarballs
252-
253-
- name: Extract tarball
254-
run: |
255-
tar xzf tarballs/*.tar.gz -C "$RUNNER_TEMP"
256-
echo "TAR_DIR=$RUNNER_TEMP/$(basename tarballs/*.tar.gz .tar.gz)" >> "$GITHUB_ENV"
257-
258-
- uses: cachix/install-nix-action@96951a368ba55167b55f1c916f7d416bac6505fe # v31.10.3
259-
with:
260-
extra_nix_config: sandbox = true
261-
262-
- uses: cachix/cachix-action@1eb2ef646ac0255473d23a5907ad7b04ce94065c # v17
215+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
263216
with:
264-
name: nodejs
265-
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
266-
267-
- name: Configure sccache
268-
if: github.base_ref == 'main' || github.ref_name == 'main'
269-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
217+
persist-credentials: false
218+
sparse-checkout: .github/actions
219+
- uses: ./.github/actions/build-shared
270220
with:
271-
script: |
272-
core.exportVariable('SCCACHE_GHA_ENABLED', 'on');
273-
core.exportVariable('ACTIONS_CACHE_SERVICE_V2', 'on');
274-
core.exportVariable('ACTIONS_RESULTS_URL', process.env.ACTIONS_RESULTS_URL || '');
275-
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
276-
core.exportVariable('NIX_SCCACHE', '(import <nixpkgs> {}).sccache');
277-
278-
- name: Build Node.js and run tests
279-
env:
280-
OPENSSL_ATTR: ${{ matrix.openssl.attr }}
281-
run: |
282-
# Same invocation as the `build` job, except `--arg sharedLibDeps`
283-
# overrides the `openssl` attr of the default shared-lib set with
221+
system: x86_64-linux
222+
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
223+
# Override just the `openssl` attr of the default shared-lib set with
284224
# the matrix-selected nixpkgs attribute (e.g. `openssl_3_6`). All
285225
# other shared libs (brotli, cares, libuv, …) keep their defaults.
286-
nix-shell \
287-
-I "nixpkgs=$TAR_DIR/tools/nix/pkgs.nix" \
288-
--pure --keep TAR_DIR --keep FLAKY_TESTS \
289-
--keep SCCACHE_GHA_ENABLED --keep ACTIONS_CACHE_SERVICE_V2 --keep ACTIONS_RESULTS_URL --keep ACTIONS_RUNTIME_TOKEN \
290-
--arg loadJSBuiltinsDynamically false \
291-
--arg useSeparateDerivationForV8 true \
292-
--arg ccache "${NIX_SCCACHE:-null}" \
293-
--arg devTools '[]' \
294-
--arg benchmarkTools '[]' \
295-
--arg sharedLibDeps "(import $TAR_DIR/tools/nix/sharedLibDeps.nix {}) // { openssl = (import $TAR_DIR/tools/nix/pkgs.nix {}).$OPENSSL_ATTR; }" \
296-
--run '
297-
make -C "$TAR_DIR" run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
298-
' "$TAR_DIR/shell.nix"
226+
extra-nix-args: --arg sharedLibDeps "(import $TAR_DIR/tools/nix/sharedLibDeps.nix {}) // { openssl = (import $TAR_DIR/tools/nix/pkgs.nix {}).$OPENSSL_ATTR; }"

0 commit comments

Comments
 (0)