-
Notifications
You must be signed in to change notification settings - Fork 86
340 lines (309 loc) · 13.2 KB
/
nodejs-workflow.yml
File metadata and controls
340 lines (309 loc) · 13.2 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
name: Build Node.js Module
on:
workflow_dispatch:
inputs:
precompiledRunId:
description: "Run ID of the precompiled-bin job whose artifacts should be used"
required: true
type: string
nodeVersion:
description: "Node.js version used to build/test this workflow"
required: false
default: "22"
type: string
linuxBuilderImage:
description: "Ubuntu 22.04 image with GCC 13 for Linux builds"
required: false
default: "ghcr.io/ladybugdb/ubuntu-22.04-gcc13:latest"
type: string
useBuiltExtensions:
description: "Use the lbug-extensions artifact from this workflow run for Node.js tests"
required: false
default: false
type: boolean
workflow_call:
inputs:
isNightly:
type: boolean
required: true
default: false
precompiledRunId:
type: string
required: true
nodeVersion:
type: string
required: false
default: "22"
artifactSuffix:
type: string
required: false
default: ""
linuxBuilderImage:
type: string
required: false
default: "ghcr.io/ladybugdb/ubuntu-22.04-gcc13:latest"
useBuiltExtensions:
type: boolean
required: false
default: false
jobs:
build-nodejs:
runs-on: ${{ matrix.os }}
container: ${{ fromJSON(matrix.platform == 'linux' && format('{{"image":"{0}"}}', inputs.linuxBuilderImage) || 'null') }}
env:
LBUG_LINUX_VARIANT: compat
LBUG_NODEJS_PRECOMPILED_DIR: ${{ github.workspace }}/precompiled-liblbug
LBUG_NODEJS_PRECOMPILED_LIB_PATH: ${{ matrix.platform == 'win32' && format('{0}/precompiled-liblbug/lbug.lib', github.workspace) || format('{0}/precompiled-liblbug/liblbug.a', github.workspace) }}
strategy:
matrix:
include:
- os: ubuntu-22.04
arch: x64
platform: linux
artifact_name: linux-nodejs-module-x86_64
node_name: lbugjs-linux-x64.node
- os: ubuntu-22.04-arm
arch: arm64
platform: linux
artifact_name: linux-nodejs-module-aarch64
node_name: lbugjs-linux-arm64.node
- os: macos-latest
arch: arm64
platform: darwin
artifact_name: mac-nodejs-module-arm64
node_name: lbugjs-darwin-arm64.node
mac_env: true
- os: macos-15-intel
arch: x64
platform: darwin
artifact_name: mac-nodejs-module-x64
node_name: lbugjs-darwin-x64.node
mac_env: true
- os: windows-latest
arch: x64
platform: win32
artifact_name: windows-nodejs-module
node_name: lbugjs-win32-x64.node
steps:
- uses: actions/checkout@v4
- name: Mark workspace safe for git (Linux container)
if: ${{ matrix.platform == 'linux' }}
run: git config --global --add safe.directory '*'
- name: Set precompiled lib path (Linux container)
if: ${{ matrix.platform == 'linux' }}
run: |
echo "LBUG_NODEJS_PRECOMPILED_DIR=${GITHUB_WORKSPACE}/precompiled-liblbug" >> "$GITHUB_ENV"
echo "LBUG_NODEJS_PRECOMPILED_LIB_PATH=${GITHUB_WORKSPACE}/precompiled-liblbug/liblbug.a" >> "$GITHUB_ENV"
- name: Update submodules
run: git submodule update --init --recursive tools/nodejs_api dataset
- name: Set up Node.js (with npm cache)
if: ${{ hashFiles('tools/nodejs_api/package-lock.json') != '' }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.nodeVersion }}
- name: Set up Node.js (without npm cache)
if: ${{ hashFiles('tools/nodejs_api/package-lock.json') == '' }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.nodeVersion }}
- name: Select GCC 13 (Linux)
if: ${{ matrix.platform == 'linux' }}
run: |
echo "CC=gcc-13" >> $GITHUB_ENV
echo "CXX=g++-13" >> $GITHUB_ENV
- name: Download precompiled liblbug
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LBUG_LIB_KIND: static
LBUG_PRECOMPILED_RUN_ID: ${{ inputs.precompiledRunId }}
run: |
export LBUG_TARGET_DIR="$LBUG_NODEJS_PRECOMPILED_DIR"
rm -rf "$LBUG_TARGET_DIR"
./scripts/download-liblbug.sh
- name: Update nightly version
if: ${{ inputs.isNightly == true }}
run: |
pip3 install packaging
python3 update-nightly-build-version.py
working-directory: scripts
shell: bash
env:
PIP_BREAK_SYSTEM_PACKAGES: ${{ matrix.mac_env && '1' || '' }}
- name: Create Node.js source distribution
if: ${{ matrix.platform != 'win32' }}
working-directory: tools/nodejs_api
run: |
rm -rf lbug-source.tar.gz package *.node
node package
- name: Extract tarball
if: ${{ matrix.platform != 'win32' }}
working-directory: tools/nodejs_api
run: tar -xvzf lbug-source.tar.gz
- name: Install Node.js dependencies (non-Windows)
if: ${{ matrix.platform != 'win32' }}
working-directory: tools/nodejs_api/package
run: npm i --ignore-scripts
env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.mac_env && '13.3' || '' }}
ARCHFLAGS: ${{ matrix.mac_env && format('-arch {0}', matrix.arch) || '' }}
- name: Install Node.js dependencies (non-Windows, tests)
if: ${{ matrix.platform != 'win32' }}
working-directory: tools/nodejs_api
run: npm i --ignore-scripts
- name: Install Node.js dependencies (Windows)
if: ${{ matrix.platform == 'win32' }}
working-directory: tools/nodejs_api
run: npm i --ignore-scripts
- name: Setup ccache (Linux/macOS)
if: ${{ matrix.platform != 'win32' }}
uses: hendrikmuhs/ccache-action@v1.2
with:
key: nodejs-${{ runner.os }}-${{ matrix.arch }}-${{ github.ref }}
max-size: 2G
restore-keys: |
nodejs-${{ runner.os }}-${{ matrix.arch }}-refs/heads/main
nodejs-${{ runner.os }}-${{ matrix.arch }}-
- name: Enable long paths (Windows)
if: ${{ matrix.platform == 'win32' }}
run: |
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
git config --system core.longpaths true
shell: pwsh
- name: Build Node.js native module (Windows)
if: ${{ matrix.platform == 'win32' }}
shell: cmd
run: |
choco install ccache -y
echo CMAKE_C_COMPILER_LAUNCHER=ccache>> %GITHUB_ENV%
echo CMAKE_CXX_COMPILER_LAUNCHER=ccache>> %GITHUB_ENV%
echo CCACHE_DIR=D:\c>> %GITHUB_ENV%
echo CCACHE_TEMPDIR=D:\t>> %GITHUB_ENV%
if not exist D:\c mkdir D:\c
if not exist D:\t mkdir D:\t
ccache --set-config=max_size=2G
ccache --set-config=compression=true
ccache --set-config=cache_dir=D:\c
ccache --set-config=temporary_dir=D:\t
env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
- name: Cache ccache directory (Windows)
if: ${{ matrix.platform == 'win32' }}
uses: actions/cache@v4
with:
path: D:\c
key: ${{ runner.os }}-ccache-node-${{ hashFiles('**/CMakeLists.txt', '**/*.cpp', '**/*.h', 'tools/nodejs_api/**') }}
restore-keys: |
${{ runner.os }}-ccache-node-
- name: Build Node.js native module with ccache (Windows)
if: ${{ matrix.platform == 'win32' }}
shell: cmd
env:
EXTRA_CMAKE_FLAGS: -DBUILD_LBUG=FALSE -DBUILD_SHELL=FALSE -DLBUG_API_USE_PRECOMPILED_LIB=TRUE -DLBUG_API_PRECOMPILED_LIB_PATH=${{ env.LBUG_NODEJS_PRECOMPILED_LIB_PATH }}
run: |
powershell.exe -Command "Add-MpPreference -ExclusionPath '${{ github.workspace }}'"
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
ccache -s
make GEN=Ninja nodejs
ccache -s
- name: Build Node.js native module (non-Windows)
if: ${{ matrix.platform != 'win32' }}
env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
LDFLAGS: ${{ matrix.platform == 'linux' && '-static-libstdc++' || '' }}
run: |
export EXTRA_CMAKE_FLAGS="-DBUILD_LBUG=FALSE -DBUILD_SHELL=FALSE -DLBUG_API_USE_PRECOMPILED_LIB=TRUE -DLBUG_API_PRECOMPILED_LIB_PATH=${LBUG_NODEJS_PRECOMPILED_LIB_PATH}"
ccache -s
make GEN=Ninja nodejs
ccache -s
- name: Download built extensions for tests
if: ${{ inputs.useBuiltExtensions == true }}
uses: actions/download-artifact@v4
with:
name: lbug-extensions
path: nodejs-extension-repo
- name: Start built extension repository for tests (non-Windows)
if: ${{ inputs.useBuiltExtensions == true && matrix.platform != 'win32' }}
shell: bash
run: |
set -euo pipefail
mkdir -p nodejs-extension-server
cp -R nodejs-extension-repo/releases/. nodejs-extension-server/
if [ -d nodejs-extension-repo/dataset ]; then
cp -R nodejs-extension-repo/dataset nodejs-extension-server/dataset
fi
extension_server="$PWD/nodejs-extension-server"
python3 -m http.server 8000 --bind 127.0.0.1 --directory "$extension_server" > nodejs-extension-server.log 2>&1 &
case "${{ matrix.platform }}-${{ matrix.arch }}" in
darwin-x64) platform_dir="osx_amd64" ;;
darwin-arm64) platform_dir="osx_arm64" ;;
linux-x64) platform_dir="linux_amd64" ;;
linux-arm64) platform_dir="linux_arm64" ;;
*) echo "Unsupported extension test platform: ${{ matrix.platform }}-${{ matrix.arch }}" && exit 1 ;;
esac
extension_version="$(grep 'DLBUG_EXTENSION_VERSION' CMakeLists.txt | cut -d '"' -f 2)"
extension_url="http://127.0.0.1:8000/v${extension_version}/${platform_dir}/json/libjson.lbug_extension"
for _ in {1..10}; do
if curl --fail --silent --show-error --noproxy '*' "$extension_url" >/dev/null; then
exit 0
fi
sleep 1
done
cat nodejs-extension-server.log
exit 1
- name: Start built extension repository for tests (Windows)
if: ${{ inputs.useBuiltExtensions == true && matrix.platform == 'win32' }}
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path nodejs-extension-server
Copy-Item -Recurse nodejs-extension-repo\releases\* nodejs-extension-server\
if (Test-Path nodejs-extension-repo\dataset) {
Copy-Item -Recurse nodejs-extension-repo\dataset nodejs-extension-server\dataset
}
$extensionServer = Join-Path $PWD "nodejs-extension-server"
Start-Process -FilePath python -ArgumentList "-m", "http.server", "8000", "--bind", "127.0.0.1", "--directory", $extensionServer -WindowStyle Hidden
$platform = "win_amd64"
$extensionVersion = (Select-String -Path CMakeLists.txt -Pattern 'DLBUG_EXTENSION_VERSION="([^"]+)"').Matches[0].Groups[1].Value
$url = "http://127.0.0.1:8000/v$extensionVersion/$platform/json/libjson.lbug_extension"
for ($i = 0; $i -lt 10; $i++) {
try {
Invoke-WebRequest -UseBasicParsing -Uri $url -TimeoutSec 2 | Out-Null
exit 0
} catch {
Start-Sleep -Seconds 1
}
}
Invoke-WebRequest -UseBasicParsing -Uri $url -TimeoutSec 2
- name: Use built extension repository in Node.js tests
if: ${{ inputs.useBuiltExtensions == true }}
shell: bash
run: |
sed -i.bak "s|INSTALL JSON|INSTALL JSON FROM 'http://127.0.0.1:8000/'|" tools/nodejs_api/test/test_data_type.js
- name: Run Node.js tests
working-directory: tools/nodejs_api
run: npm test
- name: Move Node.js native module (Linux)
if: ${{ matrix.platform == 'linux' }}
working-directory: tools/nodejs_api
run: mv build/lbugjs.node ${{ matrix.node_name }}
- name: Move Node.js native module (Mac)
if: ${{ matrix.platform == 'darwin' }}
working-directory: tools/nodejs_api
run: mv build/lbugjs.node ${{ matrix.node_name }}
- name: Move Node.js native module (Windows)
if: ${{ matrix.platform == 'win32' }}
working-directory: tools/nodejs_api/build
run: ren lbugjs.node ${{ matrix.node_name }}
shell: cmd
- uses: actions/upload-artifact@v4
with:
name: ${{ format('{0}{1}', matrix.artifact_name, inputs.artifactSuffix) }}
path: tools/nodejs_api/${{ matrix.platform == 'win32' && 'build/' || '' }}${{ matrix.node_name }}
- name: Clean up
if: ${{ matrix.platform == 'darwin' }}
working-directory: tools/nodejs_api/
run: rm -rf package