Skip to content

Commit 40eb8a1

Browse files
committed
feat: build native packages during release
1 parent b7ef170 commit 40eb8a1

5 files changed

Lines changed: 117 additions & 158 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches: ['**']
66
tags-ignore: ['**']
77
pull_request:
8-
workflow_call:
98

109
concurrency:
1110
group: ${{ github.workflow }}-${{ github.ref }}
@@ -33,82 +32,3 @@ jobs:
3332
- run: pnpm --dir fixtures/next exec next build --turbopack
3433
- run: pnpm --dir fixtures/next exec next build --webpack
3534
- run: npm pack --dry-run --ignore-scripts
36-
37-
native:
38-
strategy:
39-
fail-fast: false
40-
matrix:
41-
include:
42-
- os: macos-15
43-
target: aarch64-apple-darwin
44-
platform: darwin-arm64
45-
flags: ''
46-
- os: macos-15-intel
47-
target: x86_64-apple-darwin
48-
platform: darwin-x64
49-
flags: ''
50-
- os: ubuntu-24.04-arm
51-
target: aarch64-unknown-linux-gnu
52-
platform: linux-arm64-gnu
53-
flags: --use-napi-cross
54-
- os: ubuntu-24.04
55-
target: x86_64-unknown-linux-gnu
56-
platform: linux-x64-gnu
57-
flags: --use-napi-cross
58-
- os: ubuntu-24.04-arm
59-
target: aarch64-unknown-linux-musl
60-
platform: linux-arm64-musl
61-
flags: -x
62-
- os: ubuntu-24.04
63-
target: x86_64-unknown-linux-musl
64-
platform: linux-x64-musl
65-
flags: -x
66-
- os: windows-2025
67-
target: x86_64-pc-windows-msvc
68-
platform: win32-x64-msvc
69-
flags: ''
70-
runs-on: ${{ matrix.os }}
71-
steps:
72-
- uses: actions/checkout@v7
73-
- uses: pnpm/action-setup@v4
74-
with:
75-
version: 11.20.0
76-
- uses: actions/setup-node@v7
77-
with:
78-
node-version: 24
79-
cache: pnpm
80-
- uses: dtolnay/rust-toolchain@stable
81-
with:
82-
toolchain: 1.97.1
83-
targets: ${{ matrix.target }}
84-
- uses: mlugg/setup-zig@v2
85-
if: contains(matrix.target, 'musl')
86-
with:
87-
version: 0.14.1
88-
- uses: taiki-e/install-action@v2
89-
if: contains(matrix.target, 'musl')
90-
with:
91-
tool: cargo-zigbuild
92-
- run: pnpm install --frozen-lockfile
93-
- name: Build native binding
94-
shell: bash
95-
run: pnpm exec napi build --release --platform --no-js --dts native.d.ts --target ${{ matrix.target }} ${{ matrix.flags }}
96-
- name: Load test native binding
97-
shell: bash
98-
run: |
99-
if [[ '${{ matrix.platform }}' == *-musl ]]; then
100-
docker run --rm -v "$PWD:/work" -w /work node:20-alpine node -e "require('./index.${{ matrix.platform }}.node')"
101-
else
102-
node -e "require('./index.${{ matrix.platform }}.node')"
103-
fi
104-
- name: Stage native package
105-
shell: bash
106-
run: |
107-
mkdir -p release/${{ matrix.platform }}
108-
cp index.${{ matrix.platform }}.node release/${{ matrix.platform }}/
109-
cp npm/${{ matrix.platform }}/package.json npm/${{ matrix.platform }}/README.md release/${{ matrix.platform }}/
110-
- uses: actions/upload-artifact@v7
111-
with:
112-
name: ${{ matrix.platform }}
113-
path: release/${{ matrix.platform }}
114-
if-no-files-found: error

.github/workflows/release.yml

Lines changed: 112 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,112 @@ on:
44
push:
55
tags: ['v*']
66

7+
concurrency:
8+
group: release
9+
cancel-in-progress: false
10+
711
jobs:
12+
verify-publish-credentials:
13+
runs-on: ubuntu-24.04
14+
timeout-minutes: 5
15+
steps:
16+
- name: Verify npm publish token
17+
run: |
18+
if [ -z "$NODE_AUTH_TOKEN" ]; then
19+
echo "NPM_TOKEN secret is required before building release binaries." >&2
20+
exit 1
21+
fi
22+
env:
23+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
24+
25+
build-native:
26+
needs: verify-publish-credentials
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
include:
31+
- os: macos-15
32+
target: aarch64-apple-darwin
33+
platform: darwin-arm64
34+
flags: ''
35+
- os: macos-15-intel
36+
target: x86_64-apple-darwin
37+
platform: darwin-x64
38+
flags: ''
39+
- os: ubuntu-24.04-arm
40+
target: aarch64-unknown-linux-gnu
41+
platform: linux-arm64-gnu
42+
flags: --use-napi-cross
43+
- os: ubuntu-24.04
44+
target: x86_64-unknown-linux-gnu
45+
platform: linux-x64-gnu
46+
flags: --use-napi-cross
47+
- os: ubuntu-24.04-arm
48+
target: aarch64-unknown-linux-musl
49+
platform: linux-arm64-musl
50+
flags: -x
51+
- os: ubuntu-24.04
52+
target: x86_64-unknown-linux-musl
53+
platform: linux-x64-musl
54+
flags: -x
55+
- os: windows-2025
56+
target: x86_64-pc-windows-msvc
57+
platform: win32-x64-msvc
58+
flags: ''
59+
runs-on: ${{ matrix.os }}
60+
timeout-minutes: 30
61+
steps:
62+
- uses: actions/checkout@v7
63+
- uses: pnpm/action-setup@v4
64+
with:
65+
version: 11.20.0
66+
- uses: actions/setup-node@v7
67+
with:
68+
node-version: 24
69+
cache: pnpm
70+
- uses: dtolnay/rust-toolchain@stable
71+
with:
72+
toolchain: 1.97.1
73+
targets: ${{ matrix.target }}
74+
- uses: mlugg/setup-zig@v2
75+
if: contains(matrix.target, 'musl')
76+
with:
77+
version: 0.14.1
78+
- uses: taiki-e/install-action@v2
79+
if: contains(matrix.target, 'musl')
80+
with:
81+
tool: cargo-zigbuild
82+
- run: pnpm install --frozen-lockfile
83+
- name: Build native binding
84+
shell: bash
85+
run: pnpm exec napi build --release --platform --no-js --dts native.d.ts --target ${{ matrix.target }} ${{ matrix.flags }}
86+
- name: Load test native binding
87+
shell: bash
88+
run: |
89+
if [[ '${{ matrix.platform }}' == *-musl ]]; then
90+
docker run --rm -v "$PWD:/work" -w /work node:20-alpine node -e "require('./index.${{ matrix.platform }}.node')"
91+
else
92+
node -e "require('./index.${{ matrix.platform }}.node')"
93+
fi
94+
- name: Stage native package
95+
shell: bash
96+
run: |
97+
mkdir -p release/${{ matrix.platform }}
98+
cp index.${{ matrix.platform }}.node release/${{ matrix.platform }}/
99+
cp npm/${{ matrix.platform }}/package.json npm/${{ matrix.platform }}/README.md release/${{ matrix.platform }}/
100+
- uses: actions/upload-artifact@v7
101+
with:
102+
name: ${{ matrix.platform }}
103+
path: release/${{ matrix.platform }}
104+
if-no-files-found: error
105+
retention-days: 7
106+
8107
publish:
108+
needs:
109+
- verify-publish-credentials
110+
- build-native
9111
runs-on: ubuntu-24.04
112+
timeout-minutes: 20
10113
permissions:
11114
contents: read
12115
id-token: write
@@ -24,28 +127,28 @@ jobs:
24127
with:
25128
toolchain: 1.97.1
26129
- run: pnpm install --frozen-lockfile
27-
- run: pnpm run build
130+
- name: Verify release source
131+
run: pnpm run check
28132
- uses: actions/download-artifact@v8
29133
with:
30134
path: artifacts
135+
- run: pnpm exec napi artifacts --output-dir artifacts --npm-dir npm
31136
- name: Verify release version and artifacts
32137
shell: bash
33138
run: |
34139
test "v$(node -p "require('./package.json').version")" = "$GITHUB_REF_NAME"
35-
node scripts/check-artifacts.mjs artifacts
140+
node scripts/check-artifacts.mjs npm
141+
pnpm exec napi prepublish -t npm --no-gh-release --dry-run
36142
- name: Dry-run every package
37143
shell: bash
38144
run: |
39145
for target in darwin-arm64 darwin-x64 linux-arm64-gnu linux-arm64-musl linux-x64-gnu linux-x64-musl win32-x64-msvc; do
40-
npm pack --dry-run --ignore-scripts "artifacts/$target"
146+
npm pack --dry-run --ignore-scripts "npm/$target"
41147
done
42148
npm pack --dry-run --ignore-scripts
43149
- name: Publish native packages, then root
44-
shell: bash
45-
run: |
46-
for target in darwin-arm64 darwin-x64 linux-arm64-gnu linux-arm64-musl linux-x64-gnu linux-x64-musl win32-x64-msvc; do
47-
npm publish "artifacts/$target" --access public --provenance
48-
done
49-
npm publish --access public --provenance
150+
run: npm publish --access public --provenance
50151
env:
51152
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
153+
NPM_CONFIG_ACCESS: public
154+
NPM_CONFIG_PROVENANCE: true

package.json

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@
2828
}
2929
},
3030
"scripts": {
31+
"prepare": "simple-git-hooks",
32+
"precommit": "lint-staged && cargo fmt --check",
3133
"build:native": "napi build --platform --output-dir . --no-js --dts native.d.ts",
3234
"build:ts": "tsc -p tsconfig.json",
3335
"build": "pnpm run build:native && pnpm run build:ts",
3436
"format": "oxfmt . && cargo fmt",
3537
"format:check": "oxfmt --check . && cargo fmt --check",
3638
"lint": "oxlint .",
3739
"lint:fix": "oxlint --fix .",
38-
"prepare": "simple-git-hooks",
39-
"precommit": "lint-staged && cargo fmt --check",
40-
"release": "verso",
40+
"prepublishOnly": "napi prepublish -t npm --no-gh-release",
4141
"test": "pnpm run build && vitest run src/__tests__",
4242
"test:rust": "cargo test",
4343
"typecheck": "tsc -p tsconfig.json --noEmit",
44-
"check": "pnpm run format:check && pnpm run lint && cargo clippy --all-targets -- -D warnings && cargo test && pnpm run typecheck && pnpm run test"
44+
"check": "pnpm run format:check && pnpm run lint && cargo clippy --all-targets -- -D warnings && cargo test && pnpm run typecheck && pnpm run test",
45+
"release": "verso"
4546
},
4647
"dependencies": {
4748
"shiki": "4.4.2"
@@ -80,15 +81,6 @@
8081
"optional": true
8182
}
8283
},
83-
"optionalDependencies": {
84-
"@amamo/mdx-darwin-arm64": "0.1.0",
85-
"@amamo/mdx-darwin-x64": "0.1.0",
86-
"@amamo/mdx-linux-arm64-gnu": "0.1.0",
87-
"@amamo/mdx-linux-arm64-musl": "0.1.0",
88-
"@amamo/mdx-linux-x64-gnu": "0.1.0",
89-
"@amamo/mdx-linux-x64-musl": "0.1.0",
90-
"@amamo/mdx-win32-x64-msvc": "0.1.0"
91-
},
9284
"simple-git-hooks": {
9385
"pre-commit": "pnpm run precommit"
9486
},

scripts/check-artifacts.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { createRequire } from 'node:module'
22
import { readdir, readFile } from 'node:fs/promises'
33
import path from 'node:path'
44
import process from 'node:process'
5-
import { fileURLToPath } from 'node:url'
65

7-
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
8-
const rootPackage = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'))
96
const targets = [
107
'darwin-arm64',
118
'darwin-x64',
@@ -44,7 +41,6 @@ if (process.argv[2] === '--local') {
4441
const bindings = files.filter((file) => file.endsWith('.node'))
4542
if (
4643
pkg.name !== `@amamo/mdx-${target}` ||
47-
pkg.version !== rootPackage.version ||
4844
pkg.main !== expectedBinding ||
4945
bindings.length !== 1 ||
5046
bindings[0] !== expectedBinding

src/__tests__/package.test.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)