Skip to content

Commit 65ae121

Browse files
authored
Make bump-omicron script cooler with dax, which is zx for deno (#1820)
* make bump-omicron script cooler with dax, which is zx for deno * increase license check location threshold for long shebang
1 parent 5a6dcea commit 65ae121

File tree

2 files changed

+21
-44
lines changed

2 files changed

+21
-44
lines changed

.licenserc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
header:
2+
# default is 80, need to make it slightly longer for a long shebang
3+
license-location-threshold: 100
24
license:
35
spdx-id: MPL-2.0
46
content: |

tools/deno/bump-omicron.ts

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env -S deno run --allow-run --allow-net --allow-read --allow-write
1+
#! /usr/bin/env -S deno run --allow-run --allow-net --allow-read --allow-write --allow-env
22

33
/*
44
* This Source Code Form is subject to the terms of the Mozilla Public
@@ -9,6 +9,7 @@
99
*/
1010
import * as flags from 'https://deno.land/std@0.159.0/flags/mod.ts'
1111
import * as path from 'https://deno.land/std@0.159.0/path/mod.ts'
12+
import $ from 'https://deno.land/x/dax@0.35.0/mod.ts'
1213

1314
const HELP = `
1415
Update tools/console_version in ../omicron with current console commit
@@ -33,31 +34,8 @@ const VERSION_FILE = path.join(OMICRON_DIR, 'tools/console_version')
3334
const GH_MISSING = 'GitHub CLI not found. Please install it and try again.'
3435
const VERSION_FILE_MISSING = `Omicron console version file at '${VERSION_FILE}' not found. This script assumes Omicron is cloned in a sibling directory next to Console.`
3536

36-
/** Run shell command, get output as string */
37-
function run(cmd: string, args: string[]): string {
38-
const { success, stdout } = new Deno.Command(cmd, { args, stdout: 'piped' }).outputSync()
39-
40-
if (!success) {
41-
throw Error(`Shell command '${cmd} ${args.join(' ')}' failed`)
42-
}
43-
44-
return new TextDecoder().decode(stdout).trim()
45-
}
46-
47-
function getUploadAssetsWorkflowId() {
48-
return run('gh', [
49-
'run',
50-
'list',
51-
'-L',
52-
'1',
53-
'-w',
54-
'Upload assets to dl.oxide.computer',
55-
'--json',
56-
'databaseId',
57-
'--jq',
58-
'.[0].databaseId',
59-
])
60-
}
37+
const getUploadAssetsWorkflowId = () =>
38+
$`gh run list -L 1 -w 'Upload assets to dl.oxide.computer' --json databaseId --jq '.[0].databaseId'`.text()
6139

6240
/**
6341
* These lines get printed in an Omicron PR, so any references to commits or
@@ -94,7 +72,7 @@ if (args.help) {
9472
Deno.exit()
9573
}
9674

97-
const newCommit = run('git', ['rev-parse', 'HEAD'])
75+
const newCommit = await $`git rev-parse HEAD`.text()
9876

9977
const shaUrl = `https://dl.oxide.computer/releases/console/${newCommit}.sha256.txt`
10078
const shaResp = await fetch(shaUrl)
@@ -104,7 +82,7 @@ if (!shaResp.ok) {
10482
`
10583
Failed to fetch console tarball SHA. Either the current commit has not been pushed to origin/main or the CI job that uploads the assets is still running.
10684
107-
Run 'gh run watch ${getUploadAssetsWorkflowId()}' to watch the latest asset upload action.
85+
Run 'gh run watch ${await getUploadAssetsWorkflowId()}' to watch the latest asset upload action.
10886
`
10987
)
11088
console.error('URL:', shaUrl)
@@ -130,7 +108,7 @@ if (oldCommit === newCommit) {
130108

131109
const commitRange = `${oldCommit.slice(0, 8)}...${newCommit.slice(0, 8)}`
132110

133-
const commits = run('git', ['log', '--graph', '--oneline', commitRange])
111+
const commits = await $`git log --graph --oneline ${commitRange}`.text()
134112
// commits are console commits, so they won't auto-link in omicron
135113
const commitsMarkdown = commits.split('\n').map(linkifyGitLog).join('\n')
136114

@@ -161,36 +139,33 @@ if (args.dryRun || !confirm('\nMake Omicron PR with these changes?')) {
161139
Deno.exit()
162140
}
163141

164-
try {
165-
run('which', ['gh'])
166-
} catch (_e) {
167-
throw Error(GH_MISSING)
168-
}
142+
if (!$.commandExistsSync('gh')) throw Error(GH_MISSING)
169143

170144
await Deno.writeTextFile(VERSION_FILE, newVersionFile)
171145
console.log('Updated ', VERSION_FILE)
172146

173147
// cd to omicron, pull main, create new branch, commit changes, push, PR it, go back to
174148
// main, delete branch
175149
Deno.chdir(OMICRON_DIR)
176-
run('git', ['checkout', 'main'])
177-
run('git', ['pull'])
178-
run('git', ['checkout', '-b', branchName])
150+
await $`git checkout main`
151+
await $`git pull`
152+
await $`git checkout -b ${branchName}`
179153
console.log('Created branch', branchName)
180-
run('git', ['add', 'tools/console_version'])
181-
run('git', ['commit', '-m', prTitle, '-m', prBody])
182-
run('git', ['push', '--set-upstream', 'origin', branchName])
154+
155+
await $`git add tools/console_version`
156+
await $`git commit -m ${prTitle} -m ${prBody}`
157+
await $`git push --set-upstream origin ${branchName}`
183158
console.log('Committed changes and pushed')
184159

185160
// create PR
186-
const prUrl = run('gh', ['pr', 'create', '--title', prTitle, '--body', prBody])
161+
const prUrl = await $`gh pr create --title ${prTitle} --body ${prBody}`.text()
187162
console.log('PR created:', prUrl)
188163

189164
// set it to auto merge
190165
const prNum = prUrl.match(/\d+$/)![0]
191-
run('gh', ['pr', 'merge', prNum, '--auto', '--squash'])
166+
await $`gh pr merge ${prNum} --auto --squash`
192167
console.log('PR set to auto-merge when CI passes')
193168

194-
run('git', ['checkout', 'main'])
195-
run('git', ['branch', '-D', branchName])
169+
await $`git checkout main`
170+
await $`git branch -D ${branchName}`
196171
console.log('Checked out omicron main, deleted branch', branchName)

0 commit comments

Comments
 (0)