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 release promotion step #402

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
58 changes: 48 additions & 10 deletions components/git/release.js
Expand Up @@ -2,12 +2,17 @@

const yargs = require('yargs');

const auth = require('../../lib/auth');
const CLI = require('../../lib/cli');
const ReleasePreparation = require('../../lib/prepare_release');
const ReleasePromotion = require('../../lib/promote_release');
const TeamInfo = require('../../lib/team_info');
const Request = require('../../lib/request');
const { runPromise } = require('../../lib/run');

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

const releaseOptions = {
prepare: {
Expand All @@ -21,16 +26,25 @@ const releaseOptions = {
security: {
describe: 'Demarcate the new security release as a security release',
type: 'boolean'
},
newVersion: {
describe: 'Version number of the release to be prepared',
type: 'string'
}
};

function builder(yargs) {
return yargs
.options(releaseOptions).positional('newVersion', {
describe: 'Version number of the release to be prepared or promoted'
.options(releaseOptions).positional('prid', {
describe: 'PR number of the release to be promoted',
type: 'number'
})
.example('git node release --prepare 1.2.3',
'Prepare a new release of Node.js tagged v1.2.3');
.example('git node release --prepare --security',
'Prepare a new security release of Node.js with auto-determined version')
.example('git node release --prepare --newVersion=1.2.3',
'Prepare a new release of Node.js tagged v1.2.3')
.example('git node release --promote 12345',
'Promote a prepared release of Node.js with PR #12345');
}

function handler(argv) {
Expand Down Expand Up @@ -59,23 +73,25 @@ function release(state, argv) {
}

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

async function main(state, argv, cli, dir) {
let release;

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

if (prep.warnForWrongBranch()) return;
if (release.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}?`,
`Create release with new version ${release.newVersion}?`,
{ defaultAnswer: true });

if (!create) {
Expand All @@ -84,8 +100,30 @@ async function main(state, argv, cli, dir) {
}
}

return prep.prepare();
return release.prepare();
} else if (state === PROMOTE) {
// TODO(codebytere): implement release promotion.
release = new ReleasePromotion(argv, cli, dir);

cli.startSpinner('Verifying Releaser status');
const credentials = await auth({ github: true });
const request = new Request(credentials);
const info = new TeamInfo(cli, request, 'nodejs', RELEASERS);

const releasers = await info.getMembers();
if (release.username === undefined) {
cli.stopSpinner('Failed to verify Releaser status');
cli.info(
'Username was undefined - do you have your .ncurc set up correctly?');
return;
} else {
if (!releasers.some(r => r.login === release.username)) {
cli.stopSpinner(
`${release.username} is not a Releaser; aborting release`);
return;
}
cli.stopSpinner('Verified Releaser status');
}
Comment on lines +118 to +125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
} else {
if (!releasers.some(r => r.login === release.username)) {
cli.stopSpinner(
`${release.username} is not a Releaser; aborting release`);
return;
}
cli.stopSpinner('Verified Releaser status');
}
} else if (releasers.every(r => r.login !== release.username)) {
cli.stopSpinner(
`${release.username} is not a Releaser; aborting release`);
return;
}
cli.stopSpinner('Verified Releaser status');


return release.promote();
}
}