Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
fix(release): switch to async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
ostowe committed Jun 30, 2021
1 parent e7de1cb commit d998f0b
Showing 1 changed file with 49 additions and 47 deletions.
96 changes: 49 additions & 47 deletions bin/reconcile-release
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const path = require('path');
// Skip commitizen for all commits happening within this script.
process.env.HUSKY_SKIP_HOOKS = 1;

const blahblahblah = 'test';

const releaseBranches = execSync('git branch --all')
.toString('utf8')
.split('\n ')
Expand All @@ -24,76 +26,74 @@ const releaseBranches = execSync('git branch --all')
.concat('release-merge-test')
.reverse();

inquirer
.prompt([
const reconcile = async () => {
const { releaseBranch } = await inquirer.prompt([
{
type: 'list',
choices: releaseBranches,
name: 'releaseBranch',
message: 'Welcome to the Irving release wizard! Which release branch would you like to merge?'
},
])
.then(({ releaseBranch }) => {
execSync(`git checkout ${releaseBranch}`);
execSync('git checkout release-merge');
]);

execSync(`git checkout ${releaseBranch}`);
execSync('git checkout release-merge');

try {
execSync(`git merge ${releaseBranch}`).toString('utf8');
} catch (e) {
const gitMessage = e.stdout.toString('utf8');
// Attempt merge.
let hasConflict = false;

try {
execSync(`git merge ${releaseBranch}`).toString('utf8');
} catch (e) {
const gitMessage = e.stdout.toString('utf8');
hasConflict = gitMessage.includes('Automatic merge failed');
const { mismatchedDeps = false } = await inquirer.prompt([
{
type: 'confirm',
name: 'mismatchedDeps',
message: `${chalk.red('Merge conflict encountered.')} Have any dependencies been installed in the release branch that have not been merged into main?`,
},
]) || {};

if (gitMessage.includes('Automatic merge failed')) {
return inquirer.prompt([
if (hasConflict) {
if (mismatchedDeps) {
await inquirer.prompt([
{
type: 'confirm',
name: 'mismatchedDeps',
message: `${chalk.red('Merge conflict encountered.')} Have any dependencies been installed in the release branch that have not been merged into main?`,
name: 'packageMergeComplete',
message: `Please manually resolve conflicts in package.json files with mismatched dependencies before continuing.
Use "y" or the enter key to continue once manual resolution is complete.`,
},
]);
} else {
console.log(chalk.red('An unknown error ocurred, try again', e.message));
}
}
})
.then(({ mismatchedDeps = false } = {}) => {
if (mismatchedDeps) {
return inquirer.prompt([

// auto-resolve conflicts in package.json, package-lock, lerna.json, and package changelogs.
execSync('git ls-tree -r --name-only main | grep -E ".*((package|package-lock|lerna)\\.json|\/CHANGELOG.md)$" | xargs git checkout --ours --');
await inquirer.prompt([
{
type: 'confirm',
name: 'continueMerge',
message: `Please manually resolve conflicts in package.json files with mismatched dependencies before continuing.
Use "y" or the enter key to continue once manual resolution is complete.`,
},
]);
}
})
.then(() => {
// auto-resolve conflicts in package.json, package-lock, lerna.json, and package changelogs.
execSync('git ls-tree -r --name-only main | grep -E ".*((package|package-lock|lerna)\\.json|\/CHANGELOG.md)$" | xargs git checkout --ours --');
return inquirer.prompt([
{
type: 'confirm',
name: 'continueMerge',
message: `Unfortunately, the root CHANGELOG.md file cannot be automatically merged.
name: 'changelogMergeComplete',
message: `Unfortunately, the root CHANGELOG.md file cannot be automatically merged.
Please manually resolve conflicts in this file and continue when finished. Keep in mind:
- every changelog heading should have release notes, even if it's just "**Note:** Version bump only for package irving"
- depending on how far your release branch and the main branch have diverged, there may be duplicate changelog entries. Verify this is not the case before completing your merge.`,
},
{
type: 'input',
name: 'releaseVersion',
message: 'What is the latest release version on your release branch?',
},
]);
})
.then(({ releaseVersion }) => {
},
]);
}

// Bump release
console.log(chalk.green('Bumping main branch to next version...'));
execSync('npm run release:bump');

// Generate commit roundup.
const { releaseVersion } = await inquirer.prompt([
{
type: 'input',
name: 'releaseVersion',
message: 'What is the latest release version on your release branch?',
}
]);
console.log(chalk.green(`Creating commit roundup for ${releaseVersion}`));

const changelog = fs.readFileSync(
path.join(__dirname, '../CHANGELOG.md'),
'utf8'
Expand All @@ -112,4 +112,6 @@ Please manually resolve conflicts in this file and continue when finished. Keep

console.log(chalk.magentaBright('Commit roundup generated'));
console.log(entriesCleaned);
});
}

reconcile();

0 comments on commit d998f0b

Please sign in to comment.