Skip to content

Commit 7ac578c

Browse files
committed
feat: add prepare hook
1 parent 33db9ec commit 7ac578c

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ Execute a shell command to generate the release note.
4949
| `stdout` | Only the release note must be written to `stdout`. |
5050
| `stderr` | Can be used for logging. |
5151

52+
## prepare
53+
54+
Execute a shell command to prepare the release.
55+
56+
| Command property | Description |
57+
|------------------|---------------------------------------------------------------------------------------------------------------------|
58+
| `exit code` | Any non `0` code is considered as an unexpected error and will stop the `semantic-release` execution with an error. |
59+
| `stdout` | Can be used for logging. |
60+
| `stderr` | Can be used for logging. |
61+
5262
## publish
5363

5464
Execute a shell command to publish the release.

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ async function generateNotes(pluginConfig, params) {
4646
return execScript(pluginConfig, params);
4747
}
4848

49+
async function prepare(pluginConfig, params) {
50+
await execScript(pluginConfig, params);
51+
}
52+
4953
async function publish(pluginConfig, params) {
5054
const stdout = await execScript(pluginConfig, params);
5155
return stdout.trim() ? parseJson(stdout) : undefined;
@@ -59,4 +63,4 @@ async function fail(pluginConfig, params) {
5963
await execScript(pluginConfig, params);
6064
}
6165

62-
module.exports = {verifyConditions, analyzeCommits, verifyRelease, generateNotes, publish, success, fail};
66+
module.exports = {verifyConditions, analyzeCommits, verifyRelease, generateNotes, prepare, publish, success, fail};

test/fail.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ test.beforeEach(t => {
1212
t.context.logger = {log: t.context.log, error: t.context.error};
1313
});
1414

15-
test.serial('Return the value fail script wrote to stdout', async t => {
16-
const pluginConfig = {
17-
cmd: './test/fixtures/echo-args.sh',
18-
};
15+
test.serial('Execute script in fail step', async t => {
16+
const pluginConfig = {cmd: './test/fixtures/echo-args.sh'};
1917
const params = {logger: t.context.logger};
2018

2119
await t.notThrows(fail(pluginConfig, params));

test/prepare.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import test from 'ava';
2+
import {stub} from 'sinon';
3+
import {prepare} from '..';
4+
5+
stub(process.stdout, 'write');
6+
stub(process.stderr, 'write');
7+
8+
test.beforeEach(t => {
9+
// Mock logger
10+
t.context.log = stub();
11+
t.context.error = stub();
12+
t.context.logger = {log: t.context.log, error: t.context.error};
13+
});
14+
15+
test.serial('Execute script in prepare step', async t => {
16+
const pluginConfig = {cmd: './test/fixtures/echo-args.sh'};
17+
const params = {logger: t.context.logger};
18+
19+
await t.notThrows(prepare(pluginConfig, params));
20+
});
21+
22+
test.serial('Throw "Error" if the prepare script does not returns 0', async t => {
23+
const pluginConfig = {cmd: 'exit 1'};
24+
const params = {logger: t.context.logger};
25+
26+
await t.throws(prepare(pluginConfig, params), Error);
27+
});

test/success.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ test.beforeEach(t => {
1212
t.context.logger = {log: t.context.log, error: t.context.error};
1313
});
1414

15-
test.serial('Return the value success script wrote to stdout', async t => {
16-
const pluginConfig = {
17-
cmd: './test/fixtures/echo-args.sh',
18-
};
15+
test.serial('Execute script in success step', async t => {
16+
const pluginConfig = {cmd: './test/fixtures/echo-args.sh'};
1917
const params = {logger: t.context.logger};
2018

2119
await t.notThrows(success(pluginConfig, params));

0 commit comments

Comments
 (0)