Skip to content

Commit f7d87f8

Browse files
committed
Merge remote-tracking branch 'origin/beta'
2 parents 55d093f + 31e84e5 commit f7d87f8

File tree

6 files changed

+135
-8
lines changed

6 files changed

+135
-8
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: ~> 1.0
22

33
import:
44
- semantic-release/semantic-release:.travis/node.yml
5-
- semantic-release/semantic-release:.travis/node-versions.yml
5+
- semantic-release/semantic-release:.travis/node-versions.yml@beta
66
- semantic-release/semantic-release:.travis/semantic-release.yml
77
- semantic-release/semantic-release:.travis/greenkeeper.yml
88
- semantic-release/semantic-release:.travis/codecov.yml

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
[![npm latest version](https://img.shields.io/npm/v/@semantic-release/exec/latest.svg)](https://www.npmjs.com/package/@semantic-release/exec)
1010
[![npm next version](https://img.shields.io/npm/v/@semantic-release/exec/next.svg)](https://www.npmjs.com/package/@semantic-release/exec)
11+
[![npm beta version](https://img.shields.io/npm/v/@semantic-release/exec/beta.svg)](https://www.npmjs.com/package/@semantic-release/exec)
1112

1213
| Step | Description |
1314
|--------------------|---------------------------------------------------------------------------------------------------------|
@@ -60,6 +61,7 @@ With this example:
6061
| `verifyReleaseCmd` | The shell command to execute during the verify release step. See [verifyReleaseCmd](#verifyreleasecmd). |
6162
| `generateNotesCmd` | The shell command to execute during the generate notes step. See [generateNotesCmd](#generatenotescmd). |
6263
| `prepareCmd` | The shell command to execute during the prepare step. See [prepareCmd](#preparecmd). |
64+
| `addChannelCmd` | The shell command to execute during the add channel step. See [addChannelCmd](#addchannelcmd). |
6365
| `publishCmd` | The shell command to execute during the publish step. See [publishCmd](#publishcmd). |
6466
| `successCmd` | The shell command to execute during the success step. See [successCmd](#successcmd). |
6567
| `failCmd` | The shell command to execute during the fail step. See [failCmd](#failcmd). |
@@ -110,6 +112,14 @@ Execute a shell command to verify if the release should happen.
110112
| `stdout` | Can be used for logging. |
111113
| `stderr` | Can be used for logging. |
112114

115+
## addChannelCmd
116+
117+
| Command property | Description |
118+
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
119+
| `exit code` | Any non `0` code is considered as an unexpected error and will stop the `semantic-release` execution with an error. |
120+
| `stdout` | The `release` information can be written to `stdout` as parseable JSON (for example `{"name": "Release name", "url": "http://url/release/1.0.0"}`). If the command write non parseable JSON to `stdout` no `release` information will be returned. |
121+
| `stderr` | Can be used for logging. |
122+
113123
## publishCmd
114124

115125
| Command property | Description |

index.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ async function publish(pluginConfig, context) {
7979
return false;
8080
}
8181

82+
async function addChannel(pluginConfig, context) {
83+
if (!isNil(pluginConfig.addChannelCmd) || !isNil(pluginConfig.cmd)) {
84+
verifyConfig('addChannelCmd', pluginConfig);
85+
86+
const stdout = await exec('addChannelCmd', pluginConfig, context);
87+
88+
try {
89+
return stdout ? parseJson(stdout) : undefined;
90+
} catch (error) {
91+
debug(stdout);
92+
debug(error);
93+
94+
debug(`The command ${pluginConfig.cmd} wrote invalid JSON to stdout. The stdout content will be ignored.`);
95+
96+
return undefined;
97+
}
98+
}
99+
100+
return false;
101+
}
102+
82103
async function success(pluginConfig, context) {
83104
if (!isNil(pluginConfig.successCmd) || !isNil(pluginConfig.cmd)) {
84105
verifyConfig('successCmd', pluginConfig);
@@ -95,4 +116,14 @@ async function fail(pluginConfig, context) {
95116
}
96117
}
97118

98-
module.exports = {verifyConditions, analyzeCommits, verifyRelease, generateNotes, prepare, publish, success, fail};
119+
module.exports = {
120+
verifyConditions,
121+
analyzeCommits,
122+
verifyRelease,
123+
generateNotes,
124+
prepare,
125+
publish,
126+
addChannel,
127+
success,
128+
fail,
129+
};

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
"@semantic-release/error": "^2.1.0",
1515
"aggregate-error": "^3.0.0",
1616
"debug": "^4.0.0",
17-
"execa": "^3.2.0",
17+
"execa": "^4.0.0",
1818
"lodash": "^4.17.4",
1919
"parse-json": "^5.0.0"
2020
},
2121
"devDependencies": {
2222
"ava": "^2.0.0",
2323
"codecov": "^3.0.0",
2424
"nyc": "^15.0.0",
25-
"semantic-release": "^15.0.0",
25+
"semantic-release": "^16.0.0-beta",
2626
"sinon": "^8.0.0",
2727
"stream-buffers": "^3.0.2",
2828
"xo": "^0.25.0"
2929
},
3030
"engines": {
31-
"node": ">=8.16"
31+
"node": ">=10.13"
3232
},
3333
"files": [
3434
"lib",
@@ -59,15 +59,14 @@
5959
"all": true
6060
},
6161
"peerDependencies": {
62-
"semantic-release": ">=15.9.0 <16.0.0"
62+
"semantic-release": ">=16.0.0-beta <17.0.0"
6363
},
6464
"prettier": {
6565
"printWidth": 120,
6666
"trailingComma": "es5"
6767
},
6868
"publishConfig": {
69-
"access": "public",
70-
"tag": "next"
69+
"access": "public"
7170
},
7271
"repository": {
7372
"type": "git",

test/add-channel.test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import test from 'ava';
2+
import {stub} from 'sinon';
3+
import {WritableStreamBuffer} from 'stream-buffers';
4+
import {addChannel} from '..';
5+
6+
test.beforeEach(t => {
7+
t.context.stdout = new WritableStreamBuffer();
8+
t.context.stderr = new WritableStreamBuffer();
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('Parse JSON returned by addChannel script', async t => {
16+
const pluginConfig = {
17+
addChannelCmd:
18+
'./test/fixtures/echo-args.sh {\\"name\\": \\"Release name\\", \\"url\\": \\"https://host.com/release/1.0.0\\"}',
19+
};
20+
const context = {stdout: t.context.stdout, stderr: t.context.stderr, logger: t.context.logger};
21+
22+
const result = await addChannel(pluginConfig, context);
23+
t.deepEqual(result, {name: 'Release name', url: 'https://host.com/release/1.0.0'});
24+
});
25+
26+
test('Return "undefined" if the addChannel script wrtite invalid JSON to stdout (with "publishCmd")', async t => {
27+
const pluginConfig = {addChannelCmd: './test/fixtures/echo-args.sh invalid_json'};
28+
const context = {stdout: t.context.stdout, stderr: t.context.stderr, logger: t.context.logger};
29+
30+
const result = await addChannel(pluginConfig, context);
31+
t.is(result, undefined);
32+
});
33+
34+
test('Return "undefined" if the addChannel script wrtite invalid JSON to stdout (with "cmd")', async t => {
35+
const pluginConfig = {cmd: './test/fixtures/echo-args.sh invalid_json'};
36+
const context = {stdout: t.context.stdout, stderr: t.context.stderr, logger: t.context.logger};
37+
38+
const result = await addChannel(pluginConfig, context);
39+
t.is(result, undefined);
40+
});
41+
42+
test('Return "undefined" if the addChannel script wrtite nothing to stdout', async t => {
43+
const pluginConfig = {addChannelCmd: './test/fixtures/echo-args.sh'};
44+
const context = {stdout: t.context.stdout, stderr: t.context.stderr, logger: t.context.logger};
45+
46+
const result = await addChannel(pluginConfig, context);
47+
t.is(result, undefined);
48+
});
49+
50+
test('Throw "Error" if the addChannel script does not returns 0', async t => {
51+
const pluginConfig = {addChannelCmd: 'exit 1'};
52+
const context = {stdout: t.context.stdout, stderr: t.context.stderr, logger: t.context.logger, options: {}};
53+
54+
await t.throwsAsync(addChannel(pluginConfig, context), Error);
55+
});
56+
57+
test('Use "cmd" if defined and "addChannelCmd" is not', async t => {
58+
const pluginConfig = {
59+
cmd:
60+
'./test/fixtures/echo-args.sh {\\"name\\": \\"Release name\\", \\"url\\": \\"https://host.com/release/1.0.0\\"}',
61+
};
62+
const context = {stdout: t.context.stdout, stderr: t.context.stderr, logger: t.context.logger};
63+
64+
const result = await addChannel(pluginConfig, context);
65+
t.deepEqual(result, {name: 'Release name', url: 'https://host.com/release/1.0.0'});
66+
});
67+
68+
test('Use "addChannelCmd" even if "cmd" is defined', async t => {
69+
const pluginConfig = {
70+
addChannelCmd:
71+
'./test/fixtures/echo-args.sh {\\"name\\": \\"Release name\\", \\"url\\": \\"https://host.com/release/1.0.0\\"}',
72+
cmd: 'exit 1',
73+
};
74+
const context = {stdout: t.context.stdout, stderr: t.context.stderr, logger: t.context.logger};
75+
76+
const result = await addChannel(pluginConfig, context);
77+
t.deepEqual(result, {name: 'Release name', url: 'https://host.com/release/1.0.0'});
78+
});
79+
80+
test('Return "false" if neither "addChannelCmd" nor "cmd" is defined', async t => {
81+
const pluginConfig = {};
82+
const context = {stdout: t.context.stdout, stderr: t.context.stderr, logger: t.context.logger};
83+
84+
const result = await addChannel(pluginConfig, context);
85+
t.is(result, false);
86+
});

test/integration.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test('Skip step if neither "cmd" nor step cmd is defined', async t => {
88
await t.notThrowsAsync(m.generateNotes({}, {}));
99
await t.notThrowsAsync(m.prepare({}, {}));
1010
await t.notThrowsAsync(m.publish({}, {}));
11+
await t.notThrowsAsync(m.addChannel({}, {}));
1112
await t.notThrowsAsync(m.success({}, {}));
1213
await t.notThrowsAsync(m.fail({}, {}));
1314
});

0 commit comments

Comments
 (0)