const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const githubAuth = require('../scripts/common/github-auth');
const cliArgs = githubAuth.parseGitHubCliArgs();
const config = {
autoRun: cliArgs.autoRun !== undefined ? cliArgs.autoRun : true,
yesAll: cliArgs.yesAll !== undefined ? cliArgs.yesAll : true
};
async function runCiTasks() {
console.log('GitHub CLI Authentication CI/CD Integration (JavaScript)');
console.log('======================================================');
console.log(`Auto Run: ${config.autoRun}`);
console.log(`Yes All: ${config.yesAll}`);
try {
if (!githubAuth.isGitHubCliAvailable()) {
console.error('GitHub CLI is not installed. Please configure your CI environment with GitHub CLI.');
process.exit(1);
}
if (!githubAuth.isGitHubAuthenticated(config.autoRun, config.yesAll)) {
console.error('Not authenticated with GitHub CLI and automatic login failed.');
console.error('For CI environments, configure authentication tokens or use GITHUB_TOKEN environment variable.');
process.exit(1);
}
const authInfo = githubAuth.getGitHubAuthInfo(config.autoRun, config.yesAll);
console.log(`Authenticated as: ${authInfo.username}`);
const env = githubAuth.setupMcpEnvironment({
autoRun: config.autoRun,
yesAll: config.yesAll
});
console.log('Running CI tasks that require GitHub authentication...');
const ciConfigPath = '/tmp/ci-github-config.json';
githubAuth.createMcpGithubConfig(ciConfigPath, {
autoRun: config.autoRun,
yesAll: config.yesAll
});
console.log(`CI configuration created at: ${ciConfigPath}`);
const contributionTrackerPath = path.join(__dirname, '../dao/tools/contribution-tracker.js');
if (fs.existsSync(contributionTrackerPath)) {
console.log('Running contribution tracker...');
const contributionArgs = [];
if (config.autoRun) contributionArgs.push('--auto-run');
if (config.yesAll) contributionArgs.push('--yes-all');
try {
execSync(`node ${contributionTrackerPath} ${contributionArgs.join(' ')}`, {
stdio: 'inherit'
});
} catch (error) {
console.error(`Error running contribution tracker: ${error.message}`);
}
}
console.log('CI tasks completed successfully!');
} catch (error) {
console.error(`Error: ${error.message}`);
process.exit(1);
}
}
runCiTasks();