diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml index f7180ea1ee..b9aa498962 100644 --- a/.github/workflows/beta.yml +++ b/.github/workflows/beta.yml @@ -19,16 +19,20 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Setup Bun uses: ./.github/actions/setup-bun - - name: Configure Git - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" + - name: Setup Git Committer + id: setup-git-committer + uses: ./.github/actions/setup-git-committer + with: + opencode-app-id: ${{ vars.OPENCODE_APP_ID }} + opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }} - name: Sync beta branch env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ steps.setup-git-committer.outputs.token }} run: bun script/beta.ts diff --git a/packages/opencode/script/publish.ts b/packages/opencode/script/publish.ts index 8cdeb35b40..9e3eadf87c 100755 --- a/packages/opencode/script/publish.ts +++ b/packages/opencode/script/publish.ts @@ -37,6 +37,7 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write( ), ) +/* const tasks = Object.entries(binaries).map(async ([name]) => { if (process.platform !== "win32") { await $`chmod -R 755 .`.cwd(`./dist/${name}`) @@ -52,6 +53,7 @@ const platforms = "linux/amd64,linux/arm64" const tags = [`${image}:${version}`, `${image}:${Script.channel}`] const tagFlags = tags.flatMap((t) => ["-t", t]) await $`docker buildx build --platform ${platforms} ${tagFlags} --push .` +*/ // registries if (!Script.preview) { @@ -63,6 +65,7 @@ if (!Script.preview) { const [pkgver, _subver = ""] = Script.version.split(/(-.*)/, 2) + /* // arch const binaryPkgbuild = [ "# Maintainer: dax", @@ -176,6 +179,7 @@ if (!Script.preview) { } } } + */ // Homebrew formula const homebrewFormula = [ @@ -230,8 +234,14 @@ if (!Script.preview) { "", ].join("\n") + const token = process.env.GITHUB_TOKEN + if (!token) { + console.error("GITHUB_TOKEN is required to update homebrew tap") + process.exit(1) + } + const tap = `https://x-access-token:${token}@github.com/anomalyco/homebrew-tap.git` await $`rm -rf ./dist/homebrew-tap` - await $`git clone https://${process.env["GITHUB_TOKEN"]}@github.com/sst/homebrew-tap.git ./dist/homebrew-tap` + await $`git clone ${tap} ./dist/homebrew-tap` await Bun.file("./dist/homebrew-tap/opencode.rb").write(homebrewFormula) await $`cd ./dist/homebrew-tap && git add opencode.rb` await $`cd ./dist/homebrew-tap && git commit -m "Update to v${Script.version}"` diff --git a/script/beta.ts b/script/beta.ts index eb61540fe7..7a3dfcccf4 100755 --- a/script/beta.ts +++ b/script/beta.ts @@ -2,26 +2,25 @@ interface PR { number: number - headRefName: string - headRefOid: string - createdAt: string - isDraft: boolean title: string } +interface RunResult { + exitCode: number + stdout: string + stderr: string +} + async function main() { console.log("Fetching open contributor PRs...") - const prsResult = - await $`gh pr list --label contributor --state open --json number,headRefName,headRefOid,createdAt,isDraft,title --limit 100`.nothrow() + const prsResult = await $`gh pr list --label contributor --state open --json number,title --limit 100`.nothrow() if (prsResult.exitCode !== 0) { throw new Error(`Failed to fetch PRs: ${prsResult.stderr}`) } - const allPRs: PR[] = JSON.parse(prsResult.stdout) - const prs = allPRs.filter((pr) => !pr.isDraft) - - console.log(`Found ${prs.length} open non-draft contributor PRs`) + const prs: PR[] = JSON.parse(prsResult.stdout) + console.log(`Found ${prs.length} open contributor PRs`) console.log("Fetching latest dev branch...") const fetchDev = await $`git fetch origin dev`.nothrow() @@ -41,71 +40,52 @@ async function main() { for (const pr of prs) { console.log(`\nProcessing PR #${pr.number}: ${pr.title}`) - // Fetch the PR - const fetchPR = await $`git fetch origin pull/${pr.number}/head:pr-${pr.number}`.nothrow() - if (fetchPR.exitCode !== 0) { - console.log(` Failed to fetch PR #${pr.number}, skipping`) - skipped.push({ number: pr.number, reason: "Failed to fetch" }) + console.log(" Fetching PR head...") + const fetch = await run(["git", "fetch", "origin", `pull/${pr.number}/head:pr/${pr.number}`]) + if (fetch.exitCode !== 0) { + console.log(` Failed to fetch PR head: ${fetch.stderr}`) + skipped.push({ number: pr.number, reason: `Fetch failed: ${fetch.stderr}` }) continue } - // Try to rebase onto current beta branch - console.log(` Attempting to rebase 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() + console.log(" Merging...") + const merge = await run(["git", "merge", "--no-commit", "--no-ff", `pr/${pr.number}`]) if (merge.exitCode !== 0) { - console.log(` Squash merge failed for PR #${pr.number}`) - console.log(` Error: ${merge.stderr}`) - await $`git reset --hard HEAD`.nothrow() - skipped.push({ number: pr.number, reason: `Squash merge failed: ${merge.stderr}` }) + console.log(" Failed to merge (conflicts)") + await $`git merge --abort`.nothrow() + await $`git checkout -- .`.nothrow() + 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 } const add = await $`git add -A`.nothrow() if (add.exitCode !== 0) { - console.log(` Failed to stage changes for PR #${pr.number}`) - await $`git reset --hard HEAD`.nothrow() + console.log(" Failed to stage") + await $`git checkout -- .`.nothrow() + await $`git clean -fd`.nothrow() skipped.push({ number: pr.number, reason: "Failed to stage" }) 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 commit = await Bun.spawn(["git", "commit", "-m", commitMsg], { stdout: "pipe", stderr: "pipe" }) - const commitExit = await commit.exited - const commitStderr = await Bun.readableStreamToText(commit.stderr) - - if (commitExit !== 0) { - console.log(` Failed to commit PR #${pr.number}`) - console.log(` Error: ${commitStderr}`) - await $`git reset --hard HEAD`.nothrow() - skipped.push({ number: pr.number, reason: `Commit failed: ${commitStderr}` }) + const commit = await run(["git", "commit", "-m", commitMsg]) + if (commit.exitCode !== 0) { + console.log(` Failed to commit: ${commit.stderr}`) + await $`git checkout -- .`.nothrow() + await $`git clean -fd`.nothrow() + skipped.push({ number: pr.number, reason: `Commit failed: ${commit.stderr}` }) continue } - console.log(` Successfully applied PR #${pr.number}`) + console.log(" Applied successfully") applied.push(pr.number) } @@ -116,7 +96,7 @@ async function main() { skipped.forEach((x) => console.log(` - PR #${x.number}: ${x.reason}`)) 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) { throw new Error(`Failed to push beta branch: ${push.stderr}`) } @@ -129,6 +109,18 @@ main().catch((err) => { process.exit(1) }) +async function run(args: string[], stdin?: Uint8Array): Promise { + 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[]) { const cmd = strings.reduce((acc, str, i) => acc + str + (values[i] ?? ""), "") return { diff --git a/script/publish.ts b/script/publish.ts index 84abe6a66a..1294f8d793 100755 --- a/script/publish.ts +++ b/script/publish.ts @@ -63,6 +63,7 @@ if (Script.release) { await $`git cherry-pick HEAD..origin/dev`.nothrow() await $`git push origin HEAD --tags --no-verify --force-with-lease` await new Promise((resolve) => setTimeout(resolve, 5_000)) + await $`gh release edit v${Script.version} --draft=false` } console.log("\n=== cli ===\n")