Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions packages/kilo-vscode/script/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,22 @@ const flag = prerelease ? ["--pre-release"] : []
for (const target of targets) {
const vsixPath = join(outDir, `kilo-vscode-${target}.vsix`)
console.log(`\n🚀 Publishing ${target} to VS Code Marketplace${prerelease ? " (pre-release)" : ""}...`)
await $`vsce publish ${flag} --packagePath ${vsixPath}`
await retry(() => $`vsce publish ${flag} --skip-duplicate --packagePath ${vsixPath}`, {
attempts: 3,
delay: 30_000,
label: `vsce publish ${target}`,
})
console.log(` ✅ Published ${target} to VS Code Marketplace`)

console.log(`\n📤 Publishing ${target} to Open VSX${prerelease ? " (pre-release)" : ""}...`)
await retry(() => $`npx ovsx publish ${flag} --pat ${process.env.OPENVSX_TOKEN} --packagePath ${vsixPath}`, {
attempts: 3,
delay: 10_000,
label: `ovsx publish ${target}`,
})
await retry(
() => $`npx ovsx publish ${flag} --skip-duplicate --pat ${process.env.OPENVSX_TOKEN} --packagePath ${vsixPath}`,
{
attempts: 3,
delay: 30_000,
label: `ovsx publish ${target}`,
},
)
console.log(` ✅ Published ${target} to Open VSX`)
}

Expand All @@ -69,8 +76,9 @@ async function retry<T>(fn: () => Promise<T>, opts: { attempts: number; delay: n
return await fn()
} catch (err) {
if (i === opts.attempts) throw err
console.warn(` ⚠️ ${opts.label} failed (attempt ${i}/${opts.attempts}), retrying in ${opts.delay / 1000}s...`)
await new Promise((r) => setTimeout(r, opts.delay))
const delay = opts.delay * 2 ** (i - 1)
console.warn(` ⚠️ ${opts.label} failed (attempt ${i}/${opts.attempts}), retrying in ${delay / 1000}s...`)
await new Promise((r) => setTimeout(r, delay))
}
}
throw new Error("unreachable")
Expand Down
38 changes: 38 additions & 0 deletions packages/kilo-vscode/tests/unit/publish.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect, test } from "bun:test"
import { Project, SyntaxKind } from "ts-morph"

const project = new Project({ useInMemoryFileSystem: true })
const source = project.createSourceFile(
"publish.ts",
await Bun.file(`${import.meta.dir}/../../script/publish.ts`).text(),
)

test.each(["vsce publish", "npx ovsx publish"])("%s retries the same package and skips duplicates", (command) => {
const retry = source
.getDescendantsOfKind(SyntaxKind.CallExpression)
.find(
(call) => call.getExpression().getText() === "retry" && call.getArguments().at(0)?.getText().includes(command),
)
expect(retry).toBeDefined()

const shell = retry
?.getArguments()
.at(0)
?.asKind(SyntaxKind.ArrowFunction)
?.getBody()
.asKind(SyntaxKind.TaggedTemplateExpression)
expect(shell?.getTag().getText()).toBe("$")
expect(shell?.getTemplate().getText()).toContain("${flag} --skip-duplicate")
expect(shell?.getTemplate().getText()).toContain("--packagePath ${vsixPath}")

const options = retry?.getArguments().at(1)?.asKind(SyntaxKind.ObjectLiteralExpression)
const value = (name: string) =>
options
?.getProperty(name)
?.asKind(SyntaxKind.PropertyAssignment)
?.getInitializer()
?.asKind(SyntaxKind.NumericLiteral)
?.getLiteralValue()
expect(value("attempts")).toBe(3)
expect(value("delay")).toBe(30_000)
})
Loading