|
7 | 7 | * |
8 | 8 | * Copyright Oxide Computer Company |
9 | 9 | */ |
10 | | -import * as flags from 'https://deno.land/std@0.159.0/flags/mod.ts' |
11 | 10 | import * as path from 'https://deno.land/std@0.159.0/path/mod.ts' |
12 | 11 | 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' |
13 | 14 | import { existsSync } from 'jsr:@std/fs@1.0' |
14 | 15 |
|
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 | | - |
33 | 16 | const OMICRON_DIR = path.resolve('../omicron') |
34 | 17 | const GH_MISSING = 'GitHub CLI not found. Please install it and try again.' |
35 | 18 |
|
@@ -157,73 +140,64 @@ async function makeOmicronPR( |
157 | 140 | await $`git branch -D ${branchName}`.cwd(OMICRON_DIR) |
158 | 141 | } |
159 | 142 |
|
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 | +} |
186 | 146 |
|
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. |
188 | 153 |
|
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 | + } |
194 | 169 |
|
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() |
197 | 172 |
|
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 | + } |
199 | 177 |
|
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}` |
201 | 181 |
|
202 | | - await makeOmicronPR(newConsoleCommit, prTitle, changesLink, commits) |
| 182 | + console.info(`\n${changesLink}\n\n${commits}\n`) |
203 | 183 |
|
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`) |
210 | 187 |
|
211 | | -// script starts here |
| 188 | + const go = await Confirm.prompt({ message: 'Make Omicron PR?' }) |
| 189 | + if (!go) return |
212 | 190 |
|
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) |
218 | 192 |
|
219 | | -if (args.help) { |
220 | | - console.info(HELP) |
221 | | - Deno.exit() |
222 | | -} |
| 193 | + const consoleDir = Deno.cwd() // save it so we can change back |
223 | 194 |
|
224 | | -if (!existsSync(OMICRON_DIR)) { |
225 | | - throw new Error(`Omicron repo not found at ${OMICRON_DIR}`) |
226 | | -} |
| 195 | + await makeOmicronPR(newConsoleCommit, prTitle, changesLink, commits) |
227 | 196 |
|
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