-
Notifications
You must be signed in to change notification settings - Fork 3
203 lines (180 loc) · 7.6 KB
/
Copy pathnpm-publish.yml
File metadata and controls
203 lines (180 loc) · 7.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Publish the `docling.rs` npm package (Node.js / Bun native bindings) for a
# chosen release. The package is a native N-API addon, so it can't be a one-line
# `npm publish`: it's built on a matrix of native runners (one per OS/arch),
# each producing a platform `.node`, then a publish job assembles the main
# package plus per-platform `optionalDependencies` (docling.rs-<triple>) via
# napi-rs and publishes them all.
#
# Trigger: manual only (workflow_dispatch). By default it builds the latest
# master (the version in the workspace Cargo.toml); optionally pass a release
# tag to build that instead. Either way the workflow checks out the chosen ref
# and publishes, so npm releases stay decoupled from the crates.io release on
# every master push. Run it from the Actions tab (or
# `gh workflow run npm-publish.yml`, optionally `-f tag=v0.7.0`).
#
# Requires one repository secret: NPM_TOKEN — an npm automation token with
# publish rights to `docling.rs` and the `docling.rs-*` platform packages.
name: npm publish
on:
workflow_dispatch:
inputs:
tag:
description: "Release tag to build (e.g. v0.7.0). Blank = latest master."
required: false
default: ""
version:
description: "Override the npm version (e.g. 0.7.0). Blank = tag, or workspace version on master."
required: false
default: ""
concurrency:
group: npm-publish-${{ inputs.tag || github.ref }}
cancel-in-progress: false
defaults:
run:
working-directory: crates/docling-node
jobs:
build:
name: build ${{ matrix.target }}
runs-on: ${{ matrix.host }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
host: ubuntu-22.04
# GitHub-hosted ARM64 Linux runner (native — avoids cross-compiling the
# ONNX/ort build). Requires the arm64 runner image to be available.
- target: aarch64-unknown-linux-gnu
host: ubuntu-24.04-arm
# macOS (darwin) prebuilds are omitted: GitHub-hosted macOS runners are
# blocked in this environment, and darwin can't be cross-compiled on
# Linux (needs the Apple SDK). macOS users build from source. To re-add
# when macOS runners are available, add the darwin targets back here AND
# to `napi.triples.additional` in package.json:
# - { target: aarch64-apple-darwin, host: macos-14 }
# - { target: x86_64-apple-darwin, host: macos-14 } # cross via --target
- target: x86_64-pc-windows-msvc
host: windows-latest
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.ref }}
# rustup is preinstalled on GitHub-hosted runners (Linux + Windows); use it
# directly — the docling-project org allowlists only GitHub-owned / vetted
# actions, not marketplace toolchain actions.
- name: Install Rust (stable)
shell: bash
run: |
rustup toolchain install stable --profile minimal
rustup default stable
rustup target add ${{ matrix.target }}
# One workspace, key the cache per target so the 5 jobs don't collide.
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
target
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-${{ matrix.target }}-
- uses: actions/setup-node@v6
with:
node-version: 20
- name: Install napi CLI
run: npm install
# Native addon + the JS loader / d.ts. `--strip` keeps the (ONNX-linked)
# binary as small as possible; strip isn't available under MSVC, so the
# Windows build omits it.
- name: Build (unix)
if: runner.os != 'Windows'
run: npx napi build --platform --release --strip --target ${{ matrix.target }} --js native.js --dts native.d.ts
- name: Build (windows)
if: runner.os == 'Windows'
run: npx napi build --platform --release --target ${{ matrix.target }} --js native.js --dts native.d.ts
- name: Upload prebuilt binary
uses: actions/upload-artifact@v7
with:
name: bindings-${{ matrix.target }}
path: crates/docling-node/docling-rs.*.node
if-no-files-found: error
# The JS loader + types are platform-agnostic; upload them once (from the
# linux-x64 build) for the publish job to include in the main package.
- name: Upload JS binding
if: matrix.target == 'x86_64-unknown-linux-gnu'
uses: actions/upload-artifact@v7
with:
name: js-binding
path: |
crates/docling-node/native.js
crates/docling-node/native.d.ts
if-no-files-found: error
publish:
name: publish to npm
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.ref }}
- uses: actions/setup-node@v6
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
- name: Install napi CLI
run: npm install
# Prebuilt binaries → artifacts/<name>/docling-rs.<triple>.node
- name: Download prebuilt binaries
uses: actions/download-artifact@v8
with:
pattern: bindings-*
path: crates/docling-node/artifacts
# The JS loader + types → the package root.
- name: Download JS binding
uses: actions/download-artifact@v8
with:
name: js-binding
path: crates/docling-node
# Version = the explicit override, else the selected tag (sans leading `v`),
# else the workspace version from the root Cargo.toml (latest-master run).
- name: Resolve version
id: ver
run: |
v="${{ inputs.version }}"
if [ -z "$v" ]; then
if [ -n "${{ inputs.tag }}" ]; then
v="${{ inputs.tag }}"; v="${v#v}"
else
v="$(grep -m1 '^version = ' ../../Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')"
fi
fi
echo "version=$v" >> "$GITHUB_OUTPUT"
echo "Publishing docling.rs@$v (ref: ${{ inputs.tag || github.ref }})"
# Skip cleanly if this version is already on npm (idempotent re-runs).
- name: Check if already published
id: check
run: |
v="${{ steps.ver.outputs.version }}"
if npm view "docling.rs@$v" version >/dev/null 2>&1; then
echo "published=true" >> "$GITHUB_OUTPUT"
echo "docling.rs@$v is already on npm — skipping."
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Set package version
if: steps.check.outputs.published == 'false'
run: npm version "${{ steps.ver.outputs.version }}" --no-git-tag-version --allow-same-version
# Create the per-platform package dirs and move each prebuilt .node into
# its dir. `npm publish` then runs `prepublishOnly` (napi prepublish), which
# publishes the docling.rs-<triple> packages and wires them into the main
# package's optionalDependencies before the main package is published.
- name: Assemble platform packages
if: steps.check.outputs.published == 'false'
run: |
npx napi create-npm-dir -t .
npx napi artifacts --dir artifacts
- name: Publish
if: steps.check.outputs.published == 'false'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}