summaryrefslogtreecommitdiffhomepage
path: root/script
diff options
context:
space:
mode:
authorDavid Hill <[email protected]>2025-11-10 13:44:12 +0000
committerDavid Hill <[email protected]>2025-11-10 13:44:12 +0000
commitc6e830c954418808dc39284a1c073aa63a6d4d21 (patch)
tree9c3052e0509115188768a553c0be5a8441ebdd96 /script
parent7088bfabd773e2f076aab1c9d2468c04feff0570 (diff)
parentfc78c28df64383a9f99382093f61fc28caf6569f (diff)
downloadopencode-c6e830c954418808dc39284a1c073aa63a6d4d21.tar.gz
opencode-c6e830c954418808dc39284a1c073aa63a6d4d21.zip
Merge branch 'dev' of https://github.com/sst/opencode into dev
Diffstat (limited to 'script')
-rwxr-xr-xscript/format.ts2
-rwxr-xr-xscript/publish.ts10
-rwxr-xr-xscript/sync-zed.ts120
3 files changed, 130 insertions, 2 deletions
diff --git a/script/format.ts b/script/format.ts
index c09809737..f5a54a57f 100755
--- a/script/format.ts
+++ b/script/format.ts
@@ -2,7 +2,7 @@
import { $ } from "bun"
-await $`bun run prettier --ignore-unknown --write`
+await $`bun run prettier --ignore-unknown --write .`
if (process.env["CI"] && (await $`git status --porcelain`.text())) {
await $`git config --local user.email "[email protected]"`
diff --git a/script/publish.ts b/script/publish.ts
index 307755a1c..6dc0d9afc 100755
--- a/script/publish.ts
+++ b/script/publish.ts
@@ -21,7 +21,7 @@ if (!Script.preview) {
const commits = log
.split("\n")
- .filter((line) => line && !line.match(/^\w+ (ignore:|test:|chore:)/i))
+ .filter((line) => line && !line.match(/^\w+ (ignore:|test:|chore:|ci:)/i))
.join("\n")
const opencode = await createOpencode()
@@ -83,6 +83,14 @@ for (const file of pkgjsons) {
console.log("updated:", file)
await Bun.file(file).write(pkg)
}
+
+const extensionToml = new URL("../packages/extensions/zed/extension.toml", import.meta.url).pathname
+let toml = await Bun.file(extensionToml).text()
+toml = toml.replace(/^version = "[^"]+"/m, `version = "${Script.version}"`)
+toml = toml.replaceAll(/releases\/download\/v[^/]+\//g, `releases/download/v${Script.version}/`)
+console.log("updated:", extensionToml)
+await Bun.file(extensionToml).write(toml)
+
await $`bun install`
console.log("\n=== opencode ===\n")
diff --git a/script/sync-zed.ts b/script/sync-zed.ts
new file mode 100755
index 000000000..6b4b4c7bb
--- /dev/null
+++ b/script/sync-zed.ts
@@ -0,0 +1,120 @@
+#!/usr/bin/env bun
+
+import { $ } from "bun"
+import { tmpdir } from "os"
+import { join } from "path"
+
+const FORK_REPO = "sst/zed-extensions"
+const UPSTREAM_REPO = "zed-industries/extensions"
+const EXTENSION_NAME = "opencode"
+const OPENCODE_REPO = "sst/opencode"
+
+async function main() {
+ const version = process.argv[2]
+ if (!version) throw new Error("Version argument required: bun script/sync-zed.ts v1.0.52")
+
+ const token = process.env.GITHUB_TOKEN
+ if (!token) throw new Error("GITHUB_TOKEN environment variable required")
+
+ const cleanVersion = version.replace(/^v/, "")
+ console.log(`📦 Syncing Zed extension for version ${cleanVersion}`)
+
+ const commitSha = await $`git rev-parse ${version}`.text()
+ const sha = commitSha.trim()
+ console.log(`🔍 Found commit SHA: ${sha}`)
+
+ const extensionToml = await $`git show ${version}:packages/extensions/zed/extension.toml`.text()
+ const parsed = Bun.TOML.parse(extensionToml) as { version: string }
+ const extensionVersion = parsed.version
+
+ if (extensionVersion !== cleanVersion) {
+ throw new Error(`Version mismatch: extension.toml has ${extensionVersion} but tag is ${cleanVersion}`)
+ }
+ console.log(`✅ Version ${extensionVersion} matches tag`)
+
+ // Clone the fork to a temp directory
+ const workDir = join(tmpdir(), `zed-extensions-${Date.now()}`)
+ console.log(`📁 Working in ${workDir}`)
+
+ await $`git clone https://x-access-token:${token}@github.com/${FORK_REPO}.git ${workDir}`
+ process.chdir(workDir)
+
+ // Configure git identity
+ await $`git config user.name "github-actions[bot]"`
+ await $`git config user.email "github-actions[bot]@users.noreply.github.com"`
+
+ // Sync fork with upstream
+ console.log(`🔄 Syncing fork with upstream...`)
+ await $`git remote add upstream https://github.com/${UPSTREAM_REPO}.git`
+ await $`git fetch upstream`
+ await $`git checkout main`
+ await $`git merge upstream/main --ff-only`
+ await $`git push origin main`
+ console.log(`✅ Fork synced`)
+
+ // Create a new branch
+ const branchName = `update-${EXTENSION_NAME}-${cleanVersion}`
+ console.log(`🌿 Creating branch ${branchName}`)
+ await $`git checkout -b ${branchName}`
+
+ const submodulePath = `extensions/${EXTENSION_NAME}`
+ console.log(`📌 Updating submodule to commit ${sha}`)
+ await $`git submodule update --init ${submodulePath}`
+ process.chdir(submodulePath)
+ await $`git fetch`
+ await $`git checkout ${sha}`
+ process.chdir(workDir)
+ await $`git add ${submodulePath}`
+
+ console.log(`📝 Updating extensions.toml`)
+ const extensionsTomlPath = "extensions.toml"
+ const extensionsToml = await Bun.file(extensionsTomlPath).text()
+
+ const versionRegex = new RegExp(`(\\[${EXTENSION_NAME}\\][\\s\\S]*?)version = "[^"]+"`)
+ const updatedToml = extensionsToml.replace(versionRegex, `$1version = "${cleanVersion}"`)
+
+ if (updatedToml === extensionsToml) {
+ throw new Error(`Failed to update version in extensions.toml - pattern not found`)
+ }
+
+ await Bun.write(extensionsTomlPath, updatedToml)
+ await $`git add extensions.toml`
+
+ const commitMessage = `Update ${EXTENSION_NAME} to v${cleanVersion}`
+
+ await $`git commit -m ${commitMessage}`
+ console.log(`✅ Changes committed`)
+
+ // Delete any existing branches for opencode updates
+ console.log(`🔍 Checking for existing branches...`)
+ const branches = await $`git ls-remote --heads https://x-access-token:${token}@github.com/${FORK_REPO}.git`.text()
+ const branchPattern = `refs/heads/update-${EXTENSION_NAME}-`
+ const oldBranches = branches
+ .split("\n")
+ .filter((line) => line.includes(branchPattern))
+ .map((line) => line.split("refs/heads/")[1])
+ .filter(Boolean)
+
+ if (oldBranches.length > 0) {
+ console.log(`🗑️ Found ${oldBranches.length} old branch(es), deleting...`)
+ for (const branch of oldBranches) {
+ await $`git push https://x-access-token:${token}@github.com/${FORK_REPO}.git --delete ${branch}`
+ console.log(`✅ Deleted branch ${branch}`)
+ }
+ }
+
+ console.log(`🚀 Pushing to fork...`)
+ await $`git push https://x-access-token:${token}@github.com/${FORK_REPO}.git ${branchName}`
+
+ console.log(`📬 Creating pull request...`)
+ const prUrl =
+ await $`gh pr create --repo ${UPSTREAM_REPO} --base main --head ${FORK_REPO.split("/")[0]}:${branchName} --title "Update ${EXTENSION_NAME} to v${cleanVersion}" --body "Release notes:\n\nhttps://github.com/${OPENCODE_REPO}/releases/tag/v${cleanVersion}"`.text()
+
+ console.log(`✅ Pull request created: ${prUrl}`)
+ console.log(`🎉 Done!`)
+}
+
+main().catch((err) => {
+ console.error("❌ Error:", err.message)
+ process.exit(1)
+})