Skip to content

Commit cdb248f

Browse files
committed
feat: use cwd and env options passed by core
1 parent a4071cc commit cdb248f

11 files changed

+97
-97
lines changed

index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const verifyConfig = require('./lib/verify-config');
77

88
const PLUGIN_TYPES = ['analyzeCommits', 'verifyRelease', 'generateNotes', 'publish', 'success', 'fail'];
99

10-
async function verifyConditions(pluginConfig, params) {
11-
for (const [option, value] of Object.entries(params.options || {})) {
10+
async function verifyConditions(pluginConfig, context) {
11+
for (const [option, value] of Object.entries(context.options || {})) {
1212
if (PLUGIN_TYPES.includes(option)) {
1313
for (const plugin of castArray(value)) {
1414
if (
@@ -24,52 +24,52 @@ async function verifyConditions(pluginConfig, params) {
2424
verifyConfig(pluginConfig);
2525

2626
try {
27-
await execScript(pluginConfig, params);
27+
await execScript(pluginConfig, context);
2828
} catch (err) {
2929
throw new SemanticReleaseError(err.stdout, 'EVERIFYCONDITIONS');
3030
}
3131
}
3232

33-
async function analyzeCommits(pluginConfig, params) {
34-
const stdout = await execScript(pluginConfig, params);
33+
async function analyzeCommits(pluginConfig, context) {
34+
const stdout = await execScript(pluginConfig, context);
3535
return stdout.trim() ? stdout : undefined;
3636
}
3737

38-
async function verifyRelease(pluginConfig, params) {
38+
async function verifyRelease(pluginConfig, context) {
3939
try {
40-
await execScript(pluginConfig, params);
40+
await execScript(pluginConfig, context);
4141
} catch (err) {
4242
throw new SemanticReleaseError(err.stdout, 'EVERIFYRELEASE');
4343
}
4444
}
4545

46-
async function generateNotes(pluginConfig, params) {
47-
return execScript(pluginConfig, params);
46+
async function generateNotes(pluginConfig, context) {
47+
return execScript(pluginConfig, context);
4848
}
4949

50-
async function prepare(pluginConfig, params) {
51-
await execScript(pluginConfig, params);
50+
async function prepare(pluginConfig, context) {
51+
await execScript(pluginConfig, context);
5252
}
5353

54-
async function publish(pluginConfig, params) {
55-
const stdout = await execScript(pluginConfig, params);
54+
async function publish(pluginConfig, context) {
55+
const stdout = await execScript(pluginConfig, context);
5656
try {
5757
return stdout.trim() ? parseJson(stdout) : undefined;
5858
} catch (err) {
5959
debug(stdout);
6060
debug(err);
61-
params.logger.log(
61+
context.logger.log(
6262
`The command ${pluginConfig.cmd} wrote invalid JSON to stdout. The stdout content will be ignored.`
6363
);
6464
}
6565
}
6666

67-
async function success(pluginConfig, params) {
68-
await execScript(pluginConfig, params);
67+
async function success(pluginConfig, context) {
68+
await execScript(pluginConfig, context);
6969
}
7070

71-
async function fail(pluginConfig, params) {
72-
await execScript(pluginConfig, params);
71+
async function fail(pluginConfig, context) {
72+
await execScript(pluginConfig, context);
7373
}
7474

7575
module.exports = {verifyConditions, analyzeCommits, verifyRelease, generateNotes, prepare, publish, success, fail};

lib/exec-script.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const {template} = require('lodash');
22
const execa = require('execa');
33

4-
module.exports = async ({cmd, ...config}, {logger, ...opts}) => {
5-
const script = template(cmd)({config, ...opts});
4+
module.exports = async ({cmd, ...config}, {cwd, env, logger, ...context}) => {
5+
const script = template(cmd)({config, ...context});
66

77
logger.log('Call script %s', script);
88

9-
const shell = execa.shell(script);
9+
const shell = execa.shell(script, {cwd, env});
1010
shell.stdout.pipe(process.stdout);
1111
shell.stderr.pipe(process.stderr);
1212

test/analyze-commits.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ test.beforeEach(t => {
1313
t.context.logger = {log: t.context.log, error: t.context.error};
1414
});
1515

16-
test.serial('Return the value analyzeCommits script wrote to stdout', async t => {
16+
test('Return the value analyzeCommits script wrote to stdout', async t => {
1717
const pluginConfig = {
1818
cmd: './test/fixtures/echo-args.sh "minor "',
1919
};
20-
const params = {logger: t.context.logger};
20+
const context = {logger: t.context.logger};
2121

22-
const result = await analyzeCommits(pluginConfig, params);
22+
const result = await analyzeCommits(pluginConfig, context);
2323
t.is(result, 'minor');
2424
});
2525

26-
test.serial('Return "undefined" if the analyzeCommits script wrtite nothing to stdout', async t => {
26+
test('Return "undefined" if the analyzeCommits script wrtite nothing to stdout', async t => {
2727
const pluginConfig = {
2828
cmd: './test/fixtures/echo-args.sh " "',
2929
};
30-
const params = {logger: t.context.logger};
30+
const context = {logger: t.context.logger};
3131

32-
const result = await analyzeCommits(pluginConfig, params);
32+
const result = await analyzeCommits(pluginConfig, context);
3333
t.is(result, undefined);
3434
});
3535

36-
test.serial('Throw Error if if the analyzeCommits script does not returns 0', async t => {
36+
test('Throw Error if if the analyzeCommits script does not returns 0', async t => {
3737
const pluginConfig = {cmd: 'exit 1'};
38-
const params = {logger: t.context.logger};
38+
const context = {logger: t.context.logger};
3939

40-
await t.throws(analyzeCommits(pluginConfig, params), Error);
40+
await t.throws(analyzeCommits(pluginConfig, context), Error);
4141
});

test/exec-script.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ test.afterEach.always(t => {
1919

2020
test.serial('Pipe script output to stdout and stderr', async t => {
2121
const pluginConfig = {cmd: '>&2 echo "write to stderr" && echo "write to stdout"'};
22-
const params = {logger: t.context.logger, options: {}};
22+
const context = {logger: t.context.logger, options: {}};
2323

24-
const result = await execScript(pluginConfig, params);
24+
const result = await execScript(pluginConfig, context);
2525

2626
t.is(result, 'write to stdout');
2727
t.is(t.context.stdout.args[0][0].toString().trim(), 'write to stdout');
@@ -30,8 +30,8 @@ test.serial('Pipe script output to stdout and stderr', async t => {
3030

3131
test.serial('Generate command with template', async t => {
3232
const pluginConfig = {cmd: `./test/fixtures/echo-args.sh \${config.conf} \${lastRelease.version}`, conf: 'confValue'};
33-
const params = {lastRelease: {version: '1.0.0'}, logger: t.context.logger};
33+
const context = {lastRelease: {version: '1.0.0'}, logger: t.context.logger};
3434

35-
const result = await execScript(pluginConfig, params);
35+
const result = await execScript(pluginConfig, context);
3636
t.is(result, 'confValue 1.0.0');
3737
});

test/fail.test.js

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

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

19-
await t.notThrows(fail(pluginConfig, params));
19+
await t.notThrows(fail(pluginConfig, context));
2020
});
2121

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

26-
await t.throws(fail(pluginConfig, params), Error);
26+
await t.throws(fail(pluginConfig, context), Error);
2727
});

test/generate-notes.test.js

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

15-
test.serial('Return the value generateNotes script wrote to stdout', async t => {
15+
test('Return the value generateNotes script wrote to stdout', async t => {
1616
const pluginConfig = {
1717
cmd: './test/fixtures/echo-args.sh "\nRelease note \n\n"',
1818
};
19-
const params = {logger: t.context.logger};
19+
const context = {logger: t.context.logger};
2020

21-
const result = await generateNotes(pluginConfig, params);
21+
const result = await generateNotes(pluginConfig, context);
2222
t.is(result, 'Release note');
2323
});
2424

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

29-
await t.throws(generateNotes(pluginConfig, params), Error);
29+
await t.throws(generateNotes(pluginConfig, context), Error);
3030
});

test/prepare.test.js

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

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

19-
await t.notThrows(prepare(pluginConfig, params));
19+
await t.notThrows(prepare(pluginConfig, context));
2020
});
2121

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

26-
await t.throws(prepare(pluginConfig, params), Error);
26+
await t.throws(prepare(pluginConfig, context), Error);
2727
});

test/publish.test.js

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

16-
test.serial('Parse JSON returned by publish script', async t => {
16+
test('Parse JSON returned by publish script', async t => {
1717
const pluginConfig = {
1818
cmd:
1919
'./test/fixtures/echo-args.sh {\\"name\\": \\"Release name\\", \\"url\\": \\"https://host.com/release/1.0.0\\"}',
2020
};
21-
const params = {logger: t.context.logger};
21+
const context = {logger: t.context.logger};
2222

23-
const result = await publish(pluginConfig, params);
23+
const result = await publish(pluginConfig, context);
2424
t.deepEqual(result, {name: 'Release name', url: 'https://host.com/release/1.0.0'});
2525
});
2626

27-
test.serial('Return "undefined" if the publish script wrtite invalid JSON to stdout', async t => {
27+
test('Return "undefined" if the publish script wrtite invalid JSON to stdout', async t => {
2828
const pluginConfig = {
2929
cmd: './test/fixtures/echo-args.sh invalid_json',
3030
};
31-
const params = {logger: t.context.logger};
31+
const context = {logger: t.context.logger};
3232

33-
const result = await publish(pluginConfig, params);
33+
const result = await publish(pluginConfig, context);
3434
t.is(result, undefined);
3535
});
3636

37-
test.serial('Return "undefined" if the publish script wrtite nothing to stdout', async t => {
37+
test('Return "undefined" if the publish script wrtite nothing to stdout', async t => {
3838
const pluginConfig = {
3939
cmd: './test/fixtures/echo-args.sh',
4040
};
41-
const params = {logger: t.context.logger};
41+
const context = {logger: t.context.logger};
4242

43-
const result = await publish(pluginConfig, params);
43+
const result = await publish(pluginConfig, context);
4444
t.is(result, undefined);
4545
});
4646

47-
test.serial('Throw "Error" if the publish script does not returns 0', async t => {
47+
test('Throw "Error" if the publish script does not returns 0', async t => {
4848
const pluginConfig = {cmd: 'exit 1'};
49-
const params = {logger: t.context.logger, options: {}};
49+
const context = {logger: t.context.logger, options: {}};
5050

51-
await t.throws(publish(pluginConfig, params), Error);
51+
await t.throws(publish(pluginConfig, context), Error);
5252
});

test/success.test.js

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

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

19-
await t.notThrows(success(pluginConfig, params));
19+
await t.notThrows(success(pluginConfig, context));
2020
});
2121

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

26-
await t.throws(success(pluginConfig, params), Error);
26+
await t.throws(success(pluginConfig, context), Error);
2727
});

0 commit comments

Comments
 (0)