Repository navigation
458 lines (411 loc) · 16.3 KB
/
Copy pathplugin-cli-release.yml
File metadata and controls
458 lines (411 loc) · 16.3 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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
name: Plugin CLI Release
on:
push:
tags:
- "plugin-cli-v*"
workflow_dispatch:
inputs:
version:
description: "Plugin CLI version to publish, for example 0.1.6"
required: true
default: "0.1.6"
npm-tag:
description: "npm distribution tag"
required: true
default: "latest"
type: choice
options:
- latest
- next
permissions:
attestations: write
contents: write
id-token: write
concurrency:
group: plugin-cli-release
cancel-in-progress: false
jobs:
prepare:
name: Validate plugin CLI release
runs-on: ubuntu-24.04
outputs:
tag: ${{ steps.release.outputs.tag }}
version: ${{ steps.release.outputs.version }}
npm-tag: ${{ steps.release.outputs.npm-tag }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version: 22.23.3
registry-url: https://registry.npmjs.org
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-go@v6
with:
go-version: "1.22.x"
cache: false
- name: Validate release branch and versions
id: release
env:
INPUT_VERSION: ${{ inputs.version }}
INPUT_NPM_TAG: ${{ inputs.npm-tag }}
run: |
node <<'NODE'
const fs = require("fs");
let version;
let tag;
let npmTag;
if (process.env.GITHUB_EVENT_NAME === "push") {
tag = process.env.GITHUB_REF_NAME;
const match = /^plugin-cli-v(.+)$/.exec(tag);
if (!match) throw new Error(`Unexpected plugin CLI tag: ${tag}`);
version = match[1];
npmTag = version.includes("-") ? "next" : "latest";
} else {
if (process.env.GITHUB_REF !== "refs/heads/main") {
throw new Error(`Manual plugin CLI releases must run from main, received ${process.env.GITHUB_REF}.`);
}
version = process.env.INPUT_VERSION.trim();
tag = `plugin-cli-v${version}`;
npmTag = process.env.INPUT_NPM_TAG;
}
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {
throw new Error(`Invalid semantic version: ${version}`);
}
if (version.includes("-") && npmTag === "latest") {
throw new Error(`Prerelease ${version} cannot use the npm latest tag.`);
}
const packagePaths = [
"packages/plugin-cli/package.json",
"packages/plugin-cli-darwin-arm64/package.json",
"packages/plugin-cli-darwin-x64/package.json",
"packages/plugin-cli-linux-arm64-gnu/package.json",
"packages/plugin-cli-linux-x64-gnu/package.json",
"packages/plugin-cli-win32-arm64/package.json",
"packages/plugin-cli-win32-x64/package.json",
];
for (const path of packagePaths) {
const pkg = JSON.parse(fs.readFileSync(path, "utf8"));
if (pkg.version !== version) {
throw new Error(`${path} has version ${pkg.version}; expected ${version}.`);
}
}
const cliCargo = fs.readFileSync("plugins/sdk/cli/Cargo.toml", "utf8");
const cliVersion = cliCargo.match(/^version\s*=\s*"([^"]+)"/m)?.[1];
if (cliVersion !== version) {
throw new Error(`plugins/sdk/cli/Cargo.toml has version ${cliVersion}; expected ${version}.`);
}
const launcher = JSON.parse(fs.readFileSync(packagePaths[0], "utf8"));
for (const [dependency, dependencyVersion] of Object.entries(launcher.optionalDependencies ?? {})) {
if (dependencyVersion !== version) {
throw new Error(`${dependency} is pinned to ${dependencyVersion}; expected ${version}.`);
}
}
fs.appendFileSync(process.env.GITHUB_OUTPUT, `version=${version}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `tag=${tag}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `npm-tag=${npmTag}\n`);
NODE
- name: Check npm token
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [ -z "${NODE_AUTH_TOKEN}" ]; then
echo "::error::NPM_TOKEN secret is required to publish @dbx-app/plugin-cli."
exit 1
fi
- name: Install nextest
uses: taiki-e/install-action@a3324fb0eb94b8230ec968c3389c1b7929fc2f3b
with:
tool: cargo-nextest@0.9.137
- name: Test Rust CLI
run: cargo nextest run --locked --manifest-path plugins/sdk/cli/Cargo.toml --no-fail-fast
- name: Test Rust CLI docs
run: cargo test --doc --locked --manifest-path plugins/sdk/cli/Cargo.toml
- name: Prepare and test plugin development runtime
run: |
npm ci --prefix plugins/sdk/dev-host
npm test --prefix plugins/sdk/dev-host
- name: Test npm launcher
run: npm --prefix packages/plugin-cli test
- name: Verify packed npm installation
env:
DBX_PLUGIN_CLI_VERIFY_NATIVE: "1"
run: node scripts/verify-plugin-cli-package.mjs
- name: Create immutable source tag
if: github.event_name == 'workflow_dispatch'
env:
TAG: ${{ steps.release.outputs.tag }}
run: |
git fetch origin --tags --force
if git rev-parse "refs/tags/${TAG}" >/dev/null 2>&1; then
TAG_SHA="$(git rev-list -n 1 "refs/tags/${TAG}")"
HEAD_SHA="$(git rev-parse HEAD)"
if [ "${TAG_SHA}" != "${HEAD_SHA}" ]; then
echo "::error::${TAG} already points to ${TAG_SHA}, not ${HEAD_SHA}."
exit 1
fi
echo "${TAG} already points to this commit."
else
git tag "${TAG}" HEAD
git push origin "refs/tags/${TAG}:refs/tags/${TAG}"
fi
refresh-lockfile:
name: Refresh pnpm lockfile
needs: prepare
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
ref: main
- name: Sync plugin-cli lockfile specifiers
id: sync
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: |
node <<'NODE'
const fs = require("fs");
const version = process.env.VERSION;
const manifest = JSON.parse(fs.readFileSync("packages/plugin-cli/package.json", "utf8"));
if (manifest.version !== version) {
console.log(`main pins plugin-cli ${manifest.version}; release ${version} does not need a lockfile sync.`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, "changed=false\n");
process.exit(0);
}
const expected = Object.keys(manifest.optionalDependencies ?? {});
const lockPath = "pnpm-lock.yaml";
const lines = fs.readFileSync(lockPath, "utf8").split("\n");
let inImporter = false;
let specifiers = 0;
let changed = 0;
for (let i = 0; i < lines.length; i += 1) {
const line = lines[i];
if (/^ {2}\S/.test(line)) {
inImporter = line === " packages/plugin-cli:";
continue;
}
if (!inImporter) continue;
const match = line.match(/^( {8}specifier: )(.+)$/);
if (!match) continue;
specifiers += 1;
if (match[2] !== version) {
lines[i] = match[1] + version;
changed += 1;
}
}
if (specifiers !== expected.length) {
throw new Error(`pnpm-lock.yaml has ${specifiers} plugin-cli specifiers; manifest declares ${expected.length}.`);
}
fs.appendFileSync(process.env.GITHUB_OUTPUT, `changed=${changed > 0}\n`);
if (changed > 0) {
fs.writeFileSync(lockPath, lines.join("\n"));
console.log(`Updated ${changed} plugin-cli specifiers to ${version}.`);
} else {
console.log("plugin-cli lockfile specifiers already match; nothing to do.");
}
NODE
- name: Commit refreshed lockfile
if: steps.sync.outputs.changed == 'true'
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pnpm-lock.yaml
git commit -m "chore(plugin-cli): refresh pnpm lockfile for ${VERSION}"
for attempt in 1 2 3; do
if git push origin HEAD:main; then
echo "::notice::Refreshed pnpm-lock.yaml plugin-cli specifiers to ${VERSION}."
exit 0
fi
echo "Push attempt ${attempt} rejected; rebasing onto origin/main."
git pull --rebase origin main
done
echo "::error::Unable to push the lockfile refresh after 3 attempts."
exit 1
publish-platforms:
name: Publish ${{ matrix.package-name }}
needs: prepare
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- runner: macos-15
target: aarch64-apple-darwin
package-dir: plugin-cli-darwin-arm64
package-name: "@dbx-app/plugin-cli-darwin-arm64"
binary: dbx-plugin
- runner: macos-15-intel
target: x86_64-apple-darwin
package-dir: plugin-cli-darwin-x64
package-name: "@dbx-app/plugin-cli-darwin-x64"
binary: dbx-plugin
- runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
package-dir: plugin-cli-linux-arm64-gnu
package-name: "@dbx-app/plugin-cli-linux-arm64-gnu"
binary: dbx-plugin
- runner: ubuntu-24.04
target: x86_64-unknown-linux-gnu
package-dir: plugin-cli-linux-x64-gnu
package-name: "@dbx-app/plugin-cli-linux-x64-gnu"
binary: dbx-plugin
- runner: windows-11-arm
target: aarch64-pc-windows-msvc
package-dir: plugin-cli-win32-arm64
package-name: "@dbx-app/plugin-cli-win32-arm64"
binary: dbx-plugin.exe
- runner: windows-2025
target: x86_64-pc-windows-msvc
package-dir: plugin-cli-win32-x64
package-name: "@dbx-app/plugin-cli-win32-x64"
binary: dbx-plugin.exe
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare.outputs.tag }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: actions/setup-python@v6
if: runner.os == 'Linux'
with:
python-version: "3.x"
- name: Install Linux compatibility builder
if: runner.os == 'Linux'
run: pip install ziglang==0.14.0 cargo-zigbuild==0.23.0
- name: Build precompiled CLI
shell: bash
env:
CARGO_TARGET_DIR: ${{ github.workspace }}/target/plugin-cli
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
cargo zigbuild --locked --release --manifest-path plugins/sdk/cli/Cargo.toml --target "${{ matrix.target }}.2.31"
else
cargo build --locked --release --manifest-path plugins/sdk/cli/Cargo.toml --target "${{ matrix.target }}"
fi
- name: Stage platform package
shell: bash
run: |
mkdir -p "packages/${{ matrix.package-dir }}/bin"
cp "target/plugin-cli/${{ matrix.target }}/release/${{ matrix.binary }}" "packages/${{ matrix.package-dir }}/bin/${{ matrix.binary }}"
if [[ "${{ runner.os }}" != "Windows" ]]; then
chmod +x "packages/${{ matrix.package-dir }}/bin/${{ matrix.binary }}"
fi
- uses: actions/setup-node@v6
with:
node-version: 22.23.3
registry-url: https://registry.npmjs.org
- name: Publish platform package
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ needs.prepare.outputs.version }}
NPM_TAG: ${{ needs.prepare.outputs.npm-tag }}
run: |
if npm view "${{ matrix.package-name }}@${VERSION}" version >/dev/null 2>&1; then
echo "${{ matrix.package-name }}@${VERSION} already exists; refreshing ${NPM_TAG}."
npm dist-tag add "${{ matrix.package-name }}@${VERSION}" "${NPM_TAG}"
else
npm publish "./packages/${{ matrix.package-dir }}" --access public --provenance --tag "${NPM_TAG}"
fi
publish-launcher:
name: Publish @dbx-app/plugin-cli
needs: [prepare, publish-platforms]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare.outputs.tag }}
- uses: actions/setup-node@v6
with:
node-version: 22.23.3
registry-url: https://registry.npmjs.org
- name: Prepare development runtime build dependencies
run: npm ci --prefix plugins/sdk/dev-host
- name: Wait for platform packages
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: |
wait_for_package() {
package="$1"
for attempt in $(seq 1 60); do
if npm view "${package}@${VERSION}" version >/dev/null 2>&1; then
return 0
fi
echo "Waiting for ${package}@${VERSION} (${attempt}/60)."
sleep 10
done
return 1
}
for package in \
@dbx-app/plugin-cli-darwin-arm64 \
@dbx-app/plugin-cli-darwin-x64 \
@dbx-app/plugin-cli-linux-arm64-gnu \
@dbx-app/plugin-cli-linux-x64-gnu \
@dbx-app/plugin-cli-win32-arm64 \
@dbx-app/plugin-cli-win32-x64; do
wait_for_package "${package}" || {
echo "::error::${package}@${VERSION} is unavailable; refusing to publish the launcher."
exit 1
}
done
- name: Publish launcher and bundled SDK
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ needs.prepare.outputs.version }}
NPM_TAG: ${{ needs.prepare.outputs.npm-tag }}
run: |
if npm view "@dbx-app/plugin-cli@${VERSION}" version >/dev/null 2>&1; then
echo "@dbx-app/plugin-cli@${VERSION} already exists; refreshing ${NPM_TAG}."
npm dist-tag add "@dbx-app/plugin-cli@${VERSION}" "${NPM_TAG}"
else
npm publish ./packages/plugin-cli --access public --provenance --tag "${NPM_TAG}"
fi
verify-published-package:
name: Verify clean npm installation
needs: [prepare, publish-launcher]
runs-on: ubuntu-24.04
steps:
- uses: actions/setup-node@v6
with:
node-version: 22.23.3
registry-url: https://registry.npmjs.org
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-go@v6
with:
go-version: "1.22.x"
cache: false
- name: Install from npm and package every template
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: |
set -euo pipefail
work="$(mktemp -d)"
cd "${work}"
npm init -y >/dev/null
for attempt in $(seq 1 60); do
if npm view "@dbx-app/plugin-cli@${VERSION}" version >/dev/null 2>&1; then
break
fi
if [ "${attempt}" -eq 60 ]; then
echo "::error::@dbx-app/plugin-cli@${VERSION} did not become visible on npm."
exit 1
fi
sleep 10
done
npm install --ignore-scripts --no-audit --no-fund "@dbx-app/plugin-cli@${VERSION}"
./node_modules/.bin/dbx-plugin --version
for template in frontend rust go; do
./node_modules/.bin/dbx-plugin create "${template}-plugin" \
--template "${template}" \
--yes \
--id "com.example.npm-${template}" \
--name "npm ${template} smoke" \
--publisher example \
--description "Published npm package smoke"
./node_modules/.bin/dbx-plugin package "${template}-plugin"
test "$(find "${template}-plugin/dist" -maxdepth 1 -name '*.dbxp' | wc -l)" -eq 1
done