-
Notifications
You must be signed in to change notification settings - Fork 13
220 lines (188 loc) · 6.64 KB
/
main.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
name: Main
on:
pull_request:
push:
branches:
- "*"
tags:
- v*.*.*
env:
# When building the bundle for npm we only want to include the prebuilds for
# the current node version we are supporting for Lodestar. The makeRelease
# script that builds the release and builds the npm package will select ONLY
# the version of node in this setup for publishing to npm. The rest will be
# added to the release on github and will be downloaded by the install script
# if they are using a version of node that is different then the one in this
# setup action.
NPM_PREBUILT_NODE_VERSION: 20
jobs:
build:
strategy:
fail-fast: false
matrix:
node:
- 16
- 18
- 20
- 21
os:
- ubuntu-22.04 # linux x64
- macos-12 # osx x64
- macos-14 # osx arm
- windows-latest # windows x64
runs-on: ${{matrix.os}}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup Node.js ${{matrix.node}}
uses: actions/setup-node@v4
with:
node-version: ${{matrix.node}}
- uses: actions/setup-python@v5
with:
# More recent versions of python require more recent node-gyp
# See https://github.com/nodejs/node-gyp/issues/2869
python-version: "3.11"
- name: Install && Build TS + bindings
run: yarn
- name: Run Unit Tests
run: yarn test:unit
- name: Run Memory Tests
run: yarn test:memory
# Attempt to pull spec-tests from cache
- name: Restore spec tests cache
id: cache-restore
if: matrix.os != 'windows-latest'
uses: actions/cache/restore@v4
with:
path: spec-tests
key: spec-test-data-${{ hashFiles('test/spec/specTestVersioning.ts') }}
# Download spec tests if not persisted
- name: Download spec tests
if: matrix.os != 'windows-latest'
run: yarn download-spec-tests
# Cache Spec Tests if not already cached
- name: Save spec tests to cache
if: matrix.os != 'windows-latest' && steps.cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: spec-tests
key: spec-test-data-${{ hashFiles('test/spec/specTestVersioning.ts') }}
- name: Run spec tests
if: matrix.os != 'windows-latest'
run: yarn test:spec
- name: Upload binding.node
uses: actions/upload-artifact@v4
if: github.repository_owner == 'chainsafe' && github.event_name != 'pull_request'
with:
name: binding.node
path: prebuild/*.node
if-no-files-found: error
# Required as current base images do not support arm64
# https://resources.github.com/devops/accelerate-your-cicd-with-arm-and-gpu-runners-in-github-actions/
# https://github.com/actions/runner-images/issues/5631
build-arm:
strategy:
fail-fast: false
matrix:
node:
- 16
- 18
- 20
- 21
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
submodules: true
# Download spec tests with cache
- name: Restore spec tests cache
uses: actions/cache@v4
with:
path: spec-tests
key: spec-test-data-${{ hashFiles('test/spec/specTestVersioning.ts') }}
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build arm64 Binding, Run Tests and Copy Build Artifact to Host
run: |
docker buildx build --build-arg NODE_VERSION=${{matrix.node}} --platform linux/arm64 -t blst-ts-test-armbuild:${{matrix.node}} --load --progress=plain .
docker create --name temp-container blst-ts-test-armbuild:${{matrix.node}}
docker cp temp-container:/usr/src/blst-ts/prebuild ./prebuild
- name: Upload binding.node
uses: actions/upload-artifact@v4
if: github.repository_owner == 'chainsafe' && github.event_name != 'pull_request'
with:
name: binding.node
path: prebuild/*.node
if-no-files-found: error
benchmark:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install
run: yarn
- name: Run Perf Tests
run: yarn test:perf
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
needs: ["build", "build-arm"]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
# When building the bundle for npm we only want to include the prebuilds for
# the current node version we are supporting for Lodestar. The script below
# that builds the release and builds the npm package will select ONLY the
# version of node in this setup for publishing to npm. The rest will be
# added to the release on github and will be downloaded by the install script
# if they are using a version of node that is different then the one in this
# setup action.
- uses: actions/setup-node@v4
with:
node-version: ${{env.NPM_PREBUILT_NODE_VERSION}}
registry-url: "https://registry.npmjs.org"
- name: Get pre-built binding.node files
uses: actions/download-artifact@v4
with:
name: binding.node
path: prebuild/
- name: Install
run: yarn
- name: Build TS
run: yarn build:ts
# Moves all prebuilds to the `release` folder and then only moves the
# prebuilds for the current node version into the `prebuild` folder for
# publishing to npm. Goal is to reduce bundle size and to also provide
# faster install time for the most common version that Lodestar is supporting
- name: Prepare for Release and Publishing
run: yarn ts-node scripts/makeRelease
- name: Create Github release with prebuilds
uses: softprops/action-gh-release@v2
with:
files: release/*
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to NPM
run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}