-
Notifications
You must be signed in to change notification settings - Fork 5
263 lines (242 loc) · 8.81 KB
/
release-node-bindings.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: Node Bindings
env:
DEBUG: napi:*
APP_NAME: node-eth-kzg
MACOSX_DEPLOYMENT_TARGET: '10.13'
permissions:
contents: write
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && 'manual' || github.ref }}
cancel-in-progress: true
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
inputs:
ref:
description: The reference (branch/tag/commit) to checkout
required: false
release-type:
type: choice
required: false
default: none
description: Indicates whether we want to make a release and if which one
options:
- pre-release # Release a pre-release version to npm
- release # release an official version to npm
- none # Make no release
jobs:
build:
strategy:
fail-fast: false
matrix:
settings:
- host: ubuntu-latest
target: x86_64-apple-darwin
- host: ubuntu-latest
target: aarch64-apple-darwin
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
- host: ubuntu-latest
target: x86_64-pc-windows-msvc
- host: ubuntu-latest
target: aarch64-pc-windows-msvc
name: Build - ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: ${{ matrix.settings.target }}
# llvm-preview-tools are needed for xwin, because we are compiling assembly (blst)
# Alternatively, you can install llvm
- name: Install llvm-preview-tools
if: runner.os == 'Linux' && contains(matrix.settings.target, 'windows')
run: rustup component add llvm-tools-preview
- name: Install dependencies
run: yarn install
working-directory: bindings/node
- name: Setup Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0
- name: Install Binstall
uses: cargo-bins/cargo-binstall@main
- name: Install cargo-zigbuild
run: cargo binstall cargo-zigbuild -y
- name: Install cargo-xwin (Windows on Linux only)
if: contains(matrix.settings.target, 'windows')
run: cargo binstall cargo-xwin -y
- name: Build (Mac and Linux)
if: contains(matrix.settings.target, 'windows') == false
run: yarn build --zig --release --target ${{ matrix.settings.target }}
working-directory: bindings/node
- name: Build (Windows on Linux)
if: contains(matrix.settings.target, 'windows')
run: yarn build --release --target ${{ matrix.settings.target }}
working-directory: bindings/node
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: bindings/node/${{ env.APP_NAME }}.*.node
if-no-files-found: error
test:
needs: build
strategy:
fail-fast: false
matrix:
settings:
- host: macos-13
target: x86_64-apple-darwin
- host: macos-14
target: aarch64-apple-darwin
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
- host: windows-latest
target: x86_64-pc-windows-msvc
- host: ubuntu-latest
target: aarch64-pc-windows-msvc
node:
- '20'
name: Test - ${{ matrix.settings.target }} - node@${{ matrix.node }}
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: yarn install
working-directory: bindings/node
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: bindings/node
# Native testing for macOS (both Intel and ARM)
- name: Test bindings (macOS)
if: startsWith(matrix.settings.host, 'macos')
run: yarn test
working-directory: bindings/node
# Native testing for x86_64 Linux
- name: Test bindings (Linux x86_64)
if: matrix.settings.target == 'x86_64-unknown-linux-gnu'
run: yarn test
working-directory: bindings/node
# Emulated testing for aarch64 Linux
- name: Set up QEMU
if: matrix.settings.target == 'aarch64-unknown-linux-gnu'
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Test bindings (Linux ARM64)
if: matrix.settings.target == 'aarch64-unknown-linux-gnu'
uses: addnab/docker-run-action@v3
with:
image: node:${{ matrix.node }}-slim
options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
run: |
cd bindings/node
yarn config set supportedArchitectures.cpu "arm64"
yarn config set supportedArchitectures.libc "glibc"
yarn install
yarn test
# Native testing for x86_64 Windows
- name: Test bindings (Windows x86_64)
if: matrix.settings.target == 'x86_64-pc-windows-msvc'
run: yarn test
working-directory: bindings/node
# TODO: Its kind of hard to test windows on arm64 w yarn
# The approach of using linaro/wine-arm64 is the most promising
# We can add it back after some debugging
# - name: Test bindings (Windows ARM64)
# if: matrix.settings.target == 'aarch64-pc-windows-msvc'
# uses: addnab/docker-run-action@v3
# with:
# image: linaro/wine-arm64
# options: '-v ${{ github.workspace }}:/build -w /build'
# run: |
# echo "Download node windows-arm64"
# NODE_VERSION=20.0.0
# wget -q https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-win-arm64.zip
# unzip -q node-*.zip
# mv node-*-win-arm64 /node
# cd bindings/node
# echo "Run tests"
# wine-arm64 /node/node.exe --version
# wine-arm64 /node/npm.cmd install -g yarn
# wine-arm64 /node/yarn.cmd install
# wine-arm64 /node/yarn.cmd test
publish:
name: Publish
runs-on: ubuntu-latest
needs:
- test
defaults:
run:
working-directory: bindings/node
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: yarn install
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: bindings/node/artifacts
- name: Move artifacts
run: yarn artifacts
- name: Publish
if: ${{ inputs.release-type != 'none' && github.event_name == 'workflow_dispatch' }}
run: |
# TODO: We could remove the yarnpkg registry and set the npmregistry
# TODO: globally, by doing: yarn config set registry <registry-url>
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
echo "//registry.yarnpkg.com/:_authToken=$NPM_TOKEN" >> ~/.npmrc
if [ "${{inputs.release-type}}" = "release" ]; then
SHOULD_PUBLISH=true
elif [ "${{inputs.release-type}}" = "pre-release" ]; then
# Prepend the commit hash to the package.json files
# so we can publish a pre-release version
yarn prereleaseVersion
SHOULD_PUBLISH=true
else
echo "No release has been made"
SHOULD_PUBLISH=false
fi
if [ "$SHOULD_PUBLISH" = true ]; then
# Prepare and publish the platform specific packages
yarn prepareAndPublishAddons
# Publish the base package, setting provenance
# to true as it's recommended. The platform specific packages
# don't need to have it, TODO but we could edit them to pass provenance.
npm config set provenance true
npm publish --access public
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_RELEASE_TOKEN }}