fix: validate beta before pushing (#24230)

This commit is contained in:
Luke Parker
2026-04-25 10:32:41 +10:00
committed by GitHub
parent 1e4b7b5451
commit 386091b79a

View File

@@ -81,6 +81,39 @@ async function build() {
} }
} }
async function validate() {
if (!(await typecheck())) return false
if (!(await build())) return false
return true
}
async function commitSmokeChanges() {
const out = await $`git status --porcelain`.text()
if (!out.trim()) {
console.log("Smoke check passed")
return true
}
try {
await $`git add -A`
await $`git commit -m "Fix beta integration"`
} catch (err) {
console.log(`Failed to commit smoke fixes: ${err}`)
return false
}
if (!(await validate())) return false
const left = await $`git status --porcelain`.text()
if (!left.trim()) {
console.log("Smoke check passed")
return true
}
console.log(`Smoke check left uncommitted changes:\n${left}`)
return false
}
async function install() { async function install() {
console.log(" Regenerating bun.lock...") console.log(" Regenerating bun.lock...")
@@ -143,11 +176,15 @@ async function fix(pr: PR, files: string[], prs: PR[], applied: number[], idx: n
} }
async function smoke(prs: PR[], applied: number[]) { async function smoke(prs: PR[], applied: number[]) {
console.log("\nRunning final smoke check with opencode...") console.log("\nRunning final smoke check...")
if (await validate()) return commitSmokeChanges()
console.log("\nTrying to fix final smoke check with opencode...")
const done = lines(prs.filter((x) => applied.includes(x.number))) const done = lines(prs.filter((x) => applied.includes(x.number)))
const prompt = [ const prompt = [
"The beta merge batch is complete.", "The beta merge batch is complete, but the deterministic final smoke check failed.",
`Merged PRs on HEAD:\n${done}`, `Merged PRs on HEAD:\n${done}`,
"Run `bun typecheck` at the repo root.", "Run `bun typecheck` at the repo root.",
"Run `./script/build.ts --single` in `packages/opencode`.", "Run `./script/build.ts --single` in `packages/opencode`.",
@@ -162,38 +199,8 @@ async function smoke(prs: PR[], applied: number[]) {
return false return false
} }
if (!(await typecheck())) { if (!(await validate())) return false
return false return commitSmokeChanges()
}
if (!(await build())) {
return false
}
const out = await $`git status --porcelain`.text()
if (!out.trim()) {
console.log("Smoke check passed")
return true
}
try {
await $`git add -A`
await $`git commit -m "Fix beta integration"`
} catch (err) {
console.log(`Failed to commit smoke fixes: ${err}`)
return false
}
if (!(await typecheck())) {
return false
}
if (!(await build())) {
return false
}
console.log("Smoke check passed")
return true
} }
async function main() { async function main() {
@@ -294,17 +301,13 @@ async function main() {
throw new Error(`${failed.length} PR(s) failed to merge`) throw new Error(`${failed.length} PR(s) failed to merge`)
} }
if (applied.length > 0) {
console.log("\nSkipping final smoke check")
}
console.log("\nChecking if beta branch has changes...") console.log("\nChecking if beta branch has changes...")
await $`git fetch origin beta` await $`git fetch origin beta`
const localTree = await $`git rev-parse beta^{tree}`.text() const localTree = (await $`git rev-parse beta^{tree}`.text()).trim()
const remoteTrees = (await $`git log origin/dev..origin/beta --format=%T`.text()).split("\n") const remoteTrees = (await $`git log origin/dev..origin/beta --format=%T`.text()).split("\n")
const matchIdx = remoteTrees.indexOf(localTree.trim()) const matchIdx = remoteTrees.indexOf(localTree)
if (matchIdx !== -1) { if (matchIdx !== -1) {
if (matchIdx !== 0) { if (matchIdx !== 0) {
console.log(`Beta branch contains this sync, but additional commits exist after it. Leaving beta branch as is.`) console.log(`Beta branch contains this sync, but additional commits exist after it. Leaving beta branch as is.`)
@@ -314,7 +317,23 @@ async function main() {
return return
} }
console.log("Force pushing beta branch...") if (!(await smoke(prs, applied))) throw new Error("Final smoke check failed")
await $`git fetch origin beta`
const validatedTree = (await $`git rev-parse beta^{tree}`.text()).trim()
const remoteTreesAfterSmoke = (await $`git log origin/dev..origin/beta --format=%T`.text()).split("\n")
const matchIdxAfterSmoke = remoteTreesAfterSmoke.indexOf(validatedTree)
if (matchIdxAfterSmoke !== -1) {
if (matchIdxAfterSmoke !== 0) {
console.log(`Beta branch contains this validated sync, but additional commits exist after it. Leaving beta branch as is.`)
} else {
console.log("Validated beta branch now matches remote contents, no push needed")
}
return
}
console.log("Force pushing validated beta branch...")
await $`git push origin beta --force --no-verify` await $`git push origin beta --force --no-verify`
console.log("Successfully synced beta branch") console.log("Successfully synced beta branch")