-
Notifications
You must be signed in to change notification settings - Fork 2
334 lines (297 loc) · 12.9 KB
/
Copy pathrelease.yml
File metadata and controls
334 lines (297 loc) · 12.9 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
name: Build and Release (Node)
# napi-rs matrix CI for @utexo/rgb-lightning-node-nodejs. Builds the
# platform-specific `.node` addon for every host the package's loader
# (index.js) + scripts/download-libs.sh know about, then attaches them to
# a GitHub Release and publishes the JS wrapper to npm.
#
# Same optional overlay model as @utexo/rgb-lightning-node-bare: clone
# rgb-lightning-node at the pinned tag, apply a tag-specific C-FFI patch when
# one exists, then `napi build`. Native source is staged inside the package at
# `.native-source`, matching the exact path dependencies in Cargo.toml.
#
# Produced assets are named `index-<suffix>.node` to match the suffixes
# resolved in index.js / download-libs.sh:
# darwin-arm64, darwin-x64, linux-x64-gnu, linux-x64-musl, linux-arm64-gnu
on:
repository_dispatch:
types: [rln-release]
workflow_dispatch:
inputs:
rln_version:
description: 'rgb-lightning-node tag containing the required C-FFI surface'
required: true
type: string
env:
RUST_TOOLCHAIN: '1.88.0'
jobs:
# ==========================================================================
# Job 1: Build the napi addon natively (host == target) for the gnu/darwin
# targets. Cross-libc (musl) is handled in a separate container job below.
# ==========================================================================
build-native:
name: Build addon (${{ matrix.suffix }})
strategy:
fail-fast: false
matrix:
include:
- runner: macos-14
target: aarch64-apple-darwin
suffix: darwin-arm64
# Intel macOS is cross-compiled on an arm64 mac — GitHub's Intel
# runner is being retired and WarpBuild has no x64 macOS.
- runner: macos-14
target: x86_64-apple-darwin
suffix: darwin-x64
- runner: warp-ubuntu-latest-x64-16x
target: x86_64-unknown-linux-gnu
suffix: linux-x64-gnu
- runner: warp-ubuntu-latest-arm64-16x
target: aarch64-unknown-linux-gnu
suffix: linux-arm64-gnu
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Resolve RLN version
id: version
run: |
if [ "${{ github.event_name }}" == "repository_dispatch" ]; then
echo "rln=${{ github.event.client_payload.version }}" >> "$GITHUB_OUTPUT"
else
echo "rln=${{ inputs.rln_version }}" >> "$GITHUB_OUTPUT"
fi
- name: Clone and patch rgb-lightning-node
env:
RLN_VERSION: ${{ steps.version.outputs.rln }}
run: |
set -euo pipefail
RLN_DIR="$GITHUB_WORKSPACE/.native-source"
git clone --recurse-submodules --shallow-submodules --depth 1 \
--branch "$RLN_VERSION" \
"https://github.com/UTEXO-Protocol/rgb-lightning-node.git" "$RLN_DIR"
PATCH="$GITHUB_WORKSPACE/patches/c-ffi-utexo-patches-${RLN_VERSION}.patch"
if [ -s "$PATCH" ]; then
git -C "$RLN_DIR" apply --verbose --check "$PATCH"
git -C "$RLN_DIR" apply --verbose "$PATCH"
elif [ -f "$PATCH" ]; then
echo "Patch $PATCH is empty; nothing to apply."
else
echo "No tag-specific C-FFI overlay for $RLN_VERSION; building upstream source directly."
fi
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
target: ${{ matrix.target }}
rustflags: ''
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies (skip postinstall download)
run: npm ci --ignore-scripts
- name: Build napi addon
run: |
mkdir -p .napi-generated
npx napi build --platform --release --no-js \
--dts .napi-generated/index.d.ts \
--target ${{ matrix.target }}
- name: Stage addon as index-<suffix>.node
run: |
set -euo pipefail
NODE_FILE=$(find . -maxdepth 1 -name '*.node' -type f | head -1)
test -n "$NODE_FILE"
mkdir -p dist
cp "$NODE_FILE" "dist/index-${{ matrix.suffix }}.node"
ls -lh dist/
- name: Check public TypeScript declarations
run: npm run check:types
- name: Smoke test native addon
if: matrix.suffix != 'darwin-x64'
run: |
cp "dist/index-${{ matrix.suffix }}.node" "index-${{ matrix.suffix }}.node"
node -e "const installer = require('./scripts/install-overlay-addon'); installer.recordAddonProvenance(installer.readConfig())"
npm test
- name: Upload addon artifact
uses: actions/upload-artifact@v4
with:
name: node-${{ matrix.suffix }}
path: dist/index-${{ matrix.suffix }}.node
retention-days: 1
# ==========================================================================
# Job 2: Build the musl addon inside an Alpine container (host == target).
# ==========================================================================
build-musl:
name: Build addon (linux-x64-musl)
runs-on: warp-ubuntu-latest-x64-16x
container:
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install build prerequisites
# --force-overwrite: the base image ships LLVM 19, but Alpine edge now
# serves llvm-dev 22, whose files (LLVMgold.so, libLTO.so) collide with
# the pre-installed llvm19 package. Allow the overwrite (llvm22 libclang
# is fine for bindgen) so the install doesn't abort on the conflict.
#
# nodejs/npm: the napi-rs lts-alpine image bundles Node 18.20.5, but
# @napi-rs/cli v3 needs Node >= 20.12 (uses node:util `styleText`).
# Pull Alpine edge's current Node; the build step prepends /usr/bin to
# PATH so this Node wins over the image's bundled one.
run: apk add --no-cache --force-overwrite bash git perl cmake clang llvm-dev openssl-dev sqlite-dev build-base nodejs npm
- name: Resolve RLN version
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" == "repository_dispatch" ]; then
echo "rln=${{ github.event.client_payload.version }}" >> "$GITHUB_OUTPUT"
else
echo "rln=${{ inputs.rln_version }}" >> "$GITHUB_OUTPUT"
fi
- name: Clone and patch rgb-lightning-node
shell: bash
env:
RLN_VERSION: ${{ steps.version.outputs.rln }}
run: |
set -euo pipefail
git config --global --add safe.directory '*'
RLN_DIR="$GITHUB_WORKSPACE/.native-source"
git clone --recurse-submodules --shallow-submodules --depth 1 \
--branch "$RLN_VERSION" \
"https://github.com/UTEXO-Protocol/rgb-lightning-node.git" "$RLN_DIR"
PATCH="$GITHUB_WORKSPACE/patches/c-ffi-utexo-patches-${RLN_VERSION}.patch"
if [ -s "$PATCH" ]; then
git -C "$RLN_DIR" apply --verbose --check "$PATCH"
git -C "$RLN_DIR" apply --verbose "$PATCH"
elif [ -f "$PATCH" ]; then
echo "Patch $PATCH is empty; nothing to apply."
else
echo "No tag-specific C-FFI overlay for $RLN_VERSION; building upstream source directly."
fi
- name: Install dependencies (skip postinstall download)
run: npm ci --ignore-scripts
- name: Configure Rust toolchain (musl)
# The napi-rs container ships rustup but with no default toolchain
# configured, so `napi build` -> `cargo metadata` fails with "rustup
# could not choose a version of cargo to run ... no default is
# configured". Pin the default to the RLN-required version and add the
# musl std (the container is Alpine, so x86_64-musl is a native build).
env:
RUST_TOOLCHAIN: ${{ env.RUST_TOOLCHAIN }}
run: |
rustup default "${RUST_TOOLCHAIN}"
rustup target add x86_64-unknown-linux-musl
- name: Build napi addon (musl)
shell: bash
# aws-lc-sys compiles C with clang by default, which targets
# x86_64-unknown-linux-musl and then can't find Alpine gcc's runtime
# (crtbeginS.o / libgcc) because Alpine's gcc triple is
# x86_64-alpine-linux-musl. Build its C with gcc, which knows its own
# runtime paths. CC/CXX are honoured by the cc crate aws-lc-sys uses.
env:
CC: gcc
CXX: g++
run: |
# Prefer Alpine edge's Node (>= 20.12, has node:util styleText) over
# the image's bundled Node 18 so @napi-rs/cli v3 can run.
export PATH="/usr/bin:$PATH"
node --version
mkdir -p .napi-generated
npx napi build --platform --release --no-js \
--dts .napi-generated/index.d.ts \
--target x86_64-unknown-linux-musl
- name: Stage addon as index-linux-x64-musl.node
shell: bash
run: |
set -euo pipefail
NODE_FILE=$(find . -maxdepth 1 -name '*.node' -type f | head -1)
test -n "$NODE_FILE"
mkdir -p dist
cp "$NODE_FILE" "dist/index-linux-x64-musl.node"
ls -lh dist/
- name: Check public TypeScript declarations
run: npm run check:types
- name: Smoke test native addon
run: |
cp dist/index-linux-x64-musl.node index-linux-x64-musl.node
node -e "const installer = require('./scripts/install-overlay-addon'); installer.recordAddonProvenance(installer.readConfig())"
npm test
- name: Upload addon artifact
uses: actions/upload-artifact@v4
with:
name: node-linux-x64-musl
path: dist/index-linux-x64-musl.node
retention-days: 1
# ==========================================================================
# Job 3: Release — attach all .node addons to a GH Release + npm publish.
# ==========================================================================
release:
name: Release and Publish
needs: [build-native, build-musl]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Resolve RLN version
id: version
run: |
if [ "${{ github.event_name }}" == "repository_dispatch" ]; then
echo "rln=${{ github.event.client_payload.version }}" >> "$GITHUB_OUTPUT"
else
echo "rln=${{ inputs.rln_version }}" >> "$GITHUB_OUTPUT"
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Bump package prerelease version
run: npm version prerelease --preid=beta --no-git-tag-version
- name: Read package version
id: pkg
run: echo "version=v$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
- name: Commit and push version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json
git commit -m "chore: release ${{ steps.pkg.outputs.version }} (RLN ${{ steps.version.outputs.rln }})"
git push
- name: Download all addon artifacts
uses: actions/download-artifact@v4
with:
pattern: node-*
path: artifacts
- name: Prepare release assets
run: |
set -euo pipefail
mkdir -p release-assets
find artifacts -name 'index-*.node' -exec cp {} release-assets/ \;
ls -lh release-assets/
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
VERSION="${{ steps.pkg.outputs.version }}"
gh release create "$VERSION" \
--title "Release $VERSION" \
--notes "Automated release. Built against rgb-lightning-node ${{ steps.version.outputs.rln }}. Contains napi prebuilds for darwin-arm64, darwin-x64, linux-x64-gnu, linux-x64-musl and linux-arm64-gnu." \
--prerelease --latest || echo "Release may already exist, updating assets..."
gh release upload "$VERSION" release-assets/* --clobber
- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public
- name: Trigger wdk-rgb-lightning release
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.REPO_DISPATCH_TOKEN }}
repository: UTEXO-Protocol/wdk-rgb-lightning
event-type: rln-release
client-payload: '{"version": "${{ steps.version.outputs.rln }}"}'