Skip to content

Commit

Permalink
fix: abort process when encountering unrecoverable error (#33)
Browse files Browse the repository at this point in the history
When encountering an unrecoverable error, the plugin will
fail and exit with code 1 which should stop pipelines.

Unrecoverable errors are:
- merges into the same branch if not allowed
- errors during backmerge
  • Loading branch information
saitho committed Mar 1, 2022
1 parent aa0d163 commit 5e9b60c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
tsconfig: 'tsconfig.json'
}
},
clearMocks: true,
moduleFileExtensions: [
'js',
'json',
Expand Down
5 changes: 4 additions & 1 deletion src/perform-backmerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ async function performBackmergeIntoBranch(git: Git, pluginConfig: Partial<Config
context.logger.error(file)
}
}
return
throw new Error(
'Unable to rebase branch (see error output above).'
);
}
}
} else {
Expand Down Expand Up @@ -122,6 +124,7 @@ export async function performBackmerge(git: Git, pluginConfig: Partial<Config>,
} catch (e) {
context.logger.error('Process aborted due to an error while backmerging a branch.')
context.logger.error(e)
process.exit(1)
break
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/perform-backmerge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class NullLogger {
error(message) {}
}

const realProcessExit = process.exit;
process.exit = jest.fn(() => "" as never);
afterAll(() => { process.exit = realProcessExit; });

describe("perform-backmerge", () => {
jest.mock('semantic-release/lib/get-git-auth-url', () => jest.fn((c) => c.options.repositoryUrl));

Expand Down Expand Up @@ -438,6 +442,7 @@ describe("perform-backmerge to multiple branches", () => {
verify(mockedLogger.error('Process aborted due to an error while backmerging a branch.')).once();
verify(mockedLogger.error(anyString())).once();
verify(mockedLogger.log('Performing back-merge into develop branch "develop".')).never();
expect(process.exit).toBeCalledWith(1);
});

it("skip conditional backmerge if the release branch does not match the 'from' branch", (done) => {
Expand Down Expand Up @@ -548,6 +553,7 @@ describe("perform-backmerge with error", () => {
verify(mockedLogger.error('1 modified file(s):')).once();
verify(mockedLogger.error('M testfile')).once();
verify(mockedGit.push('my-repo', 'develop', false)).never();
expect(process.exit).toBeCalledWith(1);
done();
})
.catch((error) => done(error));
Expand Down

0 comments on commit 5e9b60c

Please sign in to comment.