From eda98fb9e50d5c495c5361ac43ea95c52f393459 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Tue, 11 Feb 2020 21:04:18 +0100 Subject: [PATCH] Simplify index.js --- action.yml | 2 +- index.js | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index 31a797e..f6b6077 100644 --- a/action.yml +++ b/action.yml @@ -37,7 +37,7 @@ inputs: runs: using: 'node12' - main: 'dist/index.js' + main: 'index.js' branding: icon: 'git-commit' diff --git a/index.js b/index.js index abba6b7..825e1a7 100644 --- a/index.js +++ b/index.js @@ -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); +})