forked from VisualSJ/action-javascript-runner
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
41 lines (36 loc) · 1.17 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
'use strict';
const { existsSync } = require('fs');
const { join } = require('path');
const { spawn } = require('child_process');
const { getInput, setOutput, setFailed } = require('@actions/core');
const github = require('@actions/github');
const time = Date.now();
try {
const script = getInput('script');
const args = (getInput('args') || '').split(' ');
const scriptFile = join(process.cwd(), script);
if (!script || !existsSync(scriptFile)) {
throw new Error(`The script does not exist: ${scriptFile}`);
}
console.log(`Executing the script: ${scriptFile}`);
const child = spawn('node', [
scriptFile, ...args,
], {
cwd: process.cwd(),
stdio: [0, 1, 2, 'ipc'],
env: Object.assign({}, process.env),
});
child.on('exit', (code) => {
if (code !== 0) {
setOutput('time', Date.now() - time);
setFailed('Error in execution');
}
});
child.on('error', (error) => {
setOutput('time', Date.now() - time);
setFailed(`Error in execution: ${error.message}`);
});
} catch (error) {
setOutput('time', Date.now() - time);
setFailed(error.message);
}