Skip to content

Commit 107e451

Browse files
authored
Improve CI for NAPI-RS (#19983)
This PR updates the CI workflows related to NAPI-RS. So far, we've been using a custom ghcr.io based image, but these run on Node v18. With this PR, I created a new project using `napi new`, with GitHub Actions workflow setup. Then essentially ported the changes from that new project to this project (as minimal as possible). The main goal was to be able to bump NAPI-RS related dependencies _and_ get an insiders release out. The images used in these CI jobs were blockers to get an actual (insiders) release out. ## Test plan 1. CI still passes 2. Added a dry-run on the prepare release workflow to test that we got through the entire workflow without issues
1 parent 615835d commit 107e451

4 files changed

Lines changed: 95 additions & 58 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848

4949
steps:
5050
- uses: actions/checkout@v6
51-
- uses: pnpm/action-setup@v4
51+
- uses: pnpm/action-setup@v6
5252

5353
- name: Use Node.js ${{ env.NODE_VERSION }}
5454
uses: actions/setup-node@v6

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656

5757
steps:
5858
- uses: actions/checkout@v6
59-
- uses: pnpm/action-setup@v4
59+
- uses: pnpm/action-setup@v6
6060

6161
- run: |
6262
git config --global user.name "github-actions[bot]"

.github/workflows/prepare-release.yml

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Prepare Release
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
dry_run:
7+
description: Skip creating the draft GitHub release
8+
required: false
9+
default: true
10+
type: boolean
511
push:
612
tags:
713
- 'v*'
@@ -48,38 +54,30 @@ jobs:
4854
- os: ubuntu-latest
4955
target: x86_64-unknown-linux-gnu
5056
strip: strip
51-
container:
52-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
57+
build-flags: --use-napi-cross
5358
- os: ubuntu-latest
5459
target: aarch64-unknown-linux-gnu
55-
strip: llvm-strip
56-
container:
57-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
60+
strip: aarch64-linux-gnu-strip
61+
build-flags: --use-napi-cross
5862
- os: ubuntu-latest
5963
target: armv7-unknown-linux-gnueabihf
60-
strip: llvm-strip
61-
container:
62-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-zig
64+
strip: arm-linux-gnueabihf-strip
65+
build-flags: --use-napi-cross
6366
- os: ubuntu-latest
6467
target: aarch64-unknown-linux-musl
65-
strip: aarch64-linux-musl-strip
66-
download: true
67-
container:
68-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
68+
strip-zig: true
69+
build-flags: -x
6970
- os: ubuntu-latest
7071
target: x86_64-unknown-linux-musl
7172
strip: strip
72-
download: true
73-
container:
74-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
73+
build-flags: -x
7574

7675
name: Build ${{ matrix.target }} (oxide)
7776
runs-on: ${{ matrix.os }}
78-
container: ${{ matrix.container }}
7977
timeout-minutes: 15
8078
steps:
8179
- uses: actions/checkout@v6
82-
- uses: pnpm/action-setup@v4
80+
- uses: pnpm/action-setup@v6
8381
with:
8482
version: ${{ env.PNPM_VERSION }}
8583

@@ -95,6 +93,12 @@ jobs:
9593
sudo apt-get update
9694
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
9795
96+
- name: Install binutils-aarch64-linux-gnu
97+
if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }}
98+
run: |
99+
sudo apt-get update
100+
sudo apt-get install binutils-aarch64-linux-gnu -y
101+
98102
# Cargo already skips downloading dependencies if they already exist
99103
- name: Cache cargo
100104
uses: actions/cache@v5
@@ -104,6 +108,8 @@ jobs:
104108
~/.cargo/registry/index/
105109
~/.cargo/registry/cache/
106110
~/.cargo/git/db/
111+
~/.napi-rs
112+
.cargo-cache
107113
target/
108114
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
109115

@@ -123,15 +129,18 @@ jobs:
123129
./crates/node/wasi-worker.mjs
124130
key: ${{ runner.os }}-${{ matrix.target }}-oxide-${{ hashFiles('./crates/**/*') }}
125131

126-
- name: Install Node.JS
127-
uses: actions/setup-node@v6
132+
- uses: mlugg/setup-zig@v2
133+
if: ${{ contains(matrix.target, 'musl') }}
128134
with:
129-
node-version: ${{ env.NODE_VERSION }}
135+
version: 0.14.1
130136

131-
- name: Install Rust (Stable)
132-
if: ${{ matrix.download }}
133-
run: |
134-
rustup default stable
137+
- name: Install cargo-zigbuild
138+
uses: taiki-e/install-action@v2
139+
if: ${{ contains(matrix.target, 'musl') }}
140+
env:
141+
GITHUB_TOKEN: ${{ github.token }}
142+
with:
143+
tool: cargo-zigbuild
135144

136145
- name: Setup rust target
137146
run: rustup target add ${{ matrix.target }}
@@ -140,14 +149,26 @@ jobs:
140149
run: pnpm install --ignore-scripts --filter=!./playgrounds/*
141150

142151
- name: Build release
143-
run: pnpm run --filter ${{ env.OXIDE_LOCATION }} build:platform --target=${{ matrix.target }}
152+
run: pnpm run --filter ${{ env.OXIDE_LOCATION }} build:platform --target=${{ matrix.target }} ${{ matrix.build-flags }}
144153
env:
145154
RUST_TARGET: ${{ matrix.target }}
146155
JEMALLOC_SYS_WITH_LG_PAGE: ${{ matrix.page-size }}
147156

148157
- name: Strip debug symbols # https://github.com/rust-lang/rust/issues/46034
149-
if: ${{ matrix.strip }}
150-
run: ${{ matrix.strip }} ${{ env.OXIDE_LOCATION }}/*.node
158+
if: ${{ matrix.strip || matrix.strip-zig }}
159+
env:
160+
STRIP_COMMAND: ${{ matrix.strip }}
161+
STRIP_ZIG: ${{ matrix.strip-zig }}
162+
run: |
163+
if [ "$STRIP_ZIG" = "true" ]; then
164+
for file in ${{ env.OXIDE_LOCATION }}/*.node; do
165+
zig objcopy --strip-all "$file" "$file.stripped"
166+
mv "$file.stripped" "$file"
167+
done
168+
exit 0
169+
fi
170+
171+
eval "$STRIP_COMMAND ${{ env.OXIDE_LOCATION }}/*.node"
151172
152173
- name: Upload artifacts
153174
uses: actions/upload-artifact@v6
@@ -225,7 +246,7 @@ jobs:
225246
run: |
226247
echo "TAG_NAME=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
227248
228-
- uses: pnpm/action-setup@v4
249+
- uses: pnpm/action-setup@v6
229250
with:
230251
version: ${{ env.PNPM_VERSION }}
231252

@@ -322,6 +343,7 @@ jobs:
322343
path: dist/*.tgz
323344

324345
- name: Prepare GitHub Release
346+
if: ${{ !inputs.dry_run }}
325347
uses: softprops/action-gh-release@v2
326348
with:
327349
draft: true

.github/workflows/release.yml

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,30 @@ jobs:
5858
- os: ubuntu-latest
5959
target: x86_64-unknown-linux-gnu
6060
strip: strip
61-
container:
62-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
61+
build-flags: --use-napi-cross
6362
- os: ubuntu-latest
6463
target: aarch64-unknown-linux-gnu
65-
strip: llvm-strip
66-
container:
67-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
64+
strip: aarch64-linux-gnu-strip
65+
build-flags: --use-napi-cross
6866
- os: ubuntu-latest
6967
target: armv7-unknown-linux-gnueabihf
70-
strip: llvm-strip
71-
container:
72-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-zig
68+
strip: arm-linux-gnueabihf-strip
69+
build-flags: --use-napi-cross
7370
- os: ubuntu-latest
7471
target: aarch64-unknown-linux-musl
75-
strip: aarch64-linux-musl-strip
76-
download: true
77-
container:
78-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
72+
strip-zig: true
73+
build-flags: -x
7974
- os: ubuntu-latest
8075
target: x86_64-unknown-linux-musl
8176
strip: strip
82-
download: true
83-
container:
84-
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
77+
build-flags: -x
8578

8679
name: Build ${{ matrix.target }} (oxide)
8780
runs-on: ${{ matrix.os }}
88-
container: ${{ matrix.container }}
8981
timeout-minutes: 15
9082
steps:
9183
- uses: actions/checkout@v6
92-
- uses: pnpm/action-setup@v4
84+
- uses: pnpm/action-setup@v6
9385
with:
9486
version: ${{ env.PNPM_VERSION }}
9587

@@ -105,6 +97,12 @@ jobs:
10597
sudo apt-get update
10698
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
10799
100+
- name: Install binutils-aarch64-linux-gnu
101+
if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }}
102+
run: |
103+
sudo apt-get update
104+
sudo apt-get install binutils-aarch64-linux-gnu -y
105+
108106
# Cargo already skips downloading dependencies if they already exist
109107
- name: Cache cargo
110108
uses: actions/cache@v5
@@ -114,6 +112,8 @@ jobs:
114112
~/.cargo/registry/index/
115113
~/.cargo/registry/cache/
116114
~/.cargo/git/db/
115+
~/.napi-rs
116+
.cargo-cache
117117
target/
118118
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
119119

@@ -133,15 +133,18 @@ jobs:
133133
./crates/node/wasi-worker.mjs
134134
key: ${{ runner.os }}-${{ matrix.target }}-oxide-${{ hashFiles('./crates/**/*') }}
135135

136-
- name: Install Node.JS
137-
uses: actions/setup-node@v6
136+
- uses: mlugg/setup-zig@v2
137+
if: ${{ contains(matrix.target, 'musl') }}
138138
with:
139-
node-version: ${{ env.NODE_VERSION }}
139+
version: 0.14.1
140140

141-
- name: Install Rust (Stable)
142-
if: ${{ matrix.download }}
143-
run: |
144-
rustup default stable
141+
- name: Install cargo-zigbuild
142+
uses: taiki-e/install-action@v2
143+
if: ${{ contains(matrix.target, 'musl') }}
144+
env:
145+
GITHUB_TOKEN: ${{ github.token }}
146+
with:
147+
tool: cargo-zigbuild
145148

146149
- name: Setup rust target
147150
run: rustup target add ${{ matrix.target }}
@@ -150,14 +153,26 @@ jobs:
150153
run: pnpm install --ignore-scripts --filter=!./playgrounds/*
151154

152155
- name: Build release
153-
run: pnpm run --filter ${{ env.OXIDE_LOCATION }} build:platform --target=${{ matrix.target }}
156+
run: pnpm run --filter ${{ env.OXIDE_LOCATION }} build:platform --target=${{ matrix.target }} ${{ matrix.build-flags }}
154157
env:
155158
RUST_TARGET: ${{ matrix.target }}
156159
JEMALLOC_SYS_WITH_LG_PAGE: ${{ matrix.page-size }}
157160

158161
- name: Strip debug symbols # https://github.com/rust-lang/rust/issues/46034
159-
if: ${{ matrix.strip }}
160-
run: ${{ matrix.strip }} ${{ env.OXIDE_LOCATION }}/*.node
162+
if: ${{ matrix.strip || matrix.strip-zig }}
163+
env:
164+
STRIP_COMMAND: ${{ matrix.strip }}
165+
STRIP_ZIG: ${{ matrix.strip-zig }}
166+
run: |
167+
if [ "$STRIP_ZIG" = "true" ]; then
168+
for file in ${{ env.OXIDE_LOCATION }}/*.node; do
169+
zig objcopy --strip-all "$file" "$file.stripped"
170+
mv "$file.stripped" "$file"
171+
done
172+
exit 0
173+
fi
174+
175+
eval "$STRIP_COMMAND ${{ env.OXIDE_LOCATION }}/*.node"
161176
162177
- name: Upload artifacts
163178
uses: actions/upload-artifact@v6
@@ -228,7 +243,7 @@ jobs:
228243
with:
229244
fetch-depth: 20
230245

231-
- uses: pnpm/action-setup@v4
246+
- uses: pnpm/action-setup@v6
232247
with:
233248
version: ${{ env.PNPM_VERSION }}
234249

0 commit comments

Comments
 (0)