Repository URL to install this package:
|
Version:
1.3.2 ▾
|
const inquirer = require('inquirer');
const chalk = require('chalk');
const open = require('open');
const ora = require('ora');
const { table } = require('table');
const { CONFIG_GITHUB_TOKEN_KEY, TAGFLOW_PROJECTS, CONFIG_DEBUG_MODE_KEY, NAMESPACES } = require('../constants');
const { createOrUpdateTag, getRecentDeploymentTags } = require('../apis/github');
module.exports = async config => {
if (!config[CONFIG_GITHUB_TOKEN_KEY]) {
console.log(chalk.red('You need to have a PAT in your configuration file'));
console.log(`Run ${chalk.yellow('doodle init')} to save your PAT`);
process.exit(1);
}
try {
const repositoryAnswer = await inquirer.prompt([
{
type: 'list',
name: 'repo',
message: 'Which repository do you want to deploy?:',
choices: config[CONFIG_DEBUG_MODE_KEY] ? [...TAGFLOW_PROJECTS, 'doodle-node-cli'] : TAGFLOW_PROJECTS,
},
]);
const namespaceAnswer = await inquirer.prompt([
{
type: 'list',
name: 'target',
message: 'Which namespace do you want to deploy to?:',
choices: NAMESPACES,
},
]);
const branchAnswer = await inquirer.prompt([
{
type: 'input',
name: 'branch',
message: 'Which branch do you want to deploy?:',
},
]);
const userWantsToSeeRecentTags = await inquirer.prompt([
{
type: 'confirm',
name: 'seeRecentTags',
message: 'Do you want to see the most recent deployments (tags)?:',
default: false,
},
]);
if (userWantsToSeeRecentTags.seeRecentTags) {
const tableHeader = ['Tag name', 'Tag commit SHA'];
const recentTags = await getRecentDeploymentTags(config[CONFIG_GITHUB_TOKEN_KEY], repositoryAnswer.repository);
const preparedData = [tableHeader, ...recentTags];
console.log(table(preparedData));
const continueAnswer = await inquirer.prompt([
{
type: 'confirm',
name: 'continueToRelease',
message: `Do you want to continue with the release (${chalk.red(
repositoryAnswer.repository
)} @ ${chalk.yellow(branchAnswer.branch)} in ${chalk.green(namespaceAnswer.namespace)})?:`,
default: false,
},
]);
if (!continueAnswer.continueToRelease) {
console.log(chalk.red('Release aborted'));
process.exit(1);
}
}
const spinner = ora('Creating tag...');
const tagName = `dtn.${namespaceAnswer.namespace}`;
await createOrUpdateTag(config[CONFIG_GITHUB_TOKEN_KEY], repositoryAnswer.repository, tagName, branchAnswer.branch);
spinner.succeed();
open(`https://builder.internal.doodle-test.com/job/${repositoryAnswer.repository}/view/tags/job/${tagName}/`);
process.exit(0);
} catch (err) {
console.log(chalk.red(err));
}
};