Skip to content

Commit f3f0b89

Browse files
committed
chore: Refactor to bundling prebuilds with prebuildify
1 parent 02f7bce commit f3f0b89

24 files changed

+837
-1969
lines changed

.github/workflows/ci-workflow.yml

Lines changed: 141 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
- '**'
1010
workflow_dispatch:
1111

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
1215

1316
jobs:
1417
lint:
@@ -19,9 +22,9 @@ jobs:
1922
node-version: [lts/*]
2023

2124
steps:
22-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
2326
- name: Use Node.js ${{ matrix.node-version }}
24-
uses: actions/setup-node@v3
27+
uses: actions/setup-node@v4
2528
with:
2629
node-version: ${{ matrix.node-version }}
2730
- name: Install Dependencies
@@ -31,112 +34,151 @@ jobs:
3134
- name: Inspect Lockfile
3235
run: npm run lint:lockfile
3336

34-
linux:
35-
runs-on: ubuntu-latest
36-
37+
test_x86_x64:
3738
strategy:
3839
matrix:
39-
node-version: [16.x, 18.x, 20.x]
40-
40+
os: [ ubuntu-latest, windows-latest ]
41+
node: [ 16, 18, 20 ]
42+
arch: [ x86, x64 ]
43+
exclude:
44+
# Ubuntu does not ship x86 builds.
45+
- { os: ubuntu-latest, arch: x86 }
46+
runs-on: ${{ matrix.os }}
47+
name: ${{ matrix.os }} / Node ${{ matrix.node }} ${{ matrix.arch }}
4148
steps:
42-
- uses: actions/checkout@v3
43-
- name: Use Node.js ${{ matrix.node-version }}
44-
uses: actions/setup-node@v3
45-
with:
46-
node-version: ${{ matrix.node-version }}
47-
- name: Install Dependencies
48-
run: npm ci
49-
- name: Rebuild
50-
run: npm run rebuild
51-
- name: Run Unit
52-
run: npm run unit
53-
- name: Post Unit Test Coverage
54-
uses: codecov/codecov-action@v3
55-
with:
56-
token: ${{ secrets.CODECOV_TOKEN }}
57-
directory: ./coverage/unit/
58-
files: lcov.info
59-
flags: unit-tests-${{ matrix.node-version }}-linux
60-
- name: Run Integration
61-
run: npm run integration
62-
- name: Post Integration Test Coverage
63-
uses: codecov/codecov-action@v3
64-
with:
65-
token: ${{ secrets.CODECOV_TOKEN }}
66-
directory: ./coverage/integration/
67-
files: lcov.info
68-
flags: integration-tests-${{ matrix.node-version }}-linux
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
- name: Use node ${{ matrix.node }}
52+
uses: actions/setup-node@v4
53+
with:
54+
node-version: ${{ matrix.node }}
55+
architecture: ${{ matrix.arch }}
56+
- uses: actions/cache@v4
57+
with:
58+
path: ${{ github.workspace }}/node_modules
59+
key: ${{ matrix.os }}-${{ matrix.arch }}-node-${{ matrix.node }}-${{ hashFiles('./package.json') }}
60+
- name: Install
61+
run: npm install
62+
- name: Unit Test
63+
run: npm run unit
64+
- name: Post Unit Test Coverage
65+
uses: codecov/codecov-action@v4
66+
with:
67+
token: ${{ secrets.CODECOV_TOKEN }}
68+
directory: ./coverage/unit/
69+
files: lcov.info
70+
flags: unit-tests-${{ matrix.node }}-${{ matrix.os }}-${{ matrix.arch }}
71+
- name: Integration Test
72+
run: npm run integration
73+
- name: Post Integration Test Coverage
74+
uses: codecov/codecov-action@v4
75+
with:
76+
token: ${{ secrets.CODECOV_TOKEN }}
77+
directory: ./coverage/integration/
78+
files: lcov.info
79+
flags: integration-tests-${{ matrix.node }}-${{ matrix.os }}-${{ matrix.arch }}
6980

70-
windows-2019:
71-
runs-on: windows-2019
7281

82+
test_macos_arm:
7383
strategy:
7484
matrix:
75-
node-version: [16.x, 18.x, 20.x]
76-
85+
os: [ macos-14 ]
86+
node: [ 16, 18, 20 ]
87+
arch: [ arm64 ]
88+
runs-on: ${{ matrix.os }}
89+
name: ${{ matrix.os }} / Node ${{ matrix.node }} ${{ matrix.arch }}
7790
steps:
78-
- uses: actions/checkout@v3
79-
- name: Use Node.js ${{ matrix.node-version }}
80-
uses: actions/setup-node@v3
81-
with:
82-
node-version: ${{ matrix.node-version }}
83-
- name: Install Dependencies
84-
run: npm ci
85-
- name: Rebuild
86-
run: npm run rebuild
87-
- name: Run Unit
88-
run: npm run unit
89-
- name: Post Unit Test Coverage
90-
uses: codecov/codecov-action@v3
91-
with:
92-
token: ${{ secrets.CODECOV_TOKEN }}
93-
directory: ./coverage/unit/
94-
files: lcov.info
95-
flags: unit-tests-${{ matrix.node-version }}-windows-2019
96-
- name: Run Integration
97-
run: npm run integration
98-
- name: Post Integration Test Coverage
99-
uses: codecov/codecov-action@v3
100-
with:
101-
token: ${{ secrets.CODECOV_TOKEN }}
102-
directory: ./coverage/integration/
103-
files: lcov.info
104-
flags: integration-tests-${{ matrix.node-version }}-windows-2019
91+
- name: Checkout
92+
uses: actions/checkout@v4
93+
- uses: actions/cache@v4
94+
with:
95+
path: ${{ github.workspace }}/node_modules
96+
key: ${{ matrix.os }}-${{ matrix.arch }}-node-${{ matrix.node }}-${{ hashFiles('./package.json') }}
97+
- name: Use node ${{ matrix.node }}
98+
uses: actions/setup-node@v4
99+
with:
100+
node-version: ${{ matrix.node }}
101+
architecture: ${{ matrix.arch }}
102+
- name: Install
103+
run: npm install
104+
- name: Unit Test
105+
run: npm run unit
106+
- name: Post Unit Test Coverage
107+
uses: codecov/codecov-action@v4
108+
with:
109+
token: ${{ secrets.CODECOV_TOKEN }}
110+
directory: ./coverage/unit/
111+
files: lcov.info
112+
flags: unit-tests-${{ matrix.node }}-${{ matrix.os }}-${{ matrix.arch }}
113+
- name: Integration Test
114+
run: npm run integration
115+
- name: Post Integration Test Coverage
116+
uses: codecov/codecov-action@v4
117+
with:
118+
token: ${{ secrets.CODECOV_TOKEN }}
119+
directory: ./coverage/integration/
120+
files: lcov.info
121+
flags: integration-tests-${{ matrix.node }}-${{ matrix.os }}-${{ matrix.arch }}
105122

106-
windows-latest:
107-
runs-on: windows-latest
108-
109-
# Node 16+ should eventually bundle node-gyp>=8.4.0 to be compatible with Server 2022.
110-
# Once compatible, can remove node-gyp upgrade.
123+
test_linux_arm:
124+
# Skip this group if the PR doesn't originate from the main repo.
125+
# Trying to run this on standard runners is just going to fail due to
126+
# lack of CPU resources.
127+
if: ${{ vars.NR_RUNNER != '' }}
111128
strategy:
112129
matrix:
113-
node-version: [16.x, 18.x, 20.x]
114-
130+
node: [ 16, 18, 20 ]
131+
runs-on: ${{ vars.NR_RUNNER }}
132+
name: Linux / Node ${{ matrix.node }} arm64
133+
timeout-minutes: 15
115134
steps:
116-
- uses: actions/checkout@v3
117-
- name: Use Node.js ${{ matrix.node-version }}
118-
uses: actions/setup-node@v3
119-
with:
120-
node-version: ${{ matrix.node-version }}
121-
- name: Install Dependencies
122-
run: npm ci
123-
- name: Rebuild
124-
run: npm run rebuild
125-
- name: Run Unit
126-
run: npm run unit
127-
- name: Post Unit Test Coverage
128-
uses: codecov/codecov-action@v3
129-
with:
130-
token: ${{ secrets.CODECOV_TOKEN }}
131-
directory: ./coverage/unit/
132-
files: lcov.info
133-
flags: unit-tests-${{ matrix.node-version }}-windows-latest
134-
- name: Run Integration
135-
run: npm run integration
136-
- name: Post Integration Test Coverage
137-
uses: codecov/codecov-action@v3
138-
with:
139-
token: ${{ secrets.CODECOV_TOKEN }}
140-
directory: ./coverage/integration/
141-
files: lcov.info
142-
flags: integration-tests-${{ matrix.node-version }}-windows-latest
135+
- name: Checkout
136+
uses: actions/checkout@v4
137+
- name: Compute cache key
138+
run: echo -e "CACHE_KEY=$(shasum -a 256 package.json | cut -f1 -d ' ')" >> "$GITHUB_ENV"
139+
- name: Restore modules cache
140+
id: cache_restore
141+
uses: actions/cache/restore@v4
142+
with:
143+
path: ${{ github.workspace }}/node_modules
144+
key: linux-arm-node-${{ matrix.node }}-${{ env.CACHE_KEY }}
145+
- name: Set up QEMU
146+
uses: docker/setup-qemu-action@v3
147+
with:
148+
platforms: arm64
149+
- uses: docker/setup-buildx-action@v3
150+
- uses: docker/build-push-action@v5
151+
with:
152+
context: .
153+
build-args: |
154+
NODE_VERSION=${{ matrix.node }}
155+
file: linux_arm.dockerfile
156+
tags: linux_arm:node-${{ matrix.node }}
157+
load: true
158+
push: false
159+
platforms: linux/arm64
160+
cache-from: type=gha
161+
cache-to: type=gha,mode=max
162+
- name: Run test
163+
uses: addnab/docker-run-action@v3
164+
with:
165+
image: linux_arm:node-${{ matrix.node }}
166+
options: --platform linux/arm64 -v ${{ github.workspace }}:/host
167+
run: |
168+
cp -R /host/node_modules . 2>/dev/null
169+
rm -rf /host/node_modules 2>/dev/null
170+
# npm install will fail on Node 18 every time unless we use this
171+
# very odd fix:
172+
# https://github.com/npm/cli/issues/4652#issuecomment-1126672629
173+
npm install --verbose --maxsockets 1
174+
cp -R node_modules /host/
175+
npm run unit
176+
# Skipping integration until we can get native arm64 runners
177+
# npm run integration
178+
- name: Update modules cache
179+
uses: actions/cache/save@v4
180+
# We always want to run this step even if the "test" step failed.
181+
if: ${{ steps.cache_restore.outputs.cache-hit != 'true' && !cancelled() }}
182+
with:
183+
path: ${{ github.workspace }}/node_modules
184+
key: linux-arm-node-${{ matrix.node }}-${{ env.CACHE_KEY }}

0 commit comments

Comments
 (0)