Skip to content

Commit c3883d7

Browse files
Development (#7)
* Switches exec package out for @actions/exec
1 parent d10106a commit c3883d7

24 files changed

+1577
-28
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
set -e
1+
#!/bin/bash
2+
set -eou pipefail
23

34
regexString=$1
45

index.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,59 @@
11
const core = require('@actions/core');
2-
const util = require('util');
3-
const exec = util.promisify(require('child_process').exec);
2+
const exec = require('@actions/exec');
3+
4+
const src = __dirname;
45

56
try {
67
// `regex-string` input defined in action metadata file
78
const regexString = core.getInput('regex-string');
89
const regexp = /^[A-Za-z0-9_-]*$/;
10+
911
if (regexp.test(regexString)) {
10-
const command = 'bash cut-release-branch.sh ' + regexString;
11-
12-
const output = getSemVerBranches(command);
13-
output.then(function(result){
14-
if (result["semanticVersion"]) {
15-
console.log('\x1b[32m%s\x1b[0m', `Last Semantic Version Found: ${result["semanticVersion"]}`);
16-
core.setOutput("last-semver", result["semanticVersion"]);
17-
}
18-
if (result["branchName"]) {
19-
console.log('\x1b[32m%s\x1b[0m', `Last Branch with Semantic Version Found: ${result["branchName"]}`);
20-
core.setOutput("last-semver-branch", result["branchName"]);
21-
}
22-
});
12+
getSemVerBranches(regexString);
2313
} else {
2414
const regexError = "Regex string must contain only numbers, strings, underscores, and dashes.";
2515
console.log('\x1b[33m%s\x1b[0m', regexError);
2616
core.setFailed(regexError);
2717
}
28-
2918
} catch (error) {
3019
core.setFailed(error.message);
3120
}
3221

33-
async function getSemVerBranches(command) {
22+
async function getSemVerBranches(regexString) {
3423
// Get all the branches with the regex prefix and return the last version
3524
try{
36-
const { err, stdout, stderr } = await exec(command, [{ shell: "bash" }]);
25+
let output = '';
26+
let err = '';
27+
28+
const options = {};
29+
options.listeners = {
30+
stdout: (data) => {
31+
output += data.toString();
32+
},
33+
stderr: (data) => {
34+
err += data.toString();
35+
}
36+
};
37+
38+
await exec.exec(`${src}/get-semver-and-branch.sh`, [regexString], options);
39+
const { semanticVersion, branchName } = JSON.parse(output);
3740

41+
if (semanticVersion) {
42+
console.log('\x1b[32m%s\x1b[0m', `Last Semantic Version Found: ${semanticVersion}`);
43+
core.setOutput("last-semver", semanticVersion);
44+
}
45+
if (branchName) {
46+
console.log('\x1b[32m%s\x1b[0m', `Last Branch with Semantic Version Found: ${branchName}`);
47+
core.setOutput("last-semver-branch", branchName);
48+
}
3849
if (err) {
3950
console.log('\x1b[33m%s\x1b[0m', 'Could not find any branches because: ');
40-
console.log('\x1b[31m%s\x1b[0m', stderr);
51+
console.log('\x1b[31m%s\x1b[0m', err);
52+
core.setFailed(err);
4153
process.exit(1);
42-
43-
return;
44-
}
45-
46-
const data = JSON.parse(stdout);
47-
if (data) {
48-
return data;
4954
}
5055
} catch (err) {
51-
console.log(err);
56+
core.setFailed(err.message);
5257
process.exit(0);
5358
}
5459
}

node_modules/@actions/exec/README.md

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/exec/lib/exec.d.ts

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/exec/lib/exec.js

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/exec/lib/exec.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/exec/lib/interfaces.d.ts

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/exec/lib/interfaces.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/exec/lib/interfaces.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/exec/lib/toolrunner.d.ts

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)