Skip to content

Commit 0f06ce9

Browse files
authored
tools: rewrite bump-omicron.ts with cliffy (#3137)
Was tweaking the script to prompt for a description (the part in the parens: `Bump web console (light mode polish)`) instead of taking it as a `-m` flag up front — you need to see the commits before you can write a description! Then I converted the script to use Cliffy, which we already use in `api-diff.ts` and I use in all my personal CLI stuff. It gets us nicer arg parsing and nice help output without having to hard code it as a string. <img width="599" height="377" alt="image" src="https://github.com/user-attachments/assets/1891dbce-1b69-46f5-9e33-066aa12abb37" />
1 parent d697520 commit 0f06ce9

File tree

2 files changed

+52
-78
lines changed

2 files changed

+52
-78
lines changed

tools/deno/api-diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
import { exists } from 'https://deno.land/std@0.208.0/fs/mod.ts'
1111
import { $ } from 'https://deno.land/x/dax@0.39.1/mod.ts'
12-
import { Command, ValidationError } from 'jsr:@cliffy/command@1.0.0-rc.8'
12+
import { Command, ValidationError } from 'jsr:@cliffy/command@1.0.0'
1313

1414
// fzf picker keeps UX quick without requiring people to wire up shell helpers
1515
async function pickPr(): Promise<number> {

tools/deno/bump-omicron.ts

Lines changed: 51 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,12 @@
77
*
88
* Copyright Oxide Computer Company
99
*/
10-
import * as flags from 'https://deno.land/std@0.159.0/flags/mod.ts'
1110
import * as path from 'https://deno.land/std@0.159.0/path/mod.ts'
1211
import $ from 'https://deno.land/x/dax@0.39.2/mod.ts'
12+
import { Command } from 'jsr:@cliffy/command@1.0.0'
13+
import { Confirm, Input } from 'jsr:@cliffy/prompt@1.0.0'
1314
import { existsSync } from 'jsr:@std/fs@1.0'
1415

15-
const HELP = `
16-
Update tools/console_version in ../omicron to the specified console
17-
commit and create PR in Omicron with that change. We use a git worktree
18-
to avoid touching your Omicron clone.
19-
20-
Requirements:
21-
- GitHub CLI installed
22-
- Omicron is a sibling dir to console
23-
24-
Usage:
25-
./tools/deno/bump-omicron.ts [commit-ish=main] [options]
26-
27-
Options:
28-
-d, --dry-run Dry run, showing changes without creating PR
29-
-h, --help Show this help message
30-
-m, --message <msg> Add message to PR title: 'Bump web console (<msg>)'
31-
`
32-
3316
const OMICRON_DIR = path.resolve('../omicron')
3417
const GH_MISSING = 'GitHub CLI not found. Please install it and try again.'
3518

@@ -157,73 +140,64 @@ async function makeOmicronPR(
157140
await $`git branch -D ${branchName}`.cwd(OMICRON_DIR)
158141
}
159142

160-
// wrapped in a function so we can do early returns rather than early
161-
// Deno.exits, which mess up the worktree cleanup
162-
async function run(commitIsh: string, dryRun: boolean, messageArg: string | undefined) {
163-
// Ensure local main matches the remote so we don't bump to a stale commit
164-
if (commitIsh === 'main') {
165-
const localMain = await $`git rev-parse main`.text()
166-
const remoteMain = await $`git ls-remote origin main`.text()
167-
const remoteMainSha = remoteMain.split('\t')[0]
168-
if (localMain !== remoteMainSha) {
169-
throw new Error('Local main does not match remote. Fetch main and try again.')
170-
}
171-
}
172-
173-
const oldConsoleCommit = await getOldCommit()
174-
const newConsoleCommit = await $`git rev-parse ${commitIsh}`.text()
175-
176-
if (oldConsoleCommit === newConsoleCommit) {
177-
console.info(`Nothing to update: Omicron already has ${newConsoleCommit} pinned`)
178-
return
179-
}
180-
181-
const commitRange = `${oldConsoleCommit.slice(0, 8)}...${newConsoleCommit.slice(0, 8)}`
182-
const commits = await $`git log --graph --oneline ${commitRange}`.text()
183-
const changesLink = `https://github.com/oxidecomputer/console/compare/${commitRange}`
184-
185-
console.info(`\n${changesLink}\n\n${commits}\n`)
143+
if (!existsSync(OMICRON_DIR)) {
144+
throw new Error(`Omicron repo not found at ${OMICRON_DIR}`)
145+
}
186146

187-
if (dryRun) return
147+
await new Command()
148+
.name('bump-omicron')
149+
.description(
150+
`Update tools/console_version in ../omicron to the specified console
151+
commit and create PR in Omicron with that change. We use a git worktree
152+
to avoid touching your Omicron clone.
188153
189-
const message =
190-
messageArg ||
191-
(await $.prompt({ message: 'Description? (enter to skip)', noClear: true }))
192-
const prTitle = 'Bump web console' + (message ? ` (${message})` : '')
193-
console.info(`\nPR title: ${prTitle}\n`)
154+
Requirements:
155+
- GitHub CLI installed
156+
- Omicron is a sibling dir to console`
157+
)
158+
.argument('[commit:string]', 'Console commit (default: main)', { default: 'main' })
159+
.action(async (_options, commitIsh) => {
160+
// Ensure local main matches the remote so we don't bump to a stale commit
161+
if (commitIsh === 'main') {
162+
const localMain = await $`git rev-parse main`.text()
163+
const remoteMain = await $`git ls-remote origin main`.text()
164+
const remoteMainSha = remoteMain.split('\t')[0]
165+
if (localMain !== remoteMainSha) {
166+
throw new Error('Local main does not match remote. Fetch main and try again.')
167+
}
168+
}
194169

195-
const go = await $.confirm({ message: 'Make Omicron PR?', noClear: true })
196-
if (!go) return
170+
const oldConsoleCommit = await getOldCommit()
171+
const newConsoleCommit = await $`git rev-parse ${commitIsh}`.text()
197172

198-
if (!$.commandExistsSync('gh')) throw new Error(GH_MISSING)
173+
if (oldConsoleCommit === newConsoleCommit) {
174+
console.info(`Nothing to update: Omicron already has ${newConsoleCommit} pinned`)
175+
return
176+
}
199177

200-
const consoleDir = Deno.cwd() // save it so we can change back
178+
const commitRange = `${oldConsoleCommit.slice(0, 8)}...${newConsoleCommit.slice(0, 8)}`
179+
const commits = await $`git log --graph --oneline ${commitRange}`.text()
180+
const changesLink = `https://github.com/oxidecomputer/console/compare/${commitRange}`
201181

202-
await makeOmicronPR(newConsoleCommit, prTitle, changesLink, commits)
182+
console.info(`\n${changesLink}\n\n${commits}\n`)
203183

204-
// bump omicron tag in console to current commit
205-
Deno.chdir(consoleDir)
206-
console.info('Bumping omicron tag in console')
207-
await $`git tag -f -a omicron -m 'pinned commit on omicron main' ${commitIsh}`
208-
await $`git push -f origin tag omicron`
209-
}
184+
const message = (await Input.prompt({ message: 'Description? (enter to skip)' })).trim()
185+
const prTitle = 'Bump web console' + (message ? ` (${message})` : '')
186+
console.info(`\nPR title: ${prTitle}\n`)
210187

211-
// script starts here
188+
const go = await Confirm.prompt({ message: 'Make Omicron PR?' })
189+
if (!go) return
212190

213-
const args = flags.parse(Deno.args, {
214-
alias: { dryRun: ['d', 'dry-run'], h: 'help', m: 'message' },
215-
boolean: ['dryRun', 'help'],
216-
string: ['message'],
217-
})
191+
if (!$.commandExistsSync('gh')) throw new Error(GH_MISSING)
218192

219-
if (args.help) {
220-
console.info(HELP)
221-
Deno.exit()
222-
}
193+
const consoleDir = Deno.cwd() // save it so we can change back
223194

224-
if (!existsSync(OMICRON_DIR)) {
225-
throw new Error(`Omicron repo not found at ${OMICRON_DIR}`)
226-
}
195+
await makeOmicronPR(newConsoleCommit, prTitle, changesLink, commits)
227196

228-
const commitIsh = args._[0]?.toString() || 'main'
229-
await run(commitIsh, args.dryRun, args.message)
197+
// bump omicron tag in console to current commit
198+
Deno.chdir(consoleDir)
199+
console.info('Bumping omicron tag in console')
200+
await $`git tag -f -a omicron -m 'pinned commit on omicron main' ${commitIsh}`
201+
await $`git push -f origin tag omicron`
202+
})
203+
.parse(Deno.args)

0 commit comments

Comments
 (0)