Skip to content

Commit aaeb05c

Browse files
committed
fix: update build.yml for improved build and release process with multi-architecture support
1 parent eb5d453 commit aaeb05c

1 file changed

Lines changed: 157 additions & 47 deletions

File tree

.github/workflows/build.yml

Lines changed: 157 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,158 @@
1-
name: Build Addons
1+
name: Build and Release
22

33
on:
44
push:
55
branches:
66
- master
7+
tags:
8+
- 'v*'
79
pull_request:
10+
workflow_dispatch:
11+
inputs:
12+
publish_npm:
13+
description: 'Publish to npm'
14+
required: false
15+
type: boolean
16+
default: false
817

918
jobs:
10-
linux-gnu:
11-
runs-on: ubuntu-latest
19+
linux-gnu-x64:
20+
runs-on: ubuntu-24.04
1221
container:
1322
image: alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest
1423
steps:
1524
- name: Install prerequisites
16-
run: |
17-
set -eux
18-
yum install -y git curl wget xz tar unzip rsync which python3 python3-pip python3-setuptools autoconf automake libtool pkgconfig gcc gcc-c++ make ninja-build cmake file vim procps-ng iputils
25+
run: yum install -y git curl wget xz tar unzip rsync which python3 python3-pip python3-setuptools autoconf automake libtool pkgconfig gcc gcc-c++ make ninja-build cmake file vim procps-ng iputils
1926

2027
- name: Checkout
2128
uses: actions/checkout@v4
2229

23-
- name: Install Node.js via NodeSource
30+
- name: Install Node.js
2431
run: |
25-
set -eux
2632
curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -
2733
yum install -y nodejs
28-
node -v
29-
npm -v
3034
3135
- name: Install npm dependencies
32-
run: |
33-
set -eux
34-
npm install --no-audit --prefer-offline
36+
run: npm install --no-audit --prefer-offline
3537

3638
- name: Build RocketMQ native deps
39+
run: ./deps/rocketmq/build.sh
40+
41+
- name: Build addon
42+
run: npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
43+
44+
- name: Package artifact
3745
run: |
38-
set -eux
39-
./deps/rocketmq/build.sh
46+
mkdir -p Release
47+
strip --strip-all build/rocketmq.node
48+
cp build/rocketmq.node Release/linux-x86_64-gnu-rocketmq.node
4049
41-
- name: Build addon (glibc)
50+
- name: Upload artifact
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: linux-x86_64-gnu
54+
path: Release/linux-x86_64-gnu-rocketmq.node
55+
56+
linux-gnu-arm64:
57+
runs-on: ubuntu-24.04-arm
58+
container:
59+
image: alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest
60+
steps:
61+
- name: Install prerequisites
62+
run: yum install -y git curl wget xz tar unzip rsync which python3 python3-pip python3-setuptools autoconf automake libtool pkgconfig gcc gcc-c++ make ninja-build cmake file vim procps-ng iputils
63+
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
67+
- name: Install Node.js
4268
run: |
43-
set -eux
44-
npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
69+
curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -
70+
yum install -y nodejs
4571
46-
- name: Detect architecture
47-
run: echo "arch=$(uname -m)" >> $GITHUB_OUTPUT
48-
id: detect_arch
72+
- name: Install npm dependencies
73+
run: npm install --no-audit --prefer-offline
74+
75+
- name: Build RocketMQ native deps
76+
run: ./deps/rocketmq/build.sh
77+
78+
- name: Build addon
79+
run: npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
4980

5081
- name: Package artifact
5182
run: |
52-
set -eux
5383
mkdir -p Release
54-
cp build/rocketmq.node Release/linux-${{ steps.detect_arch.outputs.arch }}-gnu-debug-rocketmq.node
5584
strip --strip-all build/rocketmq.node
56-
cp build/rocketmq.node Release/linux-${{ steps.detect_arch.outputs.arch }}-gnu-rocketmq.node
85+
cp build/rocketmq.node Release/linux-aarch64-gnu-rocketmq.node
5786
5887
- name: Upload artifact
5988
uses: actions/upload-artifact@v4
6089
with:
61-
name: linux-${{ steps.detect_arch.outputs.arch }}-gnu
62-
path: |
63-
Release/linux-${{ steps.detect_arch.outputs.arch }}-gnu-rocketmq.node
64-
Release/linux-${{ steps.detect_arch.outputs.arch }}-gnu-debug-rocketmq.node
90+
name: linux-aarch64-gnu
91+
path: Release/linux-aarch64-gnu-rocketmq.node
6592

66-
linux-musl:
67-
runs-on: ubuntu-latest
93+
linux-musl-x64:
94+
runs-on: ubuntu-24.04
6895
container:
6996
image: alpine:latest
7097
steps:
7198
- name: Checkout
7299
uses: actions/checkout@v4
73100

74101
- name: Install system dependencies
75-
run: |
76-
apk add --no-cache nodejs npm bash build-base cmake ninja python3 curl unzip git autoconf automake libtool pkgconfig ninja-build
102+
run: apk add --no-cache nodejs npm bash build-base cmake ninja python3 curl unzip git autoconf automake libtool pkgconfig
77103

78104
- name: Install npm dependencies
79105
run: npm install --no-audit --prefer-offline
80106

81107
- name: Build RocketMQ native deps
82108
run: ./deps/rocketmq/build.sh
83109

84-
- name: Build addon (musl)
110+
- name: Build addon
85111
run: npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
86112

87-
- name: Detect architecture
88-
run: echo "arch=$(uname -m)" >> $GITHUB_OUTPUT
89-
id: detect_arch
113+
- name: Package artifact
114+
run: |
115+
mkdir -p Release
116+
strip --strip-all build/rocketmq.node
117+
cp build/rocketmq.node Release/linux-x86_64-musl-rocketmq.node
118+
119+
- name: Upload artifact
120+
uses: actions/upload-artifact@v4
121+
with:
122+
name: linux-x86_64-musl
123+
path: Release/linux-x86_64-musl-rocketmq.node
124+
125+
linux-musl-arm64:
126+
runs-on: ubuntu-24.04-arm
127+
container:
128+
image: alpine:latest
129+
steps:
130+
- name: Checkout
131+
uses: actions/checkout@v4
132+
133+
- name: Install system dependencies
134+
run: apk add --no-cache nodejs npm bash build-base cmake ninja python3 curl unzip git autoconf automake libtool pkgconfig
135+
136+
- name: Install npm dependencies
137+
run: npm install --no-audit --prefer-offline
138+
139+
- name: Build RocketMQ native deps
140+
run: ./deps/rocketmq/build.sh
141+
142+
- name: Build addon
143+
run: npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
90144

91145
- name: Package artifact
92146
run: |
93147
mkdir -p Release
94-
cp build/rocketmq.node Release/linux-${{ steps.detect_arch.outputs.arch }}-musl-debug-rocketmq.node
95148
strip --strip-all build/rocketmq.node
96-
cp build/rocketmq.node Release/linux-${{ steps.detect_arch.outputs.arch }}-musl-rocketmq.node
149+
cp build/rocketmq.node Release/linux-aarch64-musl-rocketmq.node
97150
98151
- name: Upload artifact
99152
uses: actions/upload-artifact@v4
100153
with:
101-
name: linux-${{ steps.detect_arch.outputs.arch }}-musl
102-
path: |
103-
Release/linux-${{ steps.detect_arch.outputs.arch }}-musl-rocketmq.node
104-
Release/linux-${{ steps.detect_arch.outputs.arch }}-musl-debug-rocketmq.node
154+
name: linux-aarch64-musl
155+
path: Release/linux-aarch64-musl-rocketmq.node
105156

106157
macos-universal:
107158
runs-on: macos-latest
@@ -123,7 +174,7 @@ jobs:
123174
- name: Build RocketMQ native deps
124175
run: ./deps/rocketmq/build.sh
125176

126-
- name: Build addon (Darwin universal)
177+
- name: Build addon
127178
run: |
128179
npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release \
129180
--CDCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
@@ -133,14 +184,73 @@ jobs:
133184
- name: Package artifact
134185
run: |
135186
mkdir -p Release
136-
cp build/rocketmq.node Release/darwin-universal-debug-rocketmq.node
137187
strip -S -x build/rocketmq.node
138188
cp build/rocketmq.node Release/darwin-universal-rocketmq.node
139189
140190
- name: Upload artifact
141191
uses: actions/upload-artifact@v4
142192
with:
143193
name: darwin-universal
144-
path: |
145-
Release/darwin-universal-rocketmq.node
146-
Release/darwin-universal-debug-rocketmq.node
194+
path: Release/darwin-universal-rocketmq.node
195+
196+
release:
197+
needs: [linux-gnu-x64, linux-gnu-arm64, linux-musl-x64, linux-musl-arm64, macos-universal]
198+
runs-on: ubuntu-latest
199+
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master')
200+
permissions:
201+
contents: write
202+
steps:
203+
- name: Checkout
204+
uses: actions/checkout@v4
205+
206+
- name: Download all artifacts
207+
uses: actions/download-artifact@v4
208+
with:
209+
path: artifacts
210+
211+
- name: Prepare Release directory
212+
run: |
213+
mkdir -p Release
214+
find artifacts -name "*.node" -exec cp {} Release/ \;
215+
ls -lh Release/
216+
217+
- name: Create Release
218+
uses: softprops/action-gh-release@v1
219+
with:
220+
tag_name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || format('build-{0}', github.sha) }}
221+
name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || format('Build {0}', github.sha) }}
222+
draft: false
223+
prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') }}
224+
files: Release/*.node
225+
env:
226+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
227+
228+
publish-npm:
229+
needs: release
230+
runs-on: ubuntu-latest
231+
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && inputs.publish_npm)
232+
steps:
233+
- name: Checkout
234+
uses: actions/checkout@v4
235+
236+
- name: Setup Node.js
237+
uses: actions/setup-node@v4
238+
with:
239+
node-version: 18
240+
registry-url: 'https://registry.npmjs.org'
241+
242+
- name: Download all artifacts
243+
uses: actions/download-artifact@v4
244+
with:
245+
path: artifacts
246+
247+
- name: Prepare Release directory
248+
run: |
249+
mkdir -p Release
250+
find artifacts -name "*.node" -exec cp {} Release/ \;
251+
ls -lh Release/
252+
253+
- name: Publish to npm
254+
run: npm publish
255+
env:
256+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)