generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (56 loc) · 1.55 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
58
59
60
61
62
63
64
65
66
67
68
69
/**
* index.js
*
* Created by cannonrp on 2020/02/20.
* Copyright © 2020 The Washington Post. All rights reserved.
*/
const path = require('path');
const core = require('@actions/core');
const exec = require('@actions/exec');
// most @actions toolkit packages have async methods
async function run() {
try {
let output = '';
let error = '';
const options = {
listeners: {
stdout: (data) => { output += data.toString(); },
stderr: (data) => { error += data.toString() }
}
};
const scriptFilename = path.join(__dirname, 'git-version.sh');
const success = await exec.exec(`bash ${scriptFilename}`, [], options);
if (error) {
console.log('ERROR', error);
}
if (success == 0) {
const lines = output.split('\n');
const dict = lines.reduce((dict, text) => {
if (!text) {
return dict;
}
const parts = text.trim().split('=', 2);
if (parts.length !== 2) {
console.log(`Warning: could not parse '${text}'`);
return dict;
}
const key = parts[0];
const value = parts[1];
return { ...dict, [key]: value };
}, {});
Object.keys(dict).forEach((key) => {
const name = `git_${key}`;
const value = dict[key];
console.log(`Set Output '${name}' = '${value}'`)
core.setOutput(name, value);
})
console.log('Finished');
} else {
console.log(`Error Returned ${success}!`);
}
}
catch (error) {
core.setFailed(error.message);
}
}
run()