Skip to content

Commit e416ac7

Browse files
committed
Split release process out to manual workflow_dispatch
1 parent 0638e49 commit e416ac7

File tree

9 files changed

+465
-459
lines changed

9 files changed

+465
-459
lines changed

.github/workflows/CI.yml

Lines changed: 5 additions & 398 deletions
Large diffs are not rendered by default.
Lines changed: 365 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,365 @@
1+
name: Build and Test
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
run-tests:
7+
description: 'Whether to run tests after build'
8+
required: false
9+
type: boolean
10+
default: true
11+
12+
env:
13+
DEBUG: napi:*
14+
APP_NAME: python-node
15+
MACOSX_DEPLOYMENT_TARGET: '10.13'
16+
17+
jobs:
18+
build-wasm:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
sparse-checkout: |
24+
fix-python-soname
25+
fix-python-soname.js
26+
sparse-checkout-cone-mode: false
27+
- name: Install Rust toolchain
28+
uses: dtolnay/rust-toolchain@stable
29+
with:
30+
targets: wasm32-wasip1
31+
- name: Cache cargo
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.cargo/registry/index/
36+
~/.cargo/registry/cache/
37+
~/.cargo/git/db/
38+
.cargo-cache
39+
target/
40+
key: wasm-cargo-cache-${{ hashFiles('**/Cargo.lock') }}
41+
- name: Build WASM
42+
working-directory: fix-python-soname
43+
run: |
44+
cargo build --target wasm32-wasip1 --release
45+
cp target/wasm32-wasip1/release/fix-python-soname.wasm ../fix-python-soname.wasm
46+
- name: Upload WASM artifacts
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: wasm-bindings
50+
path: |
51+
fix-python-soname.wasm
52+
fix-python-soname.js
53+
54+
build:
55+
needs: build-wasm
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
settings:
60+
- host: macos-latest
61+
target: aarch64-apple-darwin
62+
npm_dir: darwin-arm64
63+
build: pnpm run build --target aarch64-apple-darwin
64+
- host: ubuntu-latest
65+
target: x86_64-unknown-linux-gnu
66+
npm_dir: linux-x64-gnu
67+
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
68+
build: pnpm run build --target x86_64-unknown-linux-gnu
69+
name: stable - ${{ matrix.settings.target }} - node@20
70+
runs-on: ${{ matrix.settings.host }}
71+
steps:
72+
- uses: actions/checkout@v4
73+
- name: Download WASM artifact
74+
uses: actions/download-artifact@v4
75+
with:
76+
name: wasm-bindings
77+
path: npm/${{ matrix.settings.npm_dir }}
78+
- uses: pnpm/action-setup@v4
79+
with:
80+
version: latest
81+
- uses: actions/setup-node@v4
82+
if: ${{ !matrix.settings.docker }}
83+
with:
84+
node-version: 24
85+
- uses: dtolnay/rust-toolchain@stable
86+
if: ${{ !matrix.settings.docker }}
87+
with:
88+
toolchain: stable
89+
targets: ${{ matrix.settings.target }}
90+
- uses: actions/cache@v4
91+
with:
92+
path: |
93+
~/.cargo/registry/index/
94+
~/.cargo/registry/cache/
95+
~/.cargo/git/db/
96+
.cargo-cache
97+
target/
98+
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
99+
- uses: goto-bus-stop/setup-zig@v2
100+
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }}
101+
with:
102+
version: 0.13.0
103+
- name: Setup toolchain
104+
run: ${{ matrix.settings.setup }}
105+
if: ${{ matrix.settings.setup }}
106+
shell: bash
107+
- name: Install dependencies
108+
run: pnpm install
109+
- name: Build in docker
110+
uses: addnab/docker-run-action@v3
111+
if: ${{ matrix.settings.docker }}
112+
with:
113+
image: ${{ matrix.settings.docker }}
114+
options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
115+
run: |
116+
set -x
117+
118+
# Install apt dependencies
119+
apt-get update -y
120+
apt-get install -y openssh-client python3 python3-dev
121+
122+
# Setup pnpm
123+
corepack disable
124+
npm i -gf pnpm
125+
126+
${{ matrix.settings.build }}
127+
- name: Build
128+
run: ${{ matrix.settings.build }}
129+
if: ${{ !matrix.settings.docker }}
130+
shell: bash
131+
- name: Prepare npm package
132+
run: pnpm artifacts --output-dir .
133+
shell: bash
134+
135+
- name: Upload npm package artifact
136+
uses: actions/upload-artifact@v4
137+
with:
138+
name: npm-${{ matrix.settings.npm_dir }}
139+
path: npm/${{ matrix.settings.npm_dir }}
140+
if-no-files-found: error
141+
142+
- name: Upload entrypoints artifact
143+
uses: actions/upload-artifact@v4
144+
with:
145+
name: entrypoints
146+
path: |
147+
index.d.ts
148+
index.js
149+
overwrite: true
150+
if-no-files-found: error
151+
152+
bundle:
153+
name: Bundle release artifacts
154+
needs: build
155+
runs-on: ubuntu-latest
156+
steps:
157+
- uses: actions/checkout@v4
158+
159+
- name: Download all npm package artifacts
160+
uses: actions/download-artifact@v4
161+
with:
162+
pattern: npm-*
163+
path: npm-artifacts
164+
165+
- name: Download entrypoints artifact
166+
uses: actions/download-artifact@v4
167+
with:
168+
name: entrypoints
169+
path: .
170+
171+
- name: Organize npm packages
172+
run: |
173+
for dir in npm-artifacts/npm-*/; do
174+
platform=$(basename "$dir" | sed 's/^npm-//')
175+
echo "Moving $dir to npm/$platform/"
176+
mv "$dir"/* "npm/$platform/"
177+
done
178+
rm -rf npm-artifacts
179+
shell: bash
180+
181+
- name: List release bundle contents
182+
run: |
183+
echo "=== Root entrypoints ==="
184+
ls -la index.js index.d.ts
185+
echo ""
186+
echo "=== npm package directories ==="
187+
for dir in npm/*/; do
188+
echo "--- $dir ---"
189+
ls -la "$dir"
190+
done
191+
shell: bash
192+
193+
- name: Upload release bundle
194+
uses: actions/upload-artifact@v4
195+
with:
196+
name: release-bundle
197+
path: |
198+
npm/
199+
index.js
200+
index.d.ts
201+
if-no-files-found: error
202+
203+
test-macOS-binding:
204+
name: Test ${{ matrix.settings.target }} - node@${{ matrix.node }} + python@${{ matrix.python }}
205+
if: ${{ inputs.run-tests }}
206+
needs:
207+
- build
208+
strategy:
209+
fail-fast: false
210+
matrix:
211+
settings:
212+
- host: macos-latest
213+
target: aarch64-apple-darwin
214+
architecture: arm64
215+
npm_dir: darwin-arm64
216+
node:
217+
- '20'
218+
- '22'
219+
- '24'
220+
python:
221+
- '3.8'
222+
- '3.9'
223+
- '3.10'
224+
- '3.11'
225+
- '3.12'
226+
- '3.13'
227+
runs-on: ${{ matrix.settings.host }}
228+
steps:
229+
- uses: actions/checkout@v4
230+
- uses: pnpm/action-setup@v4
231+
with:
232+
version: latest
233+
- uses: actions/setup-node@v4
234+
with:
235+
node-version: ${{ matrix.node }}
236+
architecture: ${{ matrix.settings.architecture }}
237+
cache: pnpm
238+
- uses: actions/setup-python@v6
239+
with:
240+
python-version: ${{ matrix.python }}
241+
architecture: ${{ matrix.settings.architecture }}
242+
- run: pnpm install
243+
- name: Download npm package artifact
244+
uses: actions/download-artifact@v4
245+
with:
246+
name: npm-${{ matrix.settings.npm_dir }}
247+
path: npm/${{ matrix.settings.npm_dir }}
248+
- name: Download entrypoints artifact
249+
uses: actions/download-artifact@v4
250+
with:
251+
name: entrypoints
252+
path: .
253+
- name: Remove old prebuilt binaries
254+
run: rm -rf node_modules/@platformatic/python-node-*
255+
shell: bash
256+
- run: cargo test
257+
- run: pnpm test
258+
259+
test-linux-binding:
260+
name: Test ${{ matrix.settings.target }} - node@${{ matrix.node }} + python@${{ matrix.python }}
261+
if: ${{ inputs.run-tests }}
262+
needs:
263+
- build
264+
strategy:
265+
fail-fast: false
266+
matrix:
267+
settings:
268+
- host: ubuntu-22.04
269+
target: x86_64-unknown-linux-gnu
270+
architecture: x64
271+
npm_dir: linux-x64-gnu
272+
node:
273+
- '20'
274+
- '22'
275+
- '24'
276+
python:
277+
- '3.8'
278+
- '3.9'
279+
- '3.10'
280+
- '3.11'
281+
- '3.12'
282+
- '3.13'
283+
runs-on: ${{ matrix.settings.host }}
284+
steps:
285+
- uses: actions/checkout@v4
286+
- uses: pnpm/action-setup@v4
287+
with:
288+
version: latest
289+
- name: Setup node
290+
uses: actions/setup-node@v4
291+
with:
292+
node-version: ${{ matrix.node }}
293+
architecture: ${{ matrix.settings.architecture }}
294+
cache: pnpm
295+
- uses: actions/setup-python@v6
296+
with:
297+
python-version: ${{ matrix.python }}
298+
architecture: ${{ matrix.settings.architecture }}
299+
- name: Install dependencies
300+
run: pnpm install
301+
- name: Download npm package artifact
302+
uses: actions/download-artifact@v4
303+
with:
304+
name: npm-${{ matrix.settings.npm_dir }}
305+
path: npm/${{ matrix.settings.npm_dir }}
306+
- name: Download entrypoints artifact
307+
uses: actions/download-artifact@v4
308+
with:
309+
name: entrypoints
310+
path: .
311+
- name: Remove old prebuilt binaries
312+
run: rm -rf node_modules/@platformatic/python-node-*
313+
shell: bash
314+
- name: Output docker params
315+
id: docker
316+
run: |
317+
node -e "
318+
if ('${{ matrix.settings.target }}'.startsWith('aarch64')) {
319+
console.log('PLATFORM=linux/arm64')
320+
} else if ('${{ matrix.settings.target }}'.startsWith('armv7')) {
321+
console.log('PLATFORM=linux/arm/v7')
322+
} else {
323+
console.log('PLATFORM=linux/amd64')
324+
}
325+
" >> $GITHUB_OUTPUT
326+
node -e "
327+
if ('${{ matrix.settings.target }}'.endsWith('-musl')) {
328+
console.log('IMAGE=node:${{ matrix.node }}-alpine')
329+
} else {
330+
console.log('IMAGE=node:${{ matrix.node }}-slim')
331+
}
332+
" >> $GITHUB_OUTPUT
333+
echo "PNPM_STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
334+
- name: Test crates
335+
uses: addnab/docker-run-action@v3
336+
with:
337+
image: ${{ steps.docker.outputs.IMAGE }}
338+
options: -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }}
339+
run: |
340+
set -x
341+
342+
# Install apt dependencies
343+
apt-get update -y
344+
apt-get install -y openssh-client curl git build-essential python3 python3-dev
345+
346+
# Install rust toolchain
347+
curl https://sh.rustup.rs -sSf | bash -s -- -y -t ${{ matrix.settings.target }}
348+
. "$HOME/.cargo/env"
349+
350+
cargo test --target ${{ matrix.settings.target }}
351+
- name: Test bindings
352+
uses: addnab/docker-run-action@v3
353+
with:
354+
image: ${{ steps.docker.outputs.IMAGE }}
355+
options: -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }} -e CI=true -e GITHUB_ACTIONS=true
356+
run: |
357+
# Install Python 3.x
358+
apt-get update -y
359+
apt-get install -y python3 python3-dev patchelf
360+
361+
corepack disable
362+
npm i -gf pnpm
363+
node fix-python-soname.js
364+
pnpm install --prefer-offline
365+
pnpm test

0 commit comments

Comments
 (0)