-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (48 loc) · 1.64 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
53
54
55
56
57
const core = require('@actions/core');
const exec = require('@actions/exec');
const src = __dirname;
try {
const repositoryUrl = core.getInput('repository-url');
const branchPrefix = core.getInput('branch-prefix');
const releaseVersion = core.getInput('release-version');
const branchName = branchPrefix + releaseVersion;
const baselineBranch = core.getInput('baseline-branch');
const regexp = /^[\.A-Za-z0-9_-]*$/;
console.log(`branchPrefix ${branchPrefix}`);
console.log(`releaseVersion ${releaseVersion}`);
console.log(`baselineBranch ${baselineBranch}`);
if (regexp.test(branchName)) {
mergeBranches(branchName, baselineBranch, repositoryUrl);
} else {
const regexError = "Branch prefix and semantic version must contain only numbers, strings, underscores, periods, and dashes.";
core.setFailed(regexError);
}
} catch (error) {
core.setFailed(error.message);
}
async function mergeBranches(branchName, baselineBranch, repositoryUrl) {
try {
let output = '';
let err = '';
const options = {};
options.listeners = {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
err += data.toString();
}
};
options.cwd = './';
await exec.exec(`${src}/merge-branches.sh`, [branchName, baselineBranch, repositoryUrl], options);
if (output) {
console.log('\x1b[32m%s\x1b[0m', `Github Output: ${output}`);
} else {
core.setFailed(err);
process.exit(1);
}
} catch (err) {
core.setFailed(`Could not merge branches because: ${err.message}`);
process.exit(0);
}
}