-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (44 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const core = require('@actions/core');
const github = require('@actions/github');
const { exec, execSync } = require('child_process');
try {
const inputs = {
name: core.getInput('name'),
email: core.getInput('email'),
token: core.getInput('token') || process.env.TOKEN,
};
exec(`git config user.name "${inputs.name}" && git config user.email "${inputs.email}"`, (err) => {
if (err) {
throw err;
}
});
const versionMap = ['major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', 'prerelease'];
let command = '';
/**
* @type string[]
*/
const labels = github.context.payload.pull_request.labels.map(el => el.name);
for (const version of versionMap) {
if (labels.includes(version)) {
command = version;
break;
}
}
if (command) {
exec(`npm version ${command} -m "%s\r\n\r\n\r\nskip-checks: true"`, (versionError, version) => {
if (versionError) {
core.setFailed(versionError.message);
throw versionError;
}
exec('git push --follow-tags --no-verify', (pushError) => {
if (pushError) {
core.setFailed(pushError.message);
throw pushError;
}
core.setOutput('tag', version);
});
});
}
} catch (error) {
core.setFailed(error.message);
}