Skip to content

Commit 83321d0

Browse files
chore(npm): publish WebUI previews on every webui push
Replace the tag-triggered flow with a push-to-webui flow so a plain commit publishes a new preview version. The version is resolved from the highest <core>-preview.<n> already on the registry rather than from a tag or a field in the repository, and a version that is already published is skipped, so reruns of a successful run no-op instead of failing. Authenticate with the NPM_TOKEN repository secret instead of npm trusted publishing, which is not configured for this package. Provenance is therefore not generated; docs/releasing-webui-npm.md records the one-line change that would restore it. release/webui-npm/package.json carries the last published version so a local build does not default to a version npm will refuse to accept.
1 parent ee9f6f9 commit 83321d0

3 files changed

Lines changed: 103 additions & 59 deletions

File tree

‎.github/workflows/webui-npm-preview.yml‎

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ name: WebUI npm preview
22

33
on:
44
push:
5-
tags: ["webui-v*"]
5+
branches: ["webui"]
6+
workflow_dispatch:
67

78
permissions:
89
contents: read
9-
id-token: write
1010

1111
concurrency:
12-
group: webui-npm-preview-${{ github.ref }}
12+
group: webui-npm-preview
1313
cancel-in-progress: false
1414

1515
jobs:
@@ -28,19 +28,61 @@ jobs:
2828
registry-url: "https://registry.npmjs.org"
2929
scope: "@fectivnfy112358"
3030
- run: pnpm install --frozen-lockfile
31-
- name: Validate preview tag
31+
- name: Resolve next preview version
3232
id: release
3333
shell: bash
3434
run: |
35-
version="${GITHUB_REF_NAME#webui-v}"
36-
if [[ ! "$GITHUB_REF_NAME" =~ ^webui-v[0-9]+\.[0-9]+\.[0-9]+-preview\.[0-9]+$ ]]; then
37-
echo "Expected tag webui-v<major>.<minor>.<patch>-preview.<number>." >&2
38-
exit 1
39-
fi
35+
# The published version is the next counter after the highest
36+
# `<core>-preview.<n>` already on the registry, so a plain push never
37+
# needs a version bump in the repository. Resolving it from the
38+
# registry rather than from a git tag is what makes reruns safe: a
39+
# rerun recomputes the same number only if nothing was published in
40+
# between, and the publish step below treats an existing version as a
41+
# no-op instead of a failure.
42+
package="$(node -p 'require("./release/webui-npm/package.json").name')"
43+
versions="$(npm view "$package" versions --json)"
44+
version="$(printf '%s' "$versions" | node -e '
45+
let raw = "";
46+
process.stdin.on("data", (c) => (raw += c)).on("end", () => {
47+
const parsed = JSON.parse(raw || "[]");
48+
const list = Array.isArray(parsed) ? parsed : [parsed];
49+
const seen = [];
50+
for (const value of list) {
51+
const match = /^(\d+)\.(\d+)\.(\d+)-preview\.(\d+)$/.exec(String(value));
52+
if (!match) continue;
53+
seen.push({ core: [Number(match[1]), Number(match[2]), Number(match[3])], n: Number(match[4]) });
54+
}
55+
if (seen.length === 0) {
56+
console.log("0.1.0-preview.1");
57+
return;
58+
}
59+
// Numeric tuple compare, not a string compare, so 0.10.0 outranks 0.9.0.
60+
const top = seen.reduce((a, b) => {
61+
for (let i = 0; i < 3; i++) {
62+
if (a.core[i] !== b.core[i]) return a.core[i] > b.core[i] ? a : b;
63+
}
64+
return a.n >= b.n ? a : b;
65+
});
66+
console.log(`${top.core.join(".")}-preview.${top.n + 1}`);
67+
});
68+
')"
69+
echo "package=$package" >> "$GITHUB_OUTPUT"
4070
echo "version=$version" >> "$GITHUB_OUTPUT"
71+
echo "Publishing $package@$version"
4172
- name: Build npm package
4273
run: node scripts/package-webui-npm.mjs --version "${{ steps.release.outputs.version }}" --outdir "$RUNNER_TEMP/webui-package"
4374
- name: Inspect package contents
4475
run: npm pack --dry-run --json "$RUNNER_TEMP/webui-package"
4576
- name: Publish preview to the npm registry
46-
run: npm publish "$RUNNER_TEMP/webui-package" --tag preview
77+
shell: bash
78+
run: |
79+
set -euo pipefail
80+
package="${{ steps.release.outputs.package }}"
81+
version="${{ steps.release.outputs.version }}"
82+
if npm view "$package@$version" version >/dev/null 2>&1; then
83+
echo "$package@$version is already published; nothing to do."
84+
exit 0
85+
fi
86+
npm publish "$RUNNER_TEMP/webui-package" --tag preview
87+
env:
88+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

‎docs/releasing-webui-npm.md‎

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,68 @@
11
# WebUI package on the npm registry
22

33
The WebUI is packaged as `@fectivnfy112358/minimax-code-web` and published to
4-
`https://registry.npmjs.org` with the `preview` dist-tag. The repository's
5-
`.github/workflows/webui-npm-preview.yml` workflow publishes through npm trusted
6-
publishing (OIDC) and holds no npm token. A trusted publisher can only be
7-
configured once the package exists on npmjs.com, so the first version is
8-
published from a machine that holds a token.
4+
`https://registry.npmjs.org` under the `preview` dist-tag. Publishing is fully
5+
automatic: every push to the `webui` branch builds the standalone package and
6+
publishes a new preview version. No tag, no version edit, no manual step.
97

10-
## First publication
8+
## How a release happens
119

12-
1. Build the package and inspect the tarball:
10+
`.github/workflows/webui-npm-preview.yml` runs on `push` to `webui` and on
11+
`workflow_dispatch`. It:
1312

14-
```sh
15-
pnpm install --frozen-lockfile
16-
pnpm run package:webui-npm -- --version 0.1.0-preview.0 --outdir /tmp/minimax-code-web
17-
npm pack --dry-run /tmp/minimax-code-web
18-
```
13+
1. installs the workspace with a frozen lockfile;
14+
2. resolves the next version by reading the highest `<core>-preview.<n>`
15+
already on the registry and incrementing `n`;
16+
3. builds the package with `scripts/package-webui-npm.mjs`;
17+
4. inspects the tarball with `npm pack --dry-run`;
18+
5. publishes, unless that version is already on the registry, in which case it
19+
exits successfully without publishing.
1920

20-
2. Create a granular access token on npmjs.com with **Read and write (publish
21-
and stage)** access. Put it in the user-level `~/.npmrc`; never in the
22-
repository's `.npmrc`, which is tracked by Git:
21+
Because the version is derived from the registry rather than from a git tag or a
22+
field in the repository, the `version` in `release/webui-npm/package.json` is
23+
only the default for local builds. Editing it does not trigger or choose a
24+
release.
2325

24-
```ini
25-
//registry.npmjs.org/:_authToken=<token>
26-
```
26+
The already-published check in step 5 is what makes reruns safe. A rerun of a
27+
successful run recomputes the same version, sees it published, and no-ops.
2728

28-
3. Publish the first version:
29+
## Credentials
2930

30-
```sh
31-
npm publish /tmp/minimax-code-web --tag preview
32-
```
31+
The workflow authenticates with the repository secret `NPM_TOKEN`, which must be
32+
a granular access token with **Read and write (publish and stage)** access to
33+
`@fectivnfy112358`. It is read as `NODE_AUTH_TOKEN`, which `actions/setup-node`
34+
turns into the `//registry.npmjs.org/:_authToken` entry the publish step needs.
3335

34-
`publishConfig.access` in `release/webui-npm/package.json` already makes the
35-
scoped package public.
36+
Set it once:
3637

37-
## Enable trusted publishing
38+
```sh
39+
gh secret set NPM_TOKEN --repo <owner>/<repo>
40+
```
3841

39-
On npmjs.com, open the package settings, add a trusted publisher for GitHub
40-
Actions, and use:
42+
The workflow holds no npm token in the repository, and no token belongs in the
43+
tracked `.npmrc`.
4144

42-
- **Organization or user**: `fectivnfy112358`
43-
- **Repository**: `minimax-code`
44-
- **Workflow filename**: `webui-npm-preview.yml` (filename only, including the
45-
extension)
46-
- **Environment name**: leave empty
47-
- **Allowed actions**: `npm publish`
45+
## Publishing attestations
4846

49-
The workflow declares no GitHub environment and no `NODE_AUTH_TOKEN`, so these
50-
values must stay in sync with it. Once a tag-triggered release has been verified,
51-
revoke the token from step 2.
47+
The workflow does **not** pass `--provenance`, so published versions carry no
48+
npm provenance attestation. Provenance requires npm trusted publishing (OIDC),
49+
which in turn requires the package's trusted publisher to be configured on
50+
npmjs.com. If that configuration is ever added, give the workflow
51+
`permissions: id-token: write` and pass `--provenance` to the publish step;
52+
`repository.url` in `release/webui-npm/package.json` must keep matching the
53+
GitHub repository or attestation generation fails.
5254

53-
## Publish a preview
55+
## Local builds
5456

55-
1. Merge the intended changes into `webui` and confirm the package build is
56-
ready.
57-
2. Create a tag on that commit using the package version, for example
58-
`webui-v0.1.0-preview.1`.
59-
3. Push that tag. The workflow checks the preview version format, builds the
60-
standalone package, inspects the npm tarball contents, then publishes to
61-
`https://registry.npmjs.org` with the `preview` dist-tag.
57+
`release/webui-npm/package.json` carries the version a local build falls back to
58+
when `--version` is omitted. npm never accepts a republished version, so a local
59+
build that is meant to be published needs an explicit, unused version:
6260

63-
Provenance attestations are generated automatically by the trusted publish; the
64-
`--provenance` flag is not needed. `repository.url` in
65-
`release/webui-npm/package.json` must keep matching the GitHub repository or
66-
provenance validation fails.
61+
```sh
62+
pnpm install --frozen-lockfile
63+
pnpm run package:webui-npm -- --version 0.1.0-preview.4 --outdir /tmp/minimax-code-web
64+
npm pack --dry-run /tmp/minimax-code-web
65+
```
66+
67+
`publishConfig.access` in `release/webui-npm/package.json` already makes the
68+
scoped package public.

‎release/webui-npm/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fectivnfy112358/minimax-code-web",
3-
"version": "0.1.0-preview.0",
3+
"version": "0.1.0-preview.3",
44
"description": "MiniMax Code WebUI with a local, process-based runtime.",
55
"license": "MIT",
66
"repository": {

0 commit comments

Comments
 (0)