Skip to content

Commit

Permalink
Do not show the rollback message when the test step fails (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksathyanm authored and sindresorhus committed Sep 13, 2019
1 parent c0dc3a3 commit 66bedff
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = async (input = 'patch', options) => {
const hasLockFile = fs.existsSync(path.resolve(rootDir, options.yarn ? 'yarn.lock' : 'package-lock.json')) || fs.existsSync(path.resolve(rootDir, 'npm-shrinkwrap.json'));
const isOnGitHub = options.repoUrl && (hostedGitInfo.fromUrl(options.repoUrl) || {}).type === 'github';

let isPublished = false;
let publishStatus = 'UNKNOWN';

const rollback = onetime(async () => {
console.log('\nPublish failed. Rolling back to the previous state…');
Expand All @@ -86,11 +86,14 @@ module.exports = async (input = 'patch', options) => {
});

exitHook(callback => {
if (!isPublished && runPublish) {
if (publishStatus === 'FAILED' && runPublish) {
(async () => {
await rollback();
callback();
})();
} else {
console.log('\nAborted!');
callback();
}
});

Expand Down Expand Up @@ -190,7 +193,7 @@ module.exports = async (input = 'patch', options) => {
throw new Error(`Error publishing package:\n${error.message}\n\nThe project was rolled back to its previous state.`);
}),
finalize(() => {
isPublished = !hasError;
publishStatus = hasError ? 'FAILED' : 'SUCCESS';
})
);
}
Expand All @@ -215,7 +218,7 @@ module.exports = async (input = 'patch', options) => {
return 'Upstream branch not found; not pushing.';
}

if (!isPublished && runPublish) {
if (publishStatus === 'FAILED' && runPublish) {
return 'Couldn\'t publish package to npm; not pushing.';
}
},
Expand Down

0 comments on commit 66bedff

Please sign in to comment.