Simplify index.js

This commit is contained in:
Stefan Zweifel 2020-02-11 21:04:18 +01:00
parent 844e852dde
commit eda98fb9e5
2 changed files with 25 additions and 12 deletions

View File

@ -37,7 +37,7 @@ inputs:
runs:
using: 'node12'
main: 'dist/index.js'
main: 'index.js'
branding:
icon: 'git-commit'

View File

@ -1,13 +1,26 @@
const core = require('@actions/core');
const exec = require('@actions/exec');
const spawn = require('child_process').spawn;
const path = require("path");
async function run() {
try {
await exec.exec('sh', ['entrypoint.sh']);
}
catch (error) {
core.setFailed(error.message);
}
}
const exec = (cmd, args=[]) => new Promise((resolve, reject) => {
console.log(`Started: ${cmd} ${args.join(" ")}`)
const app = spawn(cmd, args, { stdio: 'inherit' });
app.on('close', code => {
if(code !== 0){
err = new Error(`Invalid status code: ${code}`);
err.code = code;
return reject(err);
};
return resolve(code);
});
app.on('error', reject);
});
run()
const main = async () => {
await exec('sh', [path.join(__dirname, './entrypoint.sh')]);
};
main().catch(err => {
console.error(err);
console.error(err.stack);
process.exit(err.code || -1);
})