Skip to content

Commit

Permalink
Split out promotion verification steps
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Apr 9, 2020
1 parent 7fcc66a commit 13191bd
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions lib/promote_release.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,55 @@ class ReleasePromotion {
}

async promote() {
const { version, prid, cli } = this;

// In the promotion stage, we can pull most relevant data
// from the release commit created in the preparation stage.
await this.parseDataFromReleaseCommit();

const { prid, cli, version } = this;

// Verify that PR is ready to promote.
cli.startSpinner('Verifying PR promotion readiness');
const {
jenkinsReady,
githubCIReady,
isApproved
} = await this.verifyPRAttributes();

cli.startSpinner('Verifying Jenkins CI status');
if (!jenkinsReady) {
cli.stopSpinner(`Jenkins CI is failing for #${prid}`);
cli.stopSpinner(
`Jenkins CI is failing for #${prid}`, cli.SPINNER_STATUS.FAILED);
const proceed = await cli.prompt('Do you want to proceed?');
if (!proceed) {
cli.warn(`Aborting release promotion for version ${version}`);
return;
}
} else if (!githubCIReady) {
cli.stopSpinner(`GitHub CI is failing for #${prid}`);
}
cli.stopSpinner('Jenkins CI is passing');

cli.startSpinner('Verifying GitHub CI status');
if (!githubCIReady) {
cli.stopSpinner(
`GitHub CI is failing for #${prid}`, cli.SPINNER_STATUS.FAILED);
const proceed = await cli.prompt('Do you want to proceed?');
if (!proceed) {
cli.warn(`Aborting release promotion for version ${version}`);
return;
}
} else if (!isApproved) {
cli.stopSpinner(`#${prid} does not have sufficient approvals`);
}
cli.stopSpinner('GitHub CI is passing');

cli.startSpinner('Verifying PR approval status');
if (!isApproved) {
cli.stopSpinner(
`#${prid} does not have sufficient approvals`,
cli.SPINNER_STATUS.FAILED);
const proceed = await cli.prompt('Do you want to proceed?');
if (!proceed) {
cli.warn(`Aborting release promotion for version ${version}`);
return;
}
}
cli.stopSpinner(`The release PR for ${version} is ready to promote!`);
cli.stopSpinner(`#${prid} has necessary approvals`);

// Create and sign the release tag.
const shouldTagAndSignRelease = await cli.prompt(
Expand All @@ -74,7 +87,7 @@ class ReleasePromotion {
// Set up for next release.
cli.startSpinner('Setting up for next release');
await this.setupForNextRelease();
cli.startSpinner('Successfully set up for next release');
cli.stopSpinner('Successfully set up for next release');

const shouldMergeProposalBranch = await cli.prompt(
'Merge proposal branch into staging branch?');
Expand All @@ -86,7 +99,7 @@ class ReleasePromotion {
// Merge vX.Y.Z-proposal into vX.x.
cli.startSpinner('Merging proposal branch');
await this.mergeProposalBranch();
cli.startSpinner('Merged proposal branch');
cli.stopSpinner('Merged proposal branch');

// Cherry pick release commit to master.
const shouldCherryPick = await cli.prompt(
Expand All @@ -95,7 +108,17 @@ class ReleasePromotion {
cli.warn(`Aborting release promotion for version ${version}`);
return;
}
await this.cherryPickToMaster();
this.cherryPickToMaster();

// There will be cherry-pick conflicts the Releaser will
// need to resolve, so confirm they've been resolved before
// proceeding with next steps.
const didResolveConflicts = await cli.prompt(
'Finished resolving cherry-pick conflicts?', { defaultAnswer: true });
if (!didResolveConflicts) {
cli.warn(`Aborting release promotion for version ${version}`);
return;
}

// Push release tag.
const shouldPushTag = await cli.prompt('Push release tag?',
Expand Down Expand Up @@ -142,7 +165,7 @@ class ReleasePromotion {
const checker = new PRChecker(cli, data, { prid, owner, repo });
const jenkinsReady = checker.checkJenkinsCI();
const githubCIReady = checker.checkGitHubCI();
const isApproved = checker.checkReviewsAndWait(false /* checkComments */);
const isApproved = checker.checkReviewsAndWait(new Date(), false);

return {
jenkinsReady,
Expand All @@ -160,7 +183,7 @@ class ReleasePromotion {
const components = releaseCommitMessage.split(' ');

// Parse out release date.
if (!/\d{4}-\d{2}-\d{2}/.match(components[0])) {
if (!components[0].match(/\d{4}-\d{2}-\d{2}/)) {
cli.error(`Release commit contains invalid date: ${components[0]}`);
return;
}
Expand Down Expand Up @@ -283,17 +306,14 @@ class ReleasePromotion {
return runSync('./tools/release.sh', ['-i', keyPath]);
}

async cherryPickToMaster() {
// Since we've committed the Working On commit,
// the release commit will be 1 removed from
// tip-of-tree (e.g HEAD~1).
cherryPickToMaster() {
// Since we've committed the Working On commit, the release
// commit will be 1 removed from tip-of-tree (e.g HEAD~1).
const releaseCommitSha = this.getCommitSha(1);
runSync('git', ['checkout', 'master']);

// There will be conflicts.
runSync('git', ['cherry-pick', releaseCommitSha]);
// TODO(codebytere): gracefully handle conflicts and
// wait for the releaser to resolve.
}
}

Expand Down

0 comments on commit 13191bd

Please sign in to comment.