Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 8887616

Browse files
committed
ci: sync zed
1 parent 905c034 commit 8887616

2 files changed

Lines changed: 118 additions & 10 deletions

File tree

.github/workflows/sync-zed-extension.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14-
if: github.event_name == 'workflow_dispatch'
1514
with:
1615
fetch-depth: 0
1716

18-
- name: Get latest version tag
19-
if: github.event_name == 'workflow_dispatch'
17+
- uses: ./.github/actions/setup-bun
18+
19+
- name: Get version tag
2020
id: get_tag
2121
run: |
22-
TAG=$(git tag --list 'v[0-9]*.*' --sort=-version:refname | head -n 1)
22+
if [ "${{ github.event_name }}" = "release" ]; then
23+
TAG="${{ github.event.release.tag_name }}"
24+
else
25+
TAG=$(git tag --list 'v[0-9]*.*' --sort=-version:refname | head -n 1)
26+
fi
2327
echo "tag=${TAG}" >> $GITHUB_OUTPUT
2428
echo "Using tag: ${TAG}"
2529
26-
- uses: huacnlee/zed-extension-action@6a168731f1d994905eeb552b3b42b0cb6c4d12e6
27-
with:
28-
extension-name: opencode
29-
push-to: sst/zed-extensions
30-
tag-name: ${{ github.event.release.tag_name || steps.get_tag.outputs.tag }}
30+
- name: Sync Zed extension
31+
run: |
32+
./script/sync-zed.ts ${{ steps.get_tag.outputs.tag }}
3133
env:
32-
COMMITTER_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
34+
GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}

script/sync-zed.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env bun
2+
3+
import { $ } from "bun"
4+
import { tmpdir } from "os"
5+
import { join } from "path"
6+
7+
const FORK_REPO = "sst/zed-extensions"
8+
const UPSTREAM_REPO = "zed-industries/extensions"
9+
const EXTENSION_NAME = "opencode"
10+
const OPENCODE_REPO = "sst/opencode"
11+
12+
async function main() {
13+
const version = process.argv[2]
14+
if (!version) throw new Error("Version argument required: bun script/sync-zed.ts v1.0.52")
15+
16+
const token = process.env.GITHUB_TOKEN
17+
if (!token) throw new Error("GITHUB_TOKEN environment variable required")
18+
19+
const cleanVersion = version.replace(/^v/, "")
20+
console.log(`📦 Syncing Zed extension for version ${cleanVersion}`)
21+
22+
// Get the commit SHA for this version tag
23+
const commitSha = await $`git rev-parse ${version}`.text()
24+
const sha = commitSha.trim()
25+
console.log(`🔍 Found commit SHA: ${sha}`)
26+
27+
// Read the extension.toml from this commit to verify version
28+
const extensionToml = await $`git show ${version}:packages/extensions/zed/extension.toml`.text()
29+
const parsed = Bun.TOML.parse(extensionToml) as { version: string }
30+
const extensionVersion = parsed.version
31+
32+
if (extensionVersion !== cleanVersion) {
33+
throw new Error(`Version mismatch: extension.toml has ${extensionVersion} but tag is ${cleanVersion}`)
34+
}
35+
console.log(`✅ Version ${extensionVersion} matches tag`)
36+
37+
// Clone the fork to a temp directory
38+
const workDir = join(tmpdir(), `zed-extensions-${Date.now()}`)
39+
console.log(`📁 Working in ${workDir}`)
40+
41+
await $`git clone https://x-access-token:${token}@github.com/${FORK_REPO}.git ${workDir}`
42+
process.chdir(workDir)
43+
44+
// Sync fork with upstream
45+
console.log(`🔄 Syncing fork with upstream...`)
46+
await $`git remote add upstream https://github.com/${UPSTREAM_REPO}.git`
47+
await $`git fetch upstream`
48+
await $`git checkout main`
49+
await $`git merge upstream/main --ff-only`
50+
await $`git push origin main`
51+
console.log(`✅ Fork synced`)
52+
53+
// Create a new branch
54+
const branchName = `update-${EXTENSION_NAME}-${cleanVersion}`
55+
console.log(`🌿 Creating branch ${branchName}`)
56+
await $`git checkout -b ${branchName}`
57+
58+
// Update the submodule for opencode extension
59+
const submodulePath = `extensions/${EXTENSION_NAME}`
60+
console.log(`📌 Updating submodule to commit ${sha}`)
61+
await $`git submodule update --init ${submodulePath}`
62+
process.chdir(submodulePath)
63+
await $`git fetch`
64+
await $`git checkout ${sha}`
65+
process.chdir(workDir)
66+
await $`git add ${submodulePath}`
67+
68+
// Update extensions.toml
69+
console.log(`📝 Updating extensions.toml`)
70+
const extensionsTomlPath = "extensions.toml"
71+
const extensionsToml = await Bun.file(extensionsTomlPath).text()
72+
73+
// Update version field for opencode extension
74+
const versionRegex = new RegExp(`(\\[${EXTENSION_NAME}\\]\\s+(?:.*\\s*)?)version = "[^"]+"`)
75+
const updatedToml = extensionsToml.replace(versionRegex, `$1version = "${cleanVersion}"`)
76+
77+
await Bun.write(extensionsTomlPath, updatedToml)
78+
await $`git add extensions.toml`
79+
80+
// Commit changes
81+
const commitMessage = `Update ${EXTENSION_NAME} to v${cleanVersion}
82+
83+
Release notes:
84+
85+
https://github.com/${OPENCODE_REPO}/releases/tag/v${cleanVersion}`
86+
87+
await $`git commit -m ${commitMessage}`
88+
console.log(`✅ Changes committed`)
89+
90+
// Push to fork
91+
console.log(`🚀 Pushing to fork...`)
92+
await $`git push https://x-access-token:${token}@github.com/${FORK_REPO}.git ${branchName}`
93+
94+
// Create PR using gh CLI
95+
console.log(`📬 Creating pull request...`)
96+
const prUrl =
97+
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()
98+
99+
console.log(`✅ Pull request created: ${prUrl}`)
100+
console.log(`🎉 Done!`)
101+
}
102+
103+
main().catch((err) => {
104+
console.error("❌ Error:", err.message)
105+
process.exit(1)
106+
})

0 commit comments

Comments
 (0)