release: Reset Git repo on error

pull/4792/head
Richard Hansen 2021-02-15 17:19:17 -05:00 committed by John McLear
parent ba32f71f30
commit 899f2e02f3
1 changed files with 60 additions and 36 deletions

View File

@ -114,48 +114,72 @@ if (!changelog.startsWith(`# ${newVersion}\n`)) {
// //////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////
// Done with sanity checks, now it's time to make changes. // Done with sanity checks, now it's time to make changes.
console.log('Updating develop branch...'); try {
run('git pull --ff-only'); console.log('Updating develop branch...');
run('git pull --ff-only');
console.log(`Bumping ${release} version (to ${newVersion})...`); console.log(`Bumping ${release} version (to ${newVersion})...`);
pkg.version = newVersion; pkg.version = newVersion;
writeJson('./src/package.json', pkg); writeJson('./src/package.json', pkg);
// run npm version `release` where release is patch, minor or major // run npm version `release` where release is patch, minor or major
run('npm install --package-lock-only', {cwd: 'src/'}); run('npm install --package-lock-only', {cwd: 'src/'});
// run npm install --package-lock-only <-- required??? // run npm install --package-lock-only <-- required???
// Many users will be using the latest LTS version of npm, and the latest LTS version of npm uses // Many users will be using the latest LTS version of npm, and the latest LTS version of npm uses
// lockfileVersion 1. Enforce v1 so that users don't see a (benign) compatibility warning. // lockfileVersion 1. Enforce v1 so that users don't see a (benign) compatibility warning.
if (readJson('./src/package-lock.json').lockfileVersion !== 1) { if (readJson('./src/package-lock.json').lockfileVersion !== 1) {
throw new Error('Please regenerate package-lock.json with npm v6.x.'); throw new Error('Please regenerate package-lock.json with npm v6.x.');
}
run('git add src/package.json');
run('git add src/package-lock.json');
run('git commit -m "bump version"');
console.log('Switching to master...');
run('git checkout master');
console.log('Updating master branch...');
run('git pull --ff-only');
console.log('Merging develop into master...');
run('git merge --no-ff --no-edit develop');
console.log(`Creating ${newVersion} tag...`);
run(`git tag -s '${newVersion}' -m '${newVersion}'`);
console.log('Switching back to develop...');
run('git checkout develop');
console.log('Merging master into develop...');
run('git merge --no-ff --no-edit master');
} catch (err) {
console.error(err.toString());
console.warn('Resetting repository...');
console.warn('Resetting master...');
run('git checkout -f master');
run('git reset --hard @{u}');
console.warn('Resetting develop...');
run('git checkout -f develop');
run('git reset --hard @{u}');
console.warn(`Deleting ${newVersion} tag...`);
run(`git rev-parse -q --verify refs/tags/'${newVersion}' >/dev/null || exit 0; ` +
`git tag -d '${newVersion}'`);
throw err;
} }
run('git add src/package.json'); try {
run('git add src/package-lock.json'); console.log('Building documentation...');
run('git commit -m "bump version"'); run('make docs');
console.log('Switching to master...'); console.log('Updating ether.github.com master branch...');
run('git checkout master'); run('git pull --ff-only', {cwd: '../ether.github.com/'});
console.log('Updating master branch...'); console.log('Committing documentation...');
run('git pull --ff-only'); run(`cp -R out/doc/ ../ether.github.com/doc/v'${newVersion}'`);
console.log('Merging develop into master...'); run('git add .', {cwd: '../ether.github.com/'});
run('git merge --no-ff --no-edit develop'); run(`git commit -m '${newVersion} docs'`, {cwd: '../ether.github.com/'});
console.log(`Creating ${newVersion} tag...`); } catch (err) {
run(`git tag -s '${newVersion}' -m '${newVersion}'`); console.error(err.toString());
console.log('Switching back to develop...'); console.warn('Resetting repository...');
run('git checkout develop'); console.warn('Resetting master...');
console.log('Merging master into develop...'); run('git checkout -f master', {cwd: '../ether.github.com/'});
run('git merge --no-ff --no-edit master'); run('git reset --hard @{u}', {cwd: '../ether.github.com/'});
throw err;
console.log('Building documentation...'); }
run('make docs');
console.log('Updating ether.github.com master branch...');
run('git pull --ff-only', {cwd: '../ether.github.com/'});
console.log('Committing documentation...');
run(`cp -R out/doc/ ../ether.github.com/doc/v'${newVersion}'`);
run('git add .', {cwd: '../ether.github.com/'});
run(`git commit -m '${newVersion} docs'`, {cwd: '../ether.github.com/'});
console.log('Done.'); console.log('Done.');
console.log('Review the new commits and the new tag:'); console.log('Review the new commits and the new tag:');