Skip to content

Commit

Permalink
feat: add prepare hook
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Feb 19, 2018
1 parent 33db9ec commit 7ac578c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ Execute a shell command to generate the release note.
| `stdout` | Only the release note must be written to `stdout`. |
| `stderr` | Can be used for logging. |

## prepare

Execute a shell command to prepare the release.

| Command property | Description |
|------------------|---------------------------------------------------------------------------------------------------------------------|
| `exit code` | Any non `0` code is considered as an unexpected error and will stop the `semantic-release` execution with an error. |
| `stdout` | Can be used for logging. |
| `stderr` | Can be used for logging. |

## publish

Execute a shell command to publish the release.
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ async function generateNotes(pluginConfig, params) {
return execScript(pluginConfig, params);
}

async function prepare(pluginConfig, params) {
await execScript(pluginConfig, params);
}

async function publish(pluginConfig, params) {
const stdout = await execScript(pluginConfig, params);
return stdout.trim() ? parseJson(stdout) : undefined;
Expand All @@ -59,4 +63,4 @@ async function fail(pluginConfig, params) {
await execScript(pluginConfig, params);
}

module.exports = {verifyConditions, analyzeCommits, verifyRelease, generateNotes, publish, success, fail};
module.exports = {verifyConditions, analyzeCommits, verifyRelease, generateNotes, prepare, publish, success, fail};
6 changes: 2 additions & 4 deletions test/fail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ test.beforeEach(t => {
t.context.logger = {log: t.context.log, error: t.context.error};
});

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

await t.notThrows(fail(pluginConfig, params));
Expand Down
27 changes: 27 additions & 0 deletions test/prepare.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import test from 'ava';
import {stub} from 'sinon';
import {prepare} from '..';

stub(process.stdout, 'write');
stub(process.stderr, 'write');

test.beforeEach(t => {
// Mock logger
t.context.log = stub();
t.context.error = stub();
t.context.logger = {log: t.context.log, error: t.context.error};
});

test.serial('Execute script in prepare step', async t => {
const pluginConfig = {cmd: './test/fixtures/echo-args.sh'};
const params = {logger: t.context.logger};

await t.notThrows(prepare(pluginConfig, params));
});

test.serial('Throw "Error" if the prepare script does not returns 0', async t => {
const pluginConfig = {cmd: 'exit 1'};
const params = {logger: t.context.logger};

await t.throws(prepare(pluginConfig, params), Error);
});
6 changes: 2 additions & 4 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ test.beforeEach(t => {
t.context.logger = {log: t.context.log, error: t.context.error};
});

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

await t.notThrows(success(pluginConfig, params));
Expand Down

0 comments on commit 7ac578c

Please sign in to comment.