Skip to content

Commit 674de85

Browse files
committed
freebuff release command
1 parent e3a3584 commit 674de85

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

freebuff/cli/release.ts

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bun
2+
3+
/**
4+
* Freebuff CLI release script.
5+
*
6+
* Triggers the freebuff-release.yml GitHub Actions workflow
7+
* to build, publish, and release the Freebuff CLI to npm.
8+
*
9+
* Usage:
10+
* bun freebuff/cli/release.ts [patch|minor|major]
11+
*
12+
* Requires:
13+
* CODEBUFF_GITHUB_TOKEN environment variable
14+
*/
15+
16+
import { execSync } from 'child_process'
17+
18+
const args = process.argv.slice(2)
19+
const versionType = args[0] || 'patch'
20+
21+
function log(message: string) {
22+
console.log(`${message}`)
23+
}
24+
25+
function error(message: string): never {
26+
console.error(`❌ ${message}`)
27+
process.exit(1)
28+
}
29+
30+
function formatTimestamp() {
31+
const now = new Date()
32+
const options = {
33+
month: 'long',
34+
day: 'numeric',
35+
hour: '2-digit',
36+
minute: '2-digit',
37+
second: '2-digit',
38+
timeZoneName: 'short',
39+
} as const
40+
return now.toLocaleDateString('en-US', options)
41+
}
42+
43+
function checkGitHubToken() {
44+
const token = process.env.CODEBUFF_GITHUB_TOKEN
45+
if (!token) {
46+
error(
47+
'CODEBUFF_GITHUB_TOKEN environment variable is required but not set.\n' +
48+
'Please set it with your GitHub personal access token or use the infisical setup.',
49+
)
50+
}
51+
52+
process.env.GITHUB_TOKEN = token
53+
return token
54+
}
55+
56+
async function triggerWorkflow(versionType: string) {
57+
if (!process.env.GITHUB_TOKEN) {
58+
error('GITHUB_TOKEN environment variable is required but not set')
59+
}
60+
61+
try {
62+
const triggerCmd = `curl -s -w "HTTP Status: %{http_code}" -X POST \
63+
-H "Accept: application/vnd.github.v3+json" \
64+
-H "Authorization: token ${process.env.GITHUB_TOKEN}" \
65+
-H "Content-Type: application/json" \
66+
https://api.github.com/repos/CodebuffAI/codebuff/actions/workflows/freebuff-release.yml/dispatches \
67+
-d '{"ref":"main","inputs":{"version_type":"${versionType}"}}'`
68+
69+
const response = execSync(triggerCmd, { encoding: 'utf8' })
70+
71+
if (response.includes('workflow_dispatch')) {
72+
log(`⚠️ Workflow dispatch failed: ${response}`)
73+
log(
74+
'Please manually trigger the workflow at: https://github.com/CodebuffAI/codebuff/actions/workflows/freebuff-release.yml',
75+
)
76+
} else {
77+
log('🎉 Freebuff release workflow triggered!')
78+
}
79+
} catch (err: unknown) {
80+
const message = err instanceof Error ? err.message : String(err)
81+
log(`⚠️ Failed to trigger workflow automatically: ${message}`)
82+
log(
83+
'You may need to trigger it manually at: https://github.com/CodebuffAI/codebuff/actions/workflows/freebuff-release.yml',
84+
)
85+
}
86+
}
87+
88+
async function main() {
89+
log('🚀 Initiating Freebuff release...')
90+
log(`Date: ${formatTimestamp()}`)
91+
92+
checkGitHubToken()
93+
log('✅ Using local CODEBUFF_GITHUB_TOKEN')
94+
95+
log(`Version bump type: ${versionType}`)
96+
97+
await triggerWorkflow(versionType)
98+
99+
log('')
100+
log(
101+
'Monitor progress at: https://github.com/CodebuffAI/codebuff/actions/workflows/freebuff-release.yml',
102+
)
103+
}
104+
105+
main().catch((err: unknown) => {
106+
const message = err instanceof Error ? err.message : String(err)
107+
error(`Release failed: ${message}`)
108+
})

freebuff/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@codebuff/freebuff",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"release": "bun cli/release.ts"
7+
}
8+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
".agents",
99
"common",
1010
"web",
11+
"freebuff",
1112
"freebuff/web",
1213
"packages/*",
1314
"scripts",
@@ -28,6 +29,7 @@
2829
"format": "prettier --write \"**/*.{ts,tsx,json,md}\"",
2930
"release:cli": "bun run --cwd=cli release",
3031
"release:sdk": "bun run --cwd=sdk release",
32+
"release:freebuff": "bun run --cwd=freebuff release",
3133
"clean-ts": "find . -name '*.tsbuildinfo' -type f -delete && find . -name '.next' -type d -exec rm -rf {} + 2>/dev/null || true && find . -name 'node_modules' -type d -exec rm -rf {} + 2>/dev/null || true && bun install",
3234
"typecheck": "bun scripts/check-env-architecture.ts && bun --filter='*' run typecheck && echo '✅ All type checks passed!'",
3335
"test": "bun --filter='{@codebuff/common,@codebuff/agents,@codebuff/agent-runtime,@codebuff/sdk,@codebuff/web,@codebuff/cli,@codebuff/evals,@codebuff/scripts}' run test",

0 commit comments

Comments
 (0)