Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-node: add git-node-release #388

Merged
merged 16 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions components/git/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use strict';

const yargs = require('yargs');

const CLI = require('../../lib/cli');
const ReleasePreparation = require('../../lib/prepare_release');
const { runPromise } = require('../../lib/run');

const PREPARE = 'prepare';
const PROMOTE = 'promote';

const releaseOptions = {
prepare: {
describe: 'Prepare a new release of Node.js',
type: 'boolean'
},
promote: {
describe: 'Promote new release of Node.js',
type: 'boolean'
},
security: {
describe: 'Demarcate the new security release as a security release',
type: 'boolean'
}
};

function builder(yargs) {
return yargs
.options(releaseOptions).positional('newVersion', {
describe: 'Version number of the release to be prepared or promoted'
})
.example('git node release --prepare 1.2.3',
'Prepare a new release of Node.js tagged v1.2.3');
}

function handler(argv) {
if (argv.prepare) {
return release(PREPARE, argv);
} else if (argv.promote) {
return release(PROMOTE, argv);
}

// If more than one action is provided or no valid action
// is provided, show help.
yargs.showHelp();
}

function release(state, argv) {
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
const cli = new CLI(logStream);
const dir = process.cwd();

return runPromise(main(state, argv, cli, dir)).catch((err) => {
if (cli.spinner.enabled) {
cli.spinner.fail();
}
throw err;
});
}

module.exports = {
command: 'release [newVersion|options]',
describe:
'Manage an in-progress release or start a new one.',
builder,
handler
};

async function main(state, argv, cli, dir) {
if (state === PREPARE) {
const prep = new ReleasePreparation(argv, cli, dir);

if (prep.warnForWrongBranch()) return;

// If the new version was automatically calculated, confirm it.
if (!argv.newVersion) {
const create = await cli.prompt(
`Create release with new version ${prep.newVersion}?`,
{ defaultAnswer: true });

if (!create) {
cli.error('Aborting release preparation process');
return;
}
}

return prep.prepare();
} else if (state === PROMOTE) {
codebytere marked this conversation as resolved.
Show resolved Hide resolved
// TODO(codebytere): implement release promotion.
}
}
Loading