Skip to content

Commit 09b2915

Browse files
committed
feat: Use prebuildify to produce platform binaries
1 parent c1b41e3 commit 09b2915

File tree

4 files changed

+1681
-10
lines changed

4 files changed

+1681
-10
lines changed

.github/workflows/release.yml

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
6+
pull_request:
7+
branches:
8+
- master
9+
10+
release:
11+
types: [published]
12+
13+
workflow_dispatch:
14+
inputs:
15+
new-version:
16+
description: New version to be published, overrides tag
17+
required: true
18+
type: string
19+
20+
npm-tag:
21+
description: NPM tag
22+
required: true
23+
default: latest
24+
type: choice
25+
options:
26+
- latest
27+
- next
28+
29+
jobs:
30+
build:
31+
strategy:
32+
matrix:
33+
include:
34+
- os: ubuntu-22.04
35+
arch: linux-x64-glibc
36+
- os: ubuntu-22.04-arm
37+
arch: linux-arm64-glibc
38+
- os: macos-13
39+
arch: darwin-x64
40+
- os: macos-14
41+
arch: darwin-arm64
42+
43+
name: Build for ${{ matrix.arch }}
44+
runs-on: ${{ matrix.os }}
45+
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
with:
50+
submodules: true
51+
52+
- name: Use Node.js 20
53+
uses: actions/setup-node@v4
54+
with:
55+
cache: npm
56+
node-version: 20
57+
58+
- name: Install Ubuntu dependencies
59+
run: sudo apt-get install -y libpcap-dev libnetfilter-queue-dev
60+
if: runner.os == 'Linux'
61+
62+
- name: Install dependencies
63+
run: npm ci
64+
65+
- name: Prebuild
66+
run: npm run build
67+
68+
- name: Upload artifacts
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: prebuild-${{ matrix.arch }}
72+
path: prebuilds/**/*.node
73+
74+
build-musl:
75+
strategy:
76+
matrix:
77+
include:
78+
- os: ubuntu-22.04
79+
arch: x64
80+
platform: linux/amd64
81+
- os: ubuntu-22.04-arm
82+
arch: arm64
83+
platform: linux/arm64
84+
- os: ubuntu-22.04-arm
85+
arch: armv7
86+
platform: linux/arm/v7
87+
88+
name: Build for linux-${{ matrix.arch }}-musl
89+
runs-on: ${{ matrix.os }}
90+
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v4
94+
with:
95+
submodules: true
96+
97+
- name: Set up QEMU
98+
uses: docker/setup-qemu-action@v3
99+
with:
100+
platforms: ${{ matrix.platform }}
101+
102+
- name: Prebuild
103+
uses: addnab/docker-run-action@v3
104+
with:
105+
image: node:20-alpine
106+
options: --platform=${{ matrix.platform }} --volume=${{ github.workspace }}:/repo --workdir=/repo
107+
run: |
108+
apk add --no-cache g++ make python3 linux-headers libpcap-dev libnetfilter_queue-dev
109+
npm ci
110+
npm run build
111+
112+
- name: Upload artifacts
113+
uses: actions/upload-artifact@v4
114+
with:
115+
name: prebuild-linux-${{ matrix.arch }}-musl
116+
path: prebuilds/**/*.node
117+
118+
build-freebsd-x64:
119+
name: Build for freebsd-x64
120+
runs-on: ubuntu-latest
121+
122+
steps:
123+
- name: Checkout
124+
uses: actions/checkout@v4
125+
with:
126+
submodules: true
127+
128+
- name: Prebuild
129+
uses: vmactions/freebsd-vm@v1
130+
with:
131+
prepare: |
132+
pkg install -y gmake python3 npm-node20
133+
run: |
134+
npm ci
135+
npm run build
136+
sync: sshfs
137+
138+
- name: Upload artifacts
139+
uses: actions/upload-artifact@v4
140+
with:
141+
name: prebuild-freebsd-x64
142+
path: prebuilds/**/*.node
143+
144+
build-linux-armv7-glibc:
145+
name: Build for linux-armv7-glibc
146+
runs-on: ubuntu-latest
147+
148+
steps:
149+
- name: Checkout
150+
uses: actions/checkout@v4
151+
with:
152+
submodules: true
153+
154+
- name: Set up QEMU
155+
uses: docker/setup-qemu-action@v3
156+
with:
157+
platforms: linux/arm/v7
158+
159+
- name: Prebuild
160+
uses: addnab/docker-run-action@v3
161+
with:
162+
image: node:20-bullseye
163+
options: --platform=linux/arm/v7 --volume=${{ github.workspace }}:/repo --workdir=/repo
164+
run: |
165+
apt update -yq && apt install -yq wget libpcap-dev libnetfilter-queue-dev
166+
wget -qL https://deb.nodesource.com/setup_20.x | bash -
167+
apt install -yq g++ make python3 nodejs
168+
npm ci
169+
npm run build
170+
171+
- name: Upload artifacts
172+
uses: actions/upload-artifact@v4
173+
with:
174+
name: prebuild-linux-armv7-glibc
175+
path: prebuilds/**/*.node
176+
177+
publish:
178+
name: Publish package
179+
runs-on: ubuntu-latest
180+
181+
permissions:
182+
contents: read
183+
id-token: write
184+
185+
needs:
186+
- build
187+
- build-musl
188+
- build-freebsd-x64
189+
- build-linux-armv7-glibc
190+
191+
steps:
192+
- name: Checkout
193+
uses: actions/checkout@v4
194+
with:
195+
submodules: true
196+
197+
- name: Setup npm with Node.js 20
198+
uses: actions/setup-node@v4
199+
with:
200+
cache: npm
201+
node-version: 20
202+
token: ${{ secrets.NPM_TOKEN }}
203+
registry-url: 'https://registry.npmjs.org'
204+
205+
- name: Install dependencies
206+
run: npm ci --ignore-scripts
207+
208+
- name: Download artifacts
209+
id: download-artifact
210+
uses: actions/download-artifact@v4
211+
212+
- name: Move prebuild artifacts
213+
run: mkdir prebuilds && cp --recursive prebuild-*/* prebuilds/
214+
215+
- name: Pack package
216+
run: npm pack
217+
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
218+
219+
- name: Upload package artifact
220+
uses: actions/upload-artifact@v4
221+
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
222+
with:
223+
name: package
224+
path: '*.tgz'
225+
226+
- name: Publish to NPM
227+
run: |
228+
npm version --allow-same-version --no-git-tag-version $VERSION
229+
npm publish --provenance --tag $TAG
230+
if: ${{ !env.ACT && (github.event_name == 'release' || github.event_name == 'workflow_dispatch') }}
231+
env:
232+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
233+
TAG: ${{ inputs.npm-tag || 'latest' }}
234+
VERSION: ${{ inputs.new-version || github.ref_name }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build/
2+
prebuilds/
23
npm-debug.log
34
node_modules/
45
.idea/

0 commit comments

Comments
 (0)