|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const { execSync } = require('child_process') |
| 4 | + |
| 5 | +function log(message: string) { |
| 6 | + console.log(`${message}`) |
| 7 | +} |
| 8 | + |
| 9 | +function error(message: string) { |
| 10 | + console.error(`❌ ${message}`) |
| 11 | + process.exit(1) |
| 12 | +} |
| 13 | + |
| 14 | +function checkGitHubToken() { |
| 15 | + const token = process.env.CODEBUFF_GITHUB_TOKEN |
| 16 | + if (!token) { |
| 17 | + error( |
| 18 | + 'CODEBUFF_GITHUB_TOKEN environment variable is required but not set.\n' + |
| 19 | + 'Please set it with your GitHub personal access token or use the infisical setup.' |
| 20 | + ) |
| 21 | + } |
| 22 | + return token |
| 23 | +} |
| 24 | + |
| 25 | +function getCurrentBranch(): string { |
| 26 | + try { |
| 27 | + return execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim() |
| 28 | + } catch { |
| 29 | + return 'main' |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +async function triggerWorkflow(token: string, branch: string) { |
| 34 | + try { |
| 35 | + const triggerCmd = `curl -s -w "HTTP Status: %{http_code}" -X POST \ |
| 36 | + -H "Accept: application/vnd.github.v3+json" \ |
| 37 | + -H "Authorization: token ${token}" \ |
| 38 | + -H "Content-Type: application/json" \ |
| 39 | + https://api.github.com/repos/CodebuffAI/codebuff/actions/workflows/buffbench.yml/dispatches \ |
| 40 | + -d '{"ref":"${branch}"}'` |
| 41 | + |
| 42 | + const response = execSync(triggerCmd, { encoding: 'utf8' }) |
| 43 | + |
| 44 | + if (response.includes('workflow_dispatch')) { |
| 45 | + log(`⚠️ Workflow dispatch failed: ${response}`) |
| 46 | + log( |
| 47 | + 'Please manually trigger the workflow at: https://github.com/CodebuffAI/codebuff/actions/workflows/buffbench.yml', |
| 48 | + ) |
| 49 | + } else { |
| 50 | + log('🎉 BuffBench workflow triggered!') |
| 51 | + } |
| 52 | + } catch (err: any) { |
| 53 | + log(`⚠️ Failed to trigger workflow automatically: ${err.message}`) |
| 54 | + log( |
| 55 | + 'You may need to trigger it manually at: https://github.com/CodebuffAI/codebuff/actions/workflows/buffbench.yml', |
| 56 | + ) |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +async function main() { |
| 61 | + const branch = process.argv[2] || getCurrentBranch() |
| 62 | + |
| 63 | + log('🧪 Triggering BuffBench workflow...') |
| 64 | + log(`Branch: ${branch}`) |
| 65 | + |
| 66 | + const token = checkGitHubToken() |
| 67 | + if (!token) return |
| 68 | + log('✅ Using CODEBUFF_GITHUB_TOKEN') |
| 69 | + |
| 70 | + await triggerWorkflow(token, branch) |
| 71 | + |
| 72 | + log('') |
| 73 | + log('Monitor progress at: https://github.com/CodebuffAI/codebuff/actions/workflows/buffbench.yml') |
| 74 | +} |
| 75 | + |
| 76 | +main().catch((err) => { |
| 77 | + error(`Failed to trigger BuffBench: ${err.message}`) |
| 78 | +}) |
0 commit comments