|
7 | 7 | * to build, publish, and release the Freebuff CLI to npm. |
8 | 8 | * |
9 | 9 | * Usage: |
10 | | - * bun freebuff/cli/release.ts [patch|minor|major] |
| 10 | + * bun freebuff/cli/release.ts [patch|minor|major] [--ref <commit-sha>] |
11 | 11 | * |
12 | 12 | * Requires: |
13 | 13 | * CODEBUFF_GITHUB_TOKEN environment variable |
|
16 | 16 | import { execSync } from 'child_process' |
17 | 17 |
|
18 | 18 | const args = process.argv.slice(2) |
19 | | -const versionType = args[0] || 'patch' |
| 19 | + |
| 20 | +let versionType = 'patch' |
| 21 | +let checkoutRef = '' |
| 22 | + |
| 23 | +for (let i = 0; i < args.length; i++) { |
| 24 | + if (args[i] === '--ref' && args[i + 1]) { |
| 25 | + checkoutRef = args[i + 1] |
| 26 | + i++ |
| 27 | + } else if (!args[i].startsWith('--')) { |
| 28 | + versionType = args[i] |
| 29 | + } |
| 30 | +} |
20 | 31 |
|
21 | 32 | function log(message: string) { |
22 | 33 | console.log(`${message}`) |
@@ -53,18 +64,24 @@ function checkGitHubToken() { |
53 | 64 | return token |
54 | 65 | } |
55 | 66 |
|
56 | | -async function triggerWorkflow(versionType: string) { |
| 67 | +async function triggerWorkflow(versionType: string, checkoutRef: string) { |
57 | 68 | if (!process.env.GITHUB_TOKEN) { |
58 | 69 | error('GITHUB_TOKEN environment variable is required but not set') |
59 | 70 | } |
60 | 71 |
|
61 | 72 | try { |
| 73 | + const inputs: Record<string, string> = { version_type: versionType } |
| 74 | + if (checkoutRef) { |
| 75 | + inputs.checkout_ref = checkoutRef |
| 76 | + } |
| 77 | + const payload = JSON.stringify({ ref: 'main', inputs }) |
| 78 | + |
62 | 79 | const triggerCmd = `curl -s -w "HTTP Status: %{http_code}" -X POST \ |
63 | 80 | -H "Accept: application/vnd.github.v3+json" \ |
64 | 81 | -H "Authorization: token ${process.env.GITHUB_TOKEN}" \ |
65 | 82 | -H "Content-Type: application/json" \ |
66 | 83 | https://api.github.com/repos/CodebuffAI/codebuff/actions/workflows/freebuff-release.yml/dispatches \ |
67 | | - -d '{"ref":"main","inputs":{"version_type":"${versionType}"}}'` |
| 84 | + -d '${payload}'` |
68 | 85 |
|
69 | 86 | const response = execSync(triggerCmd, { encoding: 'utf8' }) |
70 | 87 |
|
@@ -93,8 +110,11 @@ async function main() { |
93 | 110 | log('✅ Using local CODEBUFF_GITHUB_TOKEN') |
94 | 111 |
|
95 | 112 | log(`Version bump type: ${versionType}`) |
| 113 | + if (checkoutRef) { |
| 114 | + log(`Building from ref: ${checkoutRef}`) |
| 115 | + } |
96 | 116 |
|
97 | | - await triggerWorkflow(versionType) |
| 117 | + await triggerWorkflow(versionType, checkoutRef) |
98 | 118 |
|
99 | 119 | log('') |
100 | 120 | log( |
|
0 commit comments