Skip to content

Commit 1175d99

Browse files
committed
refactor(workflow): tighten upgrade-deps script + prompt
- Consolidate the `check-upgrade-dependencies` Claude prompt: the three overlapping sections (old Instructions, Final check, "Help me fix") all described the same test/build/snap-test checks and sometimes contradicted each other. Replace with a single structured prompt (Background → Fixups → Final validation → Commit rule) where each requirement appears exactly once. - `updatePnpmWorkspace` now uses a single-pass `String.replace` with a callback, so the current version is captured during the substitution instead of via a separate `match` call. Drops the redundant `replacement` field from each entry and removes the "matched once but replace didn't match" edge case. - `getLatestTag` fetches only the newest tag (`?per_page=1`) instead of the default 30. - `updateCorePackage` now early-returns when `@vitejs/devtools` is absent, skipping the no-op JSON rewrite.
1 parent 9446a5f commit 1175d99

2 files changed

Lines changed: 64 additions & 101 deletions

File tree

.github/scripts/upgrade-deps.mjs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function recordChange(name, oldValue, newValue, tag) {
2424

2525
// ============ GitHub API ============
2626
async function getLatestTag(owner, repo) {
27-
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/tags`, {
27+
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/tags?per_page=1`, {
2828
headers: {
2929
Authorization: `token ${process.env.GITHUB_TOKEN}`,
3030
Accept: 'application/vnd.github.v3+json',
@@ -84,64 +84,47 @@ async function updatePnpmWorkspace(versions) {
8484
const filePath = path.join(ROOT, 'pnpm-workspace.yaml');
8585
let content = fs.readFileSync(filePath, 'utf8');
8686

87-
// The capture regex returns the current version in $1; the replacement string
88-
// substitutes the new version into the same anchor text.
89-
// oxlint's trailing \n disambiguates from oxlint-tsgolint.
87+
// The capture regex puts the current version in $1 and matches exactly what
88+
// the new string will replace. oxlint's trailing \n disambiguates from oxlint-tsgolint.
9089
const entries = [
9190
{
9291
name: 'vitest',
93-
pattern: /vitest-dev: npm:vitest@\^([\d.]+(?:-[\w.]+)?)/,
94-
replacement: `vitest-dev: npm:vitest@^${versions.vitest}`,
92+
pattern: /(vitest-dev: npm:vitest@\^)([\d.]+(?:-[\w.]+)?)/,
9593
newVersion: versions.vitest,
9694
},
97-
{
98-
name: 'tsdown',
99-
pattern: /tsdown: \^([\d.]+(?:-[\w.]+)?)/,
100-
replacement: `tsdown: ^${versions.tsdown}`,
101-
newVersion: versions.tsdown,
102-
},
95+
{ name: 'tsdown', pattern: /(tsdown: \^)([\d.]+(?:-[\w.]+)?)/, newVersion: versions.tsdown },
10396
{
10497
name: '@oxc-node/cli',
105-
pattern: /'@oxc-node\/cli': \^([\d.]+(?:-[\w.]+)?)/,
106-
replacement: `'@oxc-node/cli': ^${versions.oxcNodeCli}`,
98+
pattern: /('@oxc-node\/cli': \^)([\d.]+(?:-[\w.]+)?)/,
10799
newVersion: versions.oxcNodeCli,
108100
},
109101
{
110102
name: '@oxc-node/core',
111-
pattern: /'@oxc-node\/core': \^([\d.]+(?:-[\w.]+)?)/,
112-
replacement: `'@oxc-node/core': ^${versions.oxcNodeCore}`,
103+
pattern: /('@oxc-node\/core': \^)([\d.]+(?:-[\w.]+)?)/,
113104
newVersion: versions.oxcNodeCore,
114105
},
115-
{
116-
name: 'oxfmt',
117-
pattern: /oxfmt: =([\d.]+(?:-[\w.]+)?)/,
118-
replacement: `oxfmt: =${versions.oxfmt}`,
119-
newVersion: versions.oxfmt,
120-
},
121-
{
122-
name: 'oxlint',
123-
pattern: /oxlint: =([\d.]+(?:-[\w.]+)?)\n/,
124-
replacement: `oxlint: =${versions.oxlint}\n`,
125-
newVersion: versions.oxlint,
126-
},
106+
{ name: 'oxfmt', pattern: /(oxfmt: =)([\d.]+(?:-[\w.]+)?)/, newVersion: versions.oxfmt },
107+
{ name: 'oxlint', pattern: /(oxlint: =)([\d.]+(?:-[\w.]+)?)(\n)/, newVersion: versions.oxlint },
127108
{
128109
name: 'oxlint-tsgolint',
129-
pattern: /oxlint-tsgolint: =([\d.]+(?:-[\w.]+)?)/,
130-
replacement: `oxlint-tsgolint: =${versions.oxlintTsgolint}`,
110+
pattern: /(oxlint-tsgolint: =)([\d.]+(?:-[\w.]+)?)/,
131111
newVersion: versions.oxlintTsgolint,
132112
},
133113
];
134114

135-
for (const { name, pattern, replacement, newVersion } of entries) {
136-
const oldVersion = content.match(pattern)?.[1];
137-
if (!oldVersion) {
115+
for (const { name, pattern, newVersion } of entries) {
116+
let matched = false;
117+
content = content.replace(pattern, (_match, prefix, oldVersion, suffix = '') => {
118+
matched = true;
119+
recordChange(name, oldVersion, newVersion);
120+
return `${prefix}${newVersion}${suffix}`;
121+
});
122+
if (!matched) {
138123
throw new Error(
139124
`Failed to match ${name} in pnpm-workspace.yaml — the pattern ${pattern} is stale, ` +
140125
`please update it in .github/scripts/upgrade-deps.mjs`,
141126
);
142127
}
143-
content = content.replace(pattern, replacement);
144-
recordChange(name, oldVersion, newVersion);
145128
}
146129

147130
fs.writeFileSync(filePath, content);
@@ -180,10 +163,11 @@ async function updateCorePackage(devtoolsVersion) {
180163
const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
181164

182165
const currentDevtools = pkg.devDependencies?.['@vitejs/devtools'];
183-
if (currentDevtools) {
184-
pkg.devDependencies['@vitejs/devtools'] = `^${devtoolsVersion}`;
185-
recordChange('@vitejs/devtools', currentDevtools.replace(/^[\^~]/, ''), devtoolsVersion);
166+
if (!currentDevtools) {
167+
return;
186168
}
169+
pkg.devDependencies['@vitejs/devtools'] = `^${devtoolsVersion}`;
170+
recordChange('@vitejs/devtools', currentDevtools.replace(/^[\^~]/, ''), devtoolsVersion);
187171

188172
fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2) + '\n');
189173
console.log('Updated packages/core/package.json');

.github/workflows/upgrade-deps.yml

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -72,70 +72,49 @@ jobs:
7272
github_token: ${{ secrets.GITHUB_TOKEN }}
7373
show_full_output: 'true'
7474
prompt: |
75-
Check if the build-upstream steps failed and fix them.
75+
Your goal: after the daily upstream-dependency upgrade, bring the project back
76+
to a fully green state. The upgrade script has already bumped every dep to the
77+
latest version and the `build-upstream` action has attempted a build — your job
78+
is to diagnose and fix every error that surfaced, then prove the fix is complete
79+
by running a final validation pass.
80+
7681
### Background
77-
- The build-upstream steps are at ./.github/actions/build-upstream/action.yml
78-
- The deps upgrade script is at ./.github/scripts/upgrade-deps.mjs
79-
80-
### Instructions
81-
- We are using `pnpm` as the package manager
82-
- We are aiming to upgrade all dependencies to the latest versions in this workflow, so don't downgrade any dependencies.
83-
- Compare tsdown CLI options with `vp pack` and sync any new or removed options. Follow the instructions in `.claude/skills/sync-tsdown-cli/SKILL.md`.
84-
- Check `.claude/agents/cargo-workspace-merger.md` if rolldown hash is changed.
85-
- Run the steps in `build-upstream` action.yml after your fixing. If no errors are found, you can safe to exit.
86-
- Install global CLI after the build-upstream steps are successful, by running the following commands:
87-
- `pnpm bootstrap-cli:ci`
88-
- `echo "$HOME/.vite-plus/bin" >> $GITHUB_PATH`
89-
- Run `pnpm run lint` to check if there are any issues after the build, if has, deep investigate it and fix it. You need to run `just build` before you can run `pnpm run lint`.
90-
- If deps in our `Cargo.toml` need to be upgraded, you can refer to the `./.claude/agents/cargo-workspace-merger.md`
91-
- If `Cargo.toml` has been modified, you need to run `cargo shear` to ensure there is nothing wrong with our dependencies.
92-
- Run `cargo check --all-targets --all-features` to ensure everything works fine if any Rust related codes are modified.
93-
- Run the following commands to ensure everything works fine:
94-
vp -h
95-
vp run -h
96-
vp lint -h
97-
vp test -h
98-
vp build -h
99-
vp fmt -h
100-
vp pack -h
101-
102-
### Final check (BOTH must succeed before you exit)
103-
This step is only complete when BOTH of the following pass. If either one fails,
104-
diagnose and fix the root cause, then re-run both until they both succeed.
105-
1. `just build` — must exit 0. If it fails, investigate the error, fix the
106-
underlying issue, and run it again.
107-
2. `pnpm bootstrap-cli:ci && pnpm test` — must exit 0. If it fails, investigate
108-
the error, fix the underlying issue, and run it again. Note that the snap
109-
tests inside `pnpm test` always exit 0 even when their outputs differ, so
110-
after the command passes you MUST also inspect the `git diff` on
111-
`packages/cli/snap-tests/**/snap.txt` and `packages/cli/snap-tests-global/**/snap.txt`
112-
and decide whether each change is an acceptable consequence of the upstream
113-
upgrade (e.g. a version string bump) or a real regression that needs fixing.
114-
115-
Only exit after you have confirmed both of the above succeed. Do not consider
116-
the task complete if either `just build` fails, `pnpm bootstrap-cli:ci && pnpm test`
117-
fails, or the snap-test diff shows an apparent regression.
118-
119-
Help me fix every error that surfaces during this step. That includes, at
120-
minimum:
121-
- Failures in the `build-upstream` action (non-zero exit from any step inside
122-
`.github/actions/build-upstream/action.yml`).
123-
- `pnpm run lint` errors.
124-
- `just build` failures.
125-
- `pnpm bootstrap-cli:ci && pnpm test` failures.
126-
- Snap-test regressions: `pnpm test` always exits 0 even when snapshot outputs
127-
differ, so you MUST inspect the `git diff` on
128-
`packages/cli/snap-tests/**/snap.txt` and
129-
`packages/cli/snap-tests-global/**/snap.txt` and fix any change that looks
130-
like a real regression (e.g., unexpected stack traces, missing output,
131-
diverging CLI behavior). Cosmetic drift caused by the upstream upgrade
132-
itself (e.g., a bumped version string in help output) is acceptable —
133-
leave those in place.
134-
- `cargo check --all-targets --all-features` errors if any Rust code was
135-
modified, and stale `cargo shear` findings if `Cargo.toml` changed.
136-
137-
Do NOT commit any changes — a later workflow step handles the commit for all
138-
modified files.
82+
- Upgrade script: `./.github/scripts/upgrade-deps.mjs`
83+
- Build-upstream action: `./.github/actions/build-upstream/action.yml`
84+
- Package manager: `pnpm`. Do NOT downgrade any dep — we want the latest.
85+
86+
### Fixups to perform (in order)
87+
1. Re-run the steps in `./.github/actions/build-upstream/action.yml`; fix any
88+
non-zero exits.
89+
2. If the rolldown hash changed, follow `.claude/agents/cargo-workspace-merger.md`
90+
to resync the workspace.
91+
3. Compare tsdown CLI options with `vp pack` and sync new/removed options per
92+
`.claude/skills/sync-tsdown-cli/SKILL.md`.
93+
4. Install the global CLI:
94+
- `pnpm bootstrap-cli:ci`
95+
- `echo "$HOME/.vite-plus/bin" >> $GITHUB_PATH`
96+
5. If any Rust code or `Cargo.toml` was modified, run `cargo check
97+
--all-targets --all-features` and `cargo shear`; fix anything they report.
98+
6. Run `pnpm run lint` (requires a prior `just build`); fix any errors.
99+
7. Smoke-test the CLI: `vp -h`, `vp run -h`, `vp lint -h`, `vp test -h`,
100+
`vp build -h`, `vp fmt -h`, `vp pack -h`.
101+
102+
### Final validation (this step is complete ONLY when all pass)
103+
1. `just build` exits 0.
104+
2. `pnpm bootstrap-cli:ci && pnpm test` exits 0.
105+
3. `git diff` on `packages/cli/snap-tests/**/snap.txt` and
106+
`packages/cli/snap-tests-global/**/snap.txt` contains no real regressions.
107+
IMPORTANT: `pnpm test` always exits 0 even when snap outputs differ, so you
108+
MUST inspect the diff yourself. Cosmetic drift from the upgrade (e.g. a
109+
bumped version string in help output) is acceptable; unexpected stack
110+
traces, missing output, or diverging CLI behavior are regressions to fix.
111+
112+
If any of the three above fails, diagnose the root cause, fix it, and re-run
113+
the final validation. Do not exit with the task marked complete otherwise.
114+
115+
### Commit rule
116+
Do NOT run `git commit` or `git push`. A later workflow step commits every
117+
modified file for you.
139118
claude_args: |
140119
--model opus --allowedTools "Bash,Edit,Replace,NotebookEditCell"
141120
additional_permissions: |

0 commit comments

Comments
 (0)