-
Notifications
You must be signed in to change notification settings - Fork 0
381 lines (326 loc) · 12 KB
/
Copy pathpublish-cli.yml
File metadata and controls
381 lines (326 loc) · 12 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
name: Publish
run-name: "${{ format('release {0}', inputs.version || inputs.bump) }}"
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump type"
required: true
type: choice
default: "patch (x.x.X)"
options:
- "patch (x.x.X)"
- "minor (x.X.0)"
- "major (X.0.0)"
version:
description: "Override version (e.g., 2.0.0-beta.1). Takes precedence over bump."
required: false
type: string
permissions:
contents: write
env:
DEBUG: napi:*
APP_NAME: tokscale-core
MACOSX_DEPLOYMENT_TARGET: "10.13"
jobs:
bump-versions:
name: Bump versions
runs-on: ubuntu-latest
outputs:
version: ${{ steps.bump.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Calculate version
id: bump
run: |
# Read current version
CURRENT_VERSION=$(jq -r '.version' packages/core/package.json)
echo "📦 Current version: $CURRENT_VERSION"
# Calculate new version
if [ -n "${{ inputs.version }}" ]; then
NEW_VERSION="${{ inputs.version }}"
echo "📌 Using override version: $NEW_VERSION"
else
# Strip any prerelease suffix for calculation
BASE="${CURRENT_VERSION%%-*}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE"
case "${{ inputs.bump }}" in
"major (X.0.0)")
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
"minor (x.X.0)")
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
;;
*)
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
;;
esac
echo "🎯 Bump type: ${{ inputs.bump }}"
fi
echo "🚀 New version: $NEW_VERSION"
# Update packages/core/package.json
jq --arg v "$NEW_VERSION" '.version = $v' packages/core/package.json > tmp.json && mv tmp.json packages/core/package.json
echo "✅ Updated packages/core/package.json"
# Update packages/cli/package.json (version + @tokscale/core dependency)
jq --arg v "$NEW_VERSION" '.version = $v | .dependencies["@tokscale/core"] = $v' packages/cli/package.json > tmp.json && mv tmp.json packages/cli/package.json
echo "✅ Updated packages/cli/package.json"
# Update packages/tokscale/package.json (version + @tokscale/cli dependency)
jq --arg v "$NEW_VERSION" '.version = $v | .dependencies["@tokscale/cli"] = $v' packages/tokscale/package.json > tmp.json && mv tmp.json packages/tokscale/package.json
echo "✅ Updated packages/tokscale/package.json"
# Verify all versions are updated
echo ""
echo "📋 Verification:"
echo " @tokscale/core: $(jq -r '.version' packages/core/package.json)"
echo " @tokscale/cli: $(jq -r '.version' packages/cli/package.json)"
echo " tokscale: $(jq -r '.version' packages/tokscale/package.json)"
echo " cli -> core dep: $(jq -r '.dependencies["@tokscale/core"]' packages/cli/package.json)"
echo " tokscale -> cli: $(jq -r '.dependencies["@tokscale/cli"]' packages/tokscale/package.json)"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "📝 Version bump prepared (will commit after successful publish)"
- name: Upload bumped package.json files
uses: actions/upload-artifact@v4
with:
name: bumped-packages
path: |
packages/core/package.json
packages/cli/package.json
packages/tokscale/package.json
retention-days: 1
build:
name: Build - ${{ matrix.settings.target }}
needs: bump-versions
runs-on: ${{ matrix.settings.host }}
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
build: |
cd packages/core
bun run build:platform --target x86_64-apple-darwin
strip -x *.node
- host: macos-latest
target: aarch64-apple-darwin
build: |
cd packages/core
bun run build:platform --target aarch64-apple-darwin
strip -x *.node
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
build: |
cd packages/core
bun run build:platform --target x86_64-unknown-linux-gnu --use-napi-cross
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
build: |
cd packages/core
bun run build:platform --target x86_64-unknown-linux-musl -x
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
build: |
cd packages/core
bun run build:platform --target aarch64-unknown-linux-gnu --use-napi-cross
- host: ubuntu-latest
target: aarch64-unknown-linux-musl
build: |
cd packages/core
bun run build:platform --target aarch64-unknown-linux-musl -x
- host: windows-latest
target: x86_64-pc-windows-msvc
build: |
cd packages/core
bun run build:platform
- host: windows-latest
target: aarch64-pc-windows-msvc
build: |
cd packages/core
bun run build:platform --target aarch64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- name: Download bumped package.json files
uses: actions/download-artifact@v4
with:
name: bumped-packages
path: packages/
- name: Restore package.json structure
shell: bash
run: |
mv packages/core/package.json packages/core/package.json 2>/dev/null || true
mv packages/cli/package.json packages/cli/package.json 2>/dev/null || true
mv packages/tokscale/package.json packages/tokscale/package.json 2>/dev/null || true
echo "📦 Using version: $(jq -r '.version' packages/core/package.json)"
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.38
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.settings.target }}
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.napi-rs
.cargo-cache
packages/core/target/
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}-${{ hashFiles('packages/core/Cargo.lock') }}
- uses: mlugg/setup-zig@v2
if: ${{ contains(matrix.settings.target, 'musl') }}
with:
version: 0.13.0
- name: Install cargo-zigbuild
uses: taiki-e/install-action@v2
if: ${{ contains(matrix.settings.target, 'musl') }}
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tool: cargo-zigbuild
- name: Install napi-rs CLI
run: bun add -g @napi-rs/cli
- name: Build
run: ${{ matrix.settings.build }}
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: packages/core/*.node
if-no-files-found: error
# Upload generated JS files from first build only (ubuntu x86_64-gnu)
- name: Upload generated NAPI files
if: matrix.settings.target == 'x86_64-unknown-linux-gnu'
uses: actions/upload-artifact@v4
with:
name: napi-generated
path: |
packages/core/index.js
packages/core/index.d.ts
if-no-files-found: error
publish-core:
name: Publish @tokscale/core
needs: [bump-versions, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download bumped package.json files
uses: actions/download-artifact@v4
with:
name: bumped-packages
path: packages/
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.38
- name: Install napi-rs CLI
run: bun add -g @napi-rs/cli
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: packages/core/artifacts
pattern: bindings-*
- name: Move artifacts
working-directory: packages/core
run: |
for dir in artifacts/bindings-*/; do
cp "$dir"*.node . 2>/dev/null || true
done
ls -la *.node
- name: Download generated NAPI files
uses: actions/download-artifact@v4
with:
name: napi-generated
path: packages/core/
- name: Publish @tokscale/core
working-directory: packages/core
run: |
echo "📦 Publishing version: $(jq -r '.version' package.json)"
bun publish --access public
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-cli:
name: Publish @tokscale/cli
needs: [bump-versions, publish-core]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download bumped package.json files
uses: actions/download-artifact@v4
with:
name: bumped-packages
path: packages/
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.38
- name: Install dependencies
working-directory: packages/cli
run: bun install
- name: Build CLI
working-directory: packages/cli
run: bun run build
- name: Publish @tokscale/cli
working-directory: packages/cli
run: |
echo "📦 Publishing version: $(jq -r '.version' package.json)"
bun publish --access public
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-alias:
name: Publish tokscale (wrapper)
needs: [bump-versions, publish-cli]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download bumped package.json files
uses: actions/download-artifact@v4
with:
name: bumped-packages
path: packages/
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.38
- name: Publish tokscale
working-directory: packages/tokscale
run: |
echo "📦 Publishing version: $(jq -r '.version' package.json)"
bun publish --access public
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
finalize:
name: Commit version bump
needs: [bump-versions, publish-alias]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: true
- name: Download bumped package.json files
uses: actions/download-artifact@v4
with:
name: bumped-packages
path: packages/
- name: Download generated NAPI files
uses: actions/download-artifact@v4
with:
name: napi-generated
path: packages/core/
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit and push version bump
run: |
NEW_VERSION="${{ needs.bump-versions.outputs.version }}"
echo "📦 Committing version bump to $NEW_VERSION"
git add packages/core/package.json packages/core/index.js packages/core/index.d.ts packages/cli/package.json packages/tokscale/package.json
git commit -m "chore: bump version to $NEW_VERSION"
git push
echo "✅ Successfully published and committed version $NEW_VERSION"