-
Notifications
You must be signed in to change notification settings - Fork 1
229 lines (198 loc) · 6.92 KB
/
build-nodejs.yml
File metadata and controls
229 lines (198 loc) · 6.92 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
name: Build lni_nodejs
on:
push:
branches: [master, main]
tags:
- 'v*'
workflow_dispatch:
inputs:
release_tag:
description: 'Release tag (e.g., v0.1.0) - triggers release + publish'
required: false
type: string
env:
CARGO_TERM_COLOR: always
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
# Linux
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
name: linux-x64-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
name: linux-arm64-gnu
# macOS (use specific runners for native builds)
- os: macos-15-intel # Intel runner for x64 (macos-13 deprecated)
target: x86_64-apple-darwin
name: darwin-x64
- os: macos-latest # Apple Silicon runner for arm64 (macos-15)
target: aarch64-apple-darwin
name: darwin-arm64
# Windows
- os: windows-latest
target: x86_64-pc-windows-msvc
name: win32-x64-msvc
runs-on: ${{ matrix.os }}
name: Build - ${{ matrix.name }}
steps:
# actions/checkout@v4
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
- name: Setup Node.js
# actions/setup-node@v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version: '20'
- name: Install Rust
# dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Install build dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Install cross-compilation tools (Linux ARM64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Install build dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install protobuf
- name: Install build dependencies (Windows)
if: runner.os == 'Windows'
run: |
choco install protoc -y
- name: Install dependencies
working-directory: bindings/lni_nodejs
run: yarn install
- name: Build native module
working-directory: bindings/lni_nodejs
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
run: |
yarn napi build --platform --release --target ${{ matrix.target }}
- name: Upload artifact
# actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: bindings-${{ matrix.name }}
path: bindings/lni_nodejs/*.node
if-no-files-found: error
# Universal macOS binary
universal-macos:
needs: build
runs-on: macos-latest # Apple Silicon (lipo works on any arch)
name: Universal macOS Binary
steps:
# actions/checkout@v4
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
- name: Download x64 artifact
# actions/download-artifact@v4
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: bindings-darwin-x64
path: artifacts/x64
- name: Download arm64 artifact
# actions/download-artifact@v4
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: bindings-darwin-arm64
path: artifacts/arm64
- name: Create universal binary
run: |
lipo -create \
artifacts/x64/*.node \
artifacts/arm64/*.node \
-output lni_js.darwin-universal.node
- name: Upload universal artifact
# actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: bindings-darwin-universal
path: lni_js.darwin-universal.node
# Create release on tag
release:
if: ${{ startsWith(github.ref, 'refs/tags/v') || inputs.release_tag != '' }}
needs: [build, universal-macos]
runs-on: ubuntu-latest
name: Create Release
permissions:
contents: write
steps:
# actions/checkout@v4
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
- name: Download all artifacts
# actions/download-artifact@v4
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release
for dir in artifacts/bindings-*; do
name=$(basename "$dir")
platform="${name#bindings-}"
for file in "$dir"/*.node; do
if [ -f "$file" ]; then
cp "$file" "release/lni_js.${platform}.node"
fi
done
done
ls -la release/
- name: Create Release
# softprops/action-gh-release@v2
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b
with:
tag_name: ${{ inputs.release_tag || github.ref_name }}
files: release/*
generate_release_notes: true
draft: false
prerelease: ${{ contains(inputs.release_tag || github.ref, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Optional: Publish to npm
publish:
if: ${{ startsWith(github.ref, 'refs/tags/v') || inputs.release_tag != '' }}
needs: [release]
runs-on: ubuntu-latest
name: Publish to npm
steps:
# actions/checkout@v4
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
- name: Setup Node.js
# actions/setup-node@v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Download all artifacts
# actions/download-artifact@v4
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
path: artifacts
- name: Prepare npm package
working-directory: bindings/lni_nodejs
run: |
# Copy platform-specific binaries
for dir in ../../artifacts/bindings-*; do
cp "$dir"/*.node . 2>/dev/null || true
done
ls -la *.node
- name: Publish to npm
working-directory: bindings/lni_nodejs
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
# Only publish if NODE_AUTH_TOKEN is set (via secrets.NPM_TOKEN)
if [ -n "${NODE_AUTH_TOKEN}" ]; then
npm publish --access public
else
echo "NPM_TOKEN not configured, skipping publish"
fi