-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (44 loc) · 1.13 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 { exec } = require("child_process")
//
// try {
// const command = core.getInput('command')
//
// exec(command, (error, stdout, stderr) => {
// if (error) {
// core.setOutput('log', error.message)
// core.error(error.message)
// return
// }
// if (stderr) {
// core.setOutput('log', stderr)
// core.error(stderr)
// return
// }
// core.setOutput('log', stdout)
// core.info(stdout)
// })
// } catch (error) {
// core.setFailed(error.message)
// }
const core = require('@actions/core')
const { spawn } = require('child_process')
const command = core.getInput('command').split(' ')
const execution = spawn(command[0], command.slice(1))
let log = ''
execution.stdout.on('data', data => {
log = log + data
core.info(`STDOUT: ${data}`);
});
execution.stderr.on('data', data => {
log = log + data
core.info(`STDERR: ${data}`);
});
execution.on('error', (error) => {
log = log + error.message
core.info(`ERROR: ${error.message}`);
});
execution.on('close', (code) => {
core.info(`LOG: ${log}`)
core.setOutput('log', log)
});