Merge branch 'dev' into sqlite2
This commit is contained in:
commit
d6fbd255b6
2 changed files with 58 additions and 62 deletions
14
.github/workflows/beta.yml
vendored
14
.github/workflows/beta.yml
vendored
|
|
@ -19,16 +19,20 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup Bun
|
- name: Setup Bun
|
||||||
uses: ./.github/actions/setup-bun
|
uses: ./.github/actions/setup-bun
|
||||||
|
|
||||||
- name: Configure Git
|
- name: Setup Git Committer
|
||||||
run: |
|
id: setup-git-committer
|
||||||
git config user.name "github-actions[bot]"
|
uses: ./.github/actions/setup-git-committer
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
with:
|
||||||
|
opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
|
||||||
|
opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
|
||||||
|
|
||||||
- name: Sync beta branch
|
- name: Sync beta branch
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ steps.setup-git-committer.outputs.token }}
|
||||||
run: bun script/beta.ts
|
run: bun script/beta.ts
|
||||||
|
|
|
||||||
110
script/beta.ts
110
script/beta.ts
|
|
@ -2,26 +2,25 @@
|
||||||
|
|
||||||
interface PR {
|
interface PR {
|
||||||
number: number
|
number: number
|
||||||
headRefName: string
|
|
||||||
headRefOid: string
|
|
||||||
createdAt: string
|
|
||||||
isDraft: boolean
|
|
||||||
title: string
|
title: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface RunResult {
|
||||||
|
exitCode: number
|
||||||
|
stdout: string
|
||||||
|
stderr: string
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log("Fetching open contributor PRs...")
|
console.log("Fetching open contributor PRs...")
|
||||||
|
|
||||||
const prsResult =
|
const prsResult = await $`gh pr list --label contributor --state open --json number,title --limit 100`.nothrow()
|
||||||
await $`gh pr list --label contributor --state open --json number,headRefName,headRefOid,createdAt,isDraft,title --limit 100`.nothrow()
|
|
||||||
if (prsResult.exitCode !== 0) {
|
if (prsResult.exitCode !== 0) {
|
||||||
throw new Error(`Failed to fetch PRs: ${prsResult.stderr}`)
|
throw new Error(`Failed to fetch PRs: ${prsResult.stderr}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const allPRs: PR[] = JSON.parse(prsResult.stdout)
|
const prs: PR[] = JSON.parse(prsResult.stdout)
|
||||||
const prs = allPRs.filter((pr) => !pr.isDraft)
|
console.log(`Found ${prs.length} open contributor PRs`)
|
||||||
|
|
||||||
console.log(`Found ${prs.length} open non-draft contributor PRs`)
|
|
||||||
|
|
||||||
console.log("Fetching latest dev branch...")
|
console.log("Fetching latest dev branch...")
|
||||||
const fetchDev = await $`git fetch origin dev`.nothrow()
|
const fetchDev = await $`git fetch origin dev`.nothrow()
|
||||||
|
|
@ -41,71 +40,52 @@ async function main() {
|
||||||
for (const pr of prs) {
|
for (const pr of prs) {
|
||||||
console.log(`\nProcessing PR #${pr.number}: ${pr.title}`)
|
console.log(`\nProcessing PR #${pr.number}: ${pr.title}`)
|
||||||
|
|
||||||
// Fetch the PR
|
console.log(" Fetching PR head...")
|
||||||
const fetchPR = await $`git fetch origin pull/${pr.number}/head:pr-${pr.number}`.nothrow()
|
const fetch = await run(["git", "fetch", "origin", `pull/${pr.number}/head:pr/${pr.number}`])
|
||||||
if (fetchPR.exitCode !== 0) {
|
if (fetch.exitCode !== 0) {
|
||||||
console.log(` Failed to fetch PR #${pr.number}, skipping`)
|
console.log(` Failed to fetch PR head: ${fetch.stderr}`)
|
||||||
skipped.push({ number: pr.number, reason: "Failed to fetch" })
|
skipped.push({ number: pr.number, reason: `Fetch failed: ${fetch.stderr}` })
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to rebase onto current beta branch
|
console.log(" Merging...")
|
||||||
console.log(` Attempting to rebase PR #${pr.number}...`)
|
const merge = await run(["git", "merge", "--no-commit", "--no-ff", `pr/${pr.number}`])
|
||||||
const rebase = await $`git rebase beta pr-${pr.number}`.nothrow()
|
|
||||||
if (rebase.exitCode !== 0) {
|
|
||||||
console.log(` Rebase failed for PR #${pr.number} (has conflicts)`)
|
|
||||||
await $`git rebase --abort`.nothrow()
|
|
||||||
await $`git checkout beta`.nothrow()
|
|
||||||
skipped.push({ number: pr.number, reason: "Rebase failed (conflicts)" })
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move rebased commits to pr-${pr.number} branch and checkout back to beta
|
|
||||||
await $`git checkout -B pr-${pr.number}`.nothrow()
|
|
||||||
await $`git checkout beta`.nothrow()
|
|
||||||
|
|
||||||
console.log(` Successfully rebased PR #${pr.number}`)
|
|
||||||
|
|
||||||
// Now squash merge the rebased PR
|
|
||||||
const merge = await $`git merge --squash pr-${pr.number}`.nothrow()
|
|
||||||
if (merge.exitCode !== 0) {
|
if (merge.exitCode !== 0) {
|
||||||
console.log(` Squash merge failed for PR #${pr.number}`)
|
console.log(" Failed to merge (conflicts)")
|
||||||
console.log(` Error: ${merge.stderr}`)
|
await $`git merge --abort`.nothrow()
|
||||||
await $`git reset --hard HEAD`.nothrow()
|
await $`git checkout -- .`.nothrow()
|
||||||
skipped.push({ number: pr.number, reason: `Squash merge failed: ${merge.stderr}` })
|
await $`git clean -fd`.nothrow()
|
||||||
|
skipped.push({ number: pr.number, reason: "Has conflicts" })
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const mergeHead = await $`git rev-parse -q --verify MERGE_HEAD`.nothrow()
|
||||||
|
if (mergeHead.exitCode !== 0) {
|
||||||
|
console.log(" No changes, skipping")
|
||||||
|
skipped.push({ number: pr.number, reason: "No changes" })
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const add = await $`git add -A`.nothrow()
|
const add = await $`git add -A`.nothrow()
|
||||||
if (add.exitCode !== 0) {
|
if (add.exitCode !== 0) {
|
||||||
console.log(` Failed to stage changes for PR #${pr.number}`)
|
console.log(" Failed to stage")
|
||||||
await $`git reset --hard HEAD`.nothrow()
|
await $`git checkout -- .`.nothrow()
|
||||||
|
await $`git clean -fd`.nothrow()
|
||||||
skipped.push({ number: pr.number, reason: "Failed to stage" })
|
skipped.push({ number: pr.number, reason: "Failed to stage" })
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = await $`git status --porcelain`.nothrow()
|
|
||||||
if (status.exitCode !== 0 || !status.stdout.trim()) {
|
|
||||||
console.log(` No changes to commit for PR #${pr.number}, skipping`)
|
|
||||||
await $`git reset --hard HEAD`.nothrow()
|
|
||||||
skipped.push({ number: pr.number, reason: "No changes to commit" })
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const commitMsg = `Apply PR #${pr.number}: ${pr.title}`
|
const commitMsg = `Apply PR #${pr.number}: ${pr.title}`
|
||||||
const commit = await Bun.spawn(["git", "commit", "-m", commitMsg], { stdout: "pipe", stderr: "pipe" })
|
const commit = await run(["git", "commit", "-m", commitMsg])
|
||||||
const commitExit = await commit.exited
|
if (commit.exitCode !== 0) {
|
||||||
const commitStderr = await Bun.readableStreamToText(commit.stderr)
|
console.log(` Failed to commit: ${commit.stderr}`)
|
||||||
|
await $`git checkout -- .`.nothrow()
|
||||||
if (commitExit !== 0) {
|
await $`git clean -fd`.nothrow()
|
||||||
console.log(` Failed to commit PR #${pr.number}`)
|
skipped.push({ number: pr.number, reason: `Commit failed: ${commit.stderr}` })
|
||||||
console.log(` Error: ${commitStderr}`)
|
|
||||||
await $`git reset --hard HEAD`.nothrow()
|
|
||||||
skipped.push({ number: pr.number, reason: `Commit failed: ${commitStderr}` })
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(` Successfully applied PR #${pr.number}`)
|
console.log(" Applied successfully")
|
||||||
applied.push(pr.number)
|
applied.push(pr.number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +96,7 @@ async function main() {
|
||||||
skipped.forEach((x) => console.log(` - PR #${x.number}: ${x.reason}`))
|
skipped.forEach((x) => console.log(` - PR #${x.number}: ${x.reason}`))
|
||||||
|
|
||||||
console.log("\nForce pushing beta branch...")
|
console.log("\nForce pushing beta branch...")
|
||||||
const push = await $`git push origin beta --force`.nothrow()
|
const push = await $`git push origin beta --force --no-verify`.nothrow()
|
||||||
if (push.exitCode !== 0) {
|
if (push.exitCode !== 0) {
|
||||||
throw new Error(`Failed to push beta branch: ${push.stderr}`)
|
throw new Error(`Failed to push beta branch: ${push.stderr}`)
|
||||||
}
|
}
|
||||||
|
|
@ -129,6 +109,18 @@ main().catch((err) => {
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async function run(args: string[], stdin?: Uint8Array): Promise<RunResult> {
|
||||||
|
const proc = Bun.spawn(args, {
|
||||||
|
stdin: stdin ?? "inherit",
|
||||||
|
stdout: "pipe",
|
||||||
|
stderr: "pipe",
|
||||||
|
})
|
||||||
|
const exitCode = await proc.exited
|
||||||
|
const stdout = await new Response(proc.stdout).text()
|
||||||
|
const stderr = await new Response(proc.stderr).text()
|
||||||
|
return { exitCode, stdout, stderr }
|
||||||
|
}
|
||||||
|
|
||||||
function $(strings: TemplateStringsArray, ...values: unknown[]) {
|
function $(strings: TemplateStringsArray, ...values: unknown[]) {
|
||||||
const cmd = strings.reduce((acc, str, i) => acc + str + (values[i] ?? ""), "")
|
const cmd = strings.reduce((acc, str, i) => acc + str + (values[i] ?? ""), "")
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue