1+ name : Build Pre-built Binaries
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*'
7+ workflow_dispatch :
8+ inputs :
9+ build_type :
10+ description : ' Build type'
11+ required : true
12+ default : ' release'
13+ type : choice
14+ options :
15+ - release
16+ - debug
17+
18+ env :
19+ CARGO_TERM_COLOR : always
20+
21+ jobs :
22+ build :
23+ name : Build ${{ matrix.platform.name }}
24+ runs-on : ${{ matrix.platform.os }}
25+ strategy :
26+ fail-fast : false
27+ matrix :
28+ platform :
29+ # macOS builds
30+ - name : darwin-x64
31+ os : macos-12
32+ target : x86_64-apple-darwin
33+ node_arch : x64
34+ setup : |
35+ brew install llvm@18 python@3.11
36+ echo "LLVM_SYS_180_PREFIX=$(brew --prefix llvm@18)" >> $GITHUB_ENV
37+
38+ - name : darwin-arm64
39+ os : macos-14
40+ target : aarch64-apple-darwin
41+ node_arch : arm64
42+ setup : |
43+ brew install llvm@18 python@3.11
44+ echo "LLVM_SYS_180_PREFIX=$(brew --prefix llvm@18)" >> $GITHUB_ENV
45+
46+ # Linux builds
47+ - name : linux-x64-gnu
48+ os : ubuntu-20.04
49+ target : x86_64-unknown-linux-gnu
50+ node_arch : x64
51+ setup : |
52+ sudo apt-get update
53+ sudo apt-get install -y python3-dev
54+ wget https://apt.llvm.org/llvm.sh
55+ chmod +x llvm.sh
56+ sudo ./llvm.sh 18
57+ echo "LLVM_SYS_180_PREFIX=/usr/lib/llvm-18" >> $GITHUB_ENV
58+
59+ - name : linux-arm64-gnu
60+ os : ubuntu-20.04
61+ target : aarch64-unknown-linux-gnu
62+ node_arch : arm64
63+ setup : |
64+ sudo apt-get update
65+ sudo apt-get install -y gcc-aarch64-linux-gnu python3-dev
66+ # Install LLVM for ARM64 cross-compilation
67+ wget https://apt.llvm.org/llvm.sh
68+ chmod +x llvm.sh
69+ sudo ./llvm.sh 18
70+ echo "LLVM_SYS_180_PREFIX=/usr/lib/llvm-18" >> $GITHUB_ENV
71+
72+ # Windows builds
73+ - name : win32-x64-msvc
74+ os : windows-2022
75+ target : x86_64-pc-windows-msvc
76+ node_arch : x64
77+ setup : |
78+ choco install llvm --version=18.0.0 -y
79+ choco install python -y
80+ echo "LLVM_SYS_180_PREFIX=C:\Program Files\LLVM" >> $env:GITHUB_ENV
81+
82+ steps :
83+ - uses : actions/checkout@v4
84+
85+ - name : Setup Node.js
86+ uses : actions/setup-node@v4
87+ with :
88+ node-version : 20
89+ architecture : ${{ matrix.platform.node_arch }}
90+
91+ - name : Install Rust
92+ uses : dtolnay/rust-toolchain@stable
93+ with :
94+ targets : ${{ matrix.platform.target }}
95+
96+ - name : Setup platform dependencies
97+ if : matrix.platform.setup
98+ run : ${{ matrix.platform.setup }}
99+ shell : bash
100+
101+ - name : Install dependencies
102+ run : npm ci --ignore-scripts
103+
104+ - name : Build native bindings
105+ run : |
106+ cd native
107+ cargo build --release --target ${{ matrix.platform.target }}
108+ npx napi build --platform --release --target ${{ matrix.platform.target }}
109+ shell : bash
110+
111+ - name : Build TypeScript
112+ run : npm run build:ts
113+
114+ - name : Test binaries
115+ if : !contains(matrix.platform.target, 'aarch64')
116+ run : npm test
117+ continue-on-error : true
118+
119+ - name : Package binary
120+ run : |
121+ mkdir -p artifacts
122+ cp native/*.node artifacts/
123+ tar -czf node-rc-${{ matrix.platform.name }}.tar.gz -C artifacts .
124+ shell : bash
125+
126+ - name : Upload artifacts
127+ uses : actions/upload-artifact@v4
128+ with :
129+ name : binaries-${{ matrix.platform.name }}
130+ path : node-rc-${{ matrix.platform.name }}.tar.gz
131+ retention-days : 7
132+
133+ release :
134+ name : Create Release
135+ needs : build
136+ runs-on : ubuntu-latest
137+ if : startsWith(github.ref, 'refs/tags/')
138+
139+ steps :
140+ - uses : actions/checkout@v4
141+
142+ - name : Download all artifacts
143+ uses : actions/download-artifact@v4
144+ with :
145+ path : artifacts
146+
147+ - name : Create Release
148+ id : create_release
149+ uses : actions/create-release@v1
150+ env :
151+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
152+ with :
153+ tag_name : ${{ github.ref }}
154+ release_name : Release ${{ github.ref }}
155+ body : |
156+ ## Pre-built Binaries
157+
158+ This release includes pre-built native bindings for:
159+ - macOS (x64, ARM64)
160+ - Linux (x64, ARM64)
161+ - Windows (x64)
162+
163+ ### Installation
164+
165+ #### Option 1: NPM Install
166+ ```bash
167+ npm install node-rc
168+ ```
169+
170+ #### Option 2: Manual Binary Installation
171+ 1. Download the appropriate binary for your platform
172+ 2. Extract to `node_modules/node-rc/native/`
173+ 3. Run `npm run build:ts` to build TypeScript files
174+
175+ ### What's New
176+ See [CHANGELOG.md](https://github.com/rizome-dev/node-rc/blob/main/CHANGELOG.md) for details.
177+ draft : false
178+ prerelease : false
179+
180+ - name : Upload Release Assets
181+ run : |
182+ for file in artifacts/binaries-*/*.tar.gz; do
183+ echo "Uploading $file"
184+ gh release upload ${{ github.ref_name }} "$file" --clobber
185+ done
186+ env :
187+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
188+
189+ npm-publish :
190+ name : Publish to NPM
191+ needs : build
192+ runs-on : ubuntu-latest
193+ if : startsWith(github.ref, 'refs/tags/')
194+
195+ steps :
196+ - uses : actions/checkout@v4
197+
198+ - name : Setup Node.js
199+ uses : actions/setup-node@v4
200+ with :
201+ node-version : 20
202+ registry-url : ' https://registry.npmjs.org'
203+
204+ - name : Download Linux x64 binary
205+ uses : actions/download-artifact@v4
206+ with :
207+ name : binaries-linux-x64-gnu
208+ path : .
209+
210+ - name : Extract binary
211+ run : |
212+ tar -xzf node-rc-linux-x64-gnu.tar.gz -C native/
213+
214+ - name : Build TypeScript
215+ run : |
216+ npm ci --ignore-scripts
217+ npm run build:ts
218+
219+ - name : Publish to NPM
220+ run : npm publish
221+ env :
222+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments