3131
3232 - name : Install Node.js
3333 run : |
34- curl -fsSL https://rpm.nodesource.com/setup_18 .x | bash -
34+ curl -fsSL https://rpm.nodesource.com/setup_20 .x | bash -
3535 yum install -y nodejs
3636
3737 - name : Setup Zig
@@ -53,13 +53,45 @@ jobs:
5353 echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
5454 echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
5555
56+ - name : Cache npm dependencies
57+ id : cache-npm
58+ uses : actions/cache@v4
59+ with :
60+ path : node_modules
61+ key : npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('package-lock.json') }}
62+ restore-keys : |
63+ npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-
64+
65+ - name : Cache RocketMQ native deps
66+ uses : actions/cache@v4
67+ with :
68+ path : |
69+ deps/rocketmq/bin
70+ deps/rocketmq/libs/signature/lib
71+ deps/rocketmq/tmp_down_dir
72+ key : rocketmq-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('deps/rocketmq/build.sh', 'deps/rocketmq/CMakeLists.txt') }}
73+ restore-keys : |
74+ rocketmq-${{ runner.os }}-${{ env.ZIG_TARGET }}-
75+
76+ - name : Cache addon build
77+ id : cache-addon
78+ uses : actions/cache@v4
79+ with :
80+ path : build/rocketmq.node
81+ key : addon-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('lib/**', 'CMakeLists.txt', 'package.json') }}
82+ restore-keys : |
83+ addon-${{ runner.os }}-${{ env.ZIG_TARGET }}-
84+
5685 - name : Install npm dependencies
86+ if : steps.cache-npm.outputs.cache-hit != 'true'
5787 run : npm install --no-audit --prefer-offline
5888
5989 - name : Build RocketMQ native deps
90+ if : steps.cache-addon.outputs.cache-hit != 'true'
6091 run : ./deps/rocketmq/build.sh
6192
6293 - name : Build addon
94+ if : steps.cache-addon.outputs.cache-hit != 'true'
6395 run : npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
6496
6597 - name : Package artifact
89121
90122 - name : Install Node.js
91123 run : |
92- curl -fsSL https://rpm.nodesource.com/setup_18 .x | bash -
124+ curl -fsSL https://rpm.nodesource.com/setup_20 .x | bash -
93125 yum install -y nodejs
94126
95127 - name : Setup Zig
@@ -111,13 +143,45 @@ jobs:
111143 echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
112144 echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
113145
146+ - name : Cache npm dependencies
147+ id : cache-npm
148+ uses : actions/cache@v4
149+ with :
150+ path : node_modules
151+ key : npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('package-lock.json') }}
152+ restore-keys : |
153+ npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-
154+
155+ - name : Cache RocketMQ native deps
156+ uses : actions/cache@v4
157+ with :
158+ path : |
159+ deps/rocketmq/bin
160+ deps/rocketmq/libs/signature/lib
161+ deps/rocketmq/tmp_down_dir
162+ key : rocketmq-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('deps/rocketmq/build.sh', 'deps/rocketmq/CMakeLists.txt') }}
163+ restore-keys : |
164+ rocketmq-${{ runner.os }}-${{ env.ZIG_TARGET }}-
165+
166+ - name : Cache addon build
167+ id : cache-addon
168+ uses : actions/cache@v4
169+ with :
170+ path : build/rocketmq.node
171+ key : addon-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('lib/**', 'CMakeLists.txt', 'package.json') }}
172+ restore-keys : |
173+ addon-${{ runner.os }}-${{ env.ZIG_TARGET }}-
174+
114175 - name : Install npm dependencies
176+ if : steps.cache-npm.outputs.cache-hit != 'true'
115177 run : npm install --no-audit --prefer-offline
116178
117179 - name : Build RocketMQ native deps
180+ if : steps.cache-addon.outputs.cache-hit != 'true'
118181 run : ./deps/rocketmq/build.sh
119182
120183 - name : Build addon
184+ if : steps.cache-addon.outputs.cache-hit != 'true'
121185 run : npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
122186
123187 - name : Package artifact
@@ -135,15 +199,15 @@ jobs:
135199 linux-musl-x64 :
136200 runs-on : ubuntu-24.04
137201 container :
138- image : alpine:latest
202+ image : node:20-alpine
139203 env :
140204 ZIG_TARGET : x86_64-linux-musl
141205 steps :
142206 - name : Checkout
143207 uses : actions/checkout@v4
144208
145209 - name : Install system dependencies
146- run : apk add --no-cache nodejs npm bash build-base cmake ninja python3 curl unzip git autoconf automake libtool pkgconfig
210+ run : apk add --no-cache bash build-base cmake ninja python3 curl unzip git autoconf automake libtool pkgconfig
147211
148212 - name : Setup Zig
149213 uses : mlugg/setup-zig@v2
@@ -164,13 +228,45 @@ jobs:
164228 echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
165229 echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
166230
231+ - name : Cache npm dependencies
232+ id : cache-npm
233+ uses : actions/cache@v4
234+ with :
235+ path : node_modules
236+ key : npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('package-lock.json') }}
237+ restore-keys : |
238+ npm-${{ runner.os }}-
239+
240+ - name : Cache RocketMQ native deps
241+ uses : actions/cache@v4
242+ with :
243+ path : |
244+ deps/rocketmq/bin
245+ deps/rocketmq/libs/signature/lib
246+ deps/rocketmq/tmp_down_dir
247+ key : rocketmq-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('deps/rocketmq/build.sh', 'deps/rocketmq/CMakeLists.txt') }}
248+ restore-keys : |
249+ rocketmq-${{ runner.os }}-
250+
251+ - name : Cache addon build
252+ id : cache-addon
253+ uses : actions/cache@v4
254+ with :
255+ path : build/rocketmq.node
256+ key : addon-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('lib/**', 'CMakeLists.txt', 'package.json') }}
257+ restore-keys : |
258+ addon-${{ runner.os }}-
259+
167260 - name : Install npm dependencies
261+ if : steps.cache-npm.outputs.cache-hit != 'true'
168262 run : npm install --no-audit --prefer-offline
169263
170264 - name : Build RocketMQ native deps
265+ if : steps.cache-addon.outputs.cache-hit != 'true'
171266 run : ./deps/rocketmq/build.sh
172267
173268 - name : Build addon
269+ if : steps.cache-addon.outputs.cache-hit != 'true'
174270 run : npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
175271
176272 - name : Package artifact
@@ -196,7 +292,7 @@ jobs:
196292 - name : Setup Node.js
197293 uses : actions/setup-node@v4
198294 with :
199- node-version : 18
295+ node-version : 20
200296
201297 - name : Install system dependencies
202298 run : sudo apt-get update && sudo apt-get install -y build-essential cmake ninja-build python3 curl unzip git autoconf automake libtool pkg-config
@@ -220,13 +316,45 @@ jobs:
220316 echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
221317 echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
222318
319+ - name : Cache npm dependencies
320+ id : cache-npm
321+ uses : actions/cache@v4
322+ with :
323+ path : node_modules
324+ key : npm-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('package-lock.json') }}
325+ restore-keys : |
326+ npm-${{ runner.os }}-
327+
328+ - name : Cache RocketMQ native deps
329+ uses : actions/cache@v4
330+ with :
331+ path : |
332+ deps/rocketmq/bin
333+ deps/rocketmq/libs/signature/lib
334+ deps/rocketmq/tmp_down_dir
335+ key : rocketmq-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('deps/rocketmq/build.sh', 'deps/rocketmq/CMakeLists.txt') }}
336+ restore-keys : |
337+ rocketmq-${{ runner.os }}-
338+
339+ - name : Cache addon build
340+ id : cache-addon
341+ uses : actions/cache@v4
342+ with :
343+ path : build/rocketmq.node
344+ key : addon-${{ runner.os }}-${{ env.ZIG_TARGET }}-${{ hashFiles('lib/**', 'CMakeLists.txt', 'package.json') }}
345+ restore-keys : |
346+ addon-${{ runner.os }}-
347+
223348 - name : Install npm dependencies
349+ if : steps.cache-npm.outputs.cache-hit != 'true'
224350 run : npm install --no-audit --prefer-offline
225351
226352 - name : Build RocketMQ native deps
353+ if : steps.cache-addon.outputs.cache-hit != 'true'
227354 run : ./deps/rocketmq/build.sh
228355
229356 - name : Build addon
357+ if : steps.cache-addon.outputs.cache-hit != 'true'
230358 run : npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
231359
232360 - name : Package artifact
@@ -250,18 +378,50 @@ jobs:
250378 - name : Setup Node.js
251379 uses : actions/setup-node@v4
252380 with :
253- node-version : 18
381+ node-version : 20
254382
255383 - name : Install build tools
256384 run : brew install cmake ninja xz autoconf automake libtool pkg-config
257385
386+ - name : Cache npm dependencies
387+ id : cache-npm
388+ uses : actions/cache@v4
389+ with :
390+ path : node_modules
391+ key : npm-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}
392+ restore-keys : |
393+ npm-${{ runner.os }}-
394+
395+ - name : Cache RocketMQ native deps
396+ uses : actions/cache@v4
397+ with :
398+ path : |
399+ deps/rocketmq/bin
400+ deps/rocketmq/libs/signature/lib
401+ deps/rocketmq/tmp_down_dir
402+ key : rocketmq-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('deps/rocketmq/build.sh', 'deps/rocketmq/CMakeLists.txt') }}
403+ restore-keys : |
404+ rocketmq-${{ runner.os }}-
405+
406+ - name : Cache addon build
407+ id : cache-addon
408+ uses : actions/cache@v4
409+ with :
410+ path : build/rocketmq.node
411+ key : addon-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('lib/**', 'CMakeLists.txt', 'package.json') }}
412+ restore-keys : |
413+ addon-${{ runner.os }}-
414+
258415 - name : Install npm dependencies
416+ if : steps.cache-npm.outputs.cache-hit != 'true'
259417 run : npm install --no-audit --prefer-offline
260418
261419 - name : Build RocketMQ native deps
420+ if : steps.cache-addon.outputs.cache-hit != 'true'
262421 run : ./deps/rocketmq/build.sh
263422
264423 - name : Build addon
424+ if : steps.cache-addon.outputs.cache-hit != 'true'
265425 run : |
266426 npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release \
267427 --CDCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
@@ -283,7 +443,7 @@ jobs:
283443 release :
284444 needs : [linux-gnu-x64, linux-gnu-arm64, linux-musl-x64, linux-musl-arm64, macos-universal]
285445 runs-on : ubuntu-latest
286- if : github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master ')
446+ if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
287447 permissions :
288448 contents : write
289449 steps :
@@ -304,10 +464,10 @@ jobs:
304464 - name : Create Release
305465 uses : softprops/action-gh-release@v1
306466 with :
307- tag_name : ${{ startsWith( github.ref, 'refs/tags/v') && github. ref_name || format('build-{0}', github.sha) }}
308- name : ${{ startsWith( github.ref, 'refs/tags/v') && github. ref_name || format('Build {0}', github.sha) }}
467+ tag_name : ${{ github.ref_name }}
468+ name : ${{ github.ref_name }}
309469 draft : false
310- prerelease : ${{ !startsWith(github.ref, 'refs/tags/v') }}
470+ prerelease : false
311471 files : Release/*.node
312472 env :
313473 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -323,8 +483,10 @@ jobs:
323483 - name : Setup Node.js
324484 uses : actions/setup-node@v4
325485 with :
326- node-version : 18
486+ node-version : 20
327487 registry-url : ' https://registry.npmjs.org'
488+ cache : ' npm'
489+ cache-dependency-path : package-lock.json
328490
329491 - name : Download all artifacts
330492 uses : actions/download-artifact@v4
@@ -337,7 +499,64 @@ jobs:
337499 find artifacts -name "*.node" -exec cp {} Release/ \;
338500 ls -lh Release/
339501
502+ - name : Verify version consistency
503+ if : startsWith(github.ref, 'refs/tags/v')
504+ run : |
505+ PKG_VERSION=$(node -p "require('./package.json').version")
506+ TAG_VERSION=${GITHUB_REF#refs/tags/v}
507+ if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
508+ echo "❌ Version mismatch: package.json=$PKG_VERSION, tag=$TAG_VERSION"
509+ exit 1
510+ fi
511+ echo "✅ Version consistent: $PKG_VERSION"
512+
513+ - name : Install dependencies (skip native build)
514+ run : npm ci --include=dev --ignore-scripts
515+ env :
516+ NODE_ENV : development
517+ NPM_CONFIG_PRODUCTION : " false"
518+
519+ - name : Ensure node types
520+ run : |
521+ if [ ! -f "node_modules/@types/node/index.d.ts" ]; then
522+ NODE_TYPES_VERSION=$(node -p "require('./package.json').devDependencies['@types/node']")
523+ npm install --no-save --no-package-lock --ignore-scripts "@types/node@${NODE_TYPES_VERSION}"
524+ fi
525+
526+ - name : Build TypeScript
527+ run : npm run build:ts
528+
529+ - name : Validate build output
530+ run : |
531+ echo "Validating TypeScript build..."
532+ if [ ! -f "dist/index.js" ]; then
533+ echo "❌ dist/index.js not found"
534+ exit 1
535+ fi
536+ if [ ! -f "dist/index.d.ts" ]; then
537+ echo "❌ dist/index.d.ts not found"
538+ exit 1
539+ fi
540+ echo "✅ TypeScript build verified"
541+
542+ echo "Validating native addons..."
543+ for f in linux-x86_64-gnu linux-aarch64-gnu linux-x86_64-musl linux-aarch64-musl darwin-universal; do
544+ if [ ! -f "Release/${f}-rocketmq.node" ]; then
545+ echo "❌ Missing: ${f}-rocketmq.node"
546+ exit 1
547+ fi
548+ done
549+ echo "✅ All native addons present"
550+
551+ - name : Verify package contents
552+ run : |
553+ echo "=== Package contents ==="
554+ npm pack --dry-run
555+ echo ""
556+ echo "=== Release binaries ==="
557+ ls -lh Release/
558+
340559 - name : Publish to npm
341- run : npm publish
560+ run : npm publish --ignore-scripts
342561 env :
343562 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments