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: runs:
using: 'node12' using: 'node12'
main: 'dist/index.js' main: 'index.js'
branding: branding:
icon: 'git-commit' icon: 'git-commit'

View File

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