From 061ff3ba7b5226e28fe106ecd226c148d0d85e9d Mon Sep 17 00:00:00 2001 From: Matteo Ferrando Date: Thu, 21 Jul 2022 10:32:08 -0400 Subject: [PATCH] Remove git sha checkout and return as output --- action.yml | 11 +++++++---- index.js | 37 +++++++++++-------------------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/action.yml b/action.yml index 6eef3a0..10f50ad 100644 --- a/action.yml +++ b/action.yml @@ -1,17 +1,17 @@ name: "dbt Cloud action" -description: "Runs a dbt Cloud job specified by job id" +description: "Runs a dbt Cloud Job specified by Job ID" branding: icon: "cloud" color: "orange" inputs: dbt_cloud_token: - description: "dbt Cloud api token" + description: "dbt Cloud API token" required: true dbt_cloud_account_id: - description: "dbt Cloud account id" + description: "dbt Cloud account ID" required: true dbt_cloud_job_id: - description: "dbt Cloud job id" + description: "dbt Cloud Job ID" required: true cause: description: "Job trigger cause" @@ -21,6 +21,9 @@ inputs: description: "Interval between polls in seconds" required: false default: "30" +outputs: + git_sha: + description: "Repository SHA in which dbt Cloud Job ran" runs: using: "node12" main: "index.js" diff --git a/index.js b/index.js index d2daad9..819ca8e 100644 --- a/index.js +++ b/index.js @@ -91,31 +91,16 @@ async function executeAction() { } } -function checkoutTargetBranch(git_sha) { - core.info(`Checking out ${git_sha}`); - const command = `git -c advice.detachedHead=false checkout ${git_sha}`; - return new Promise((resolve, reject) => { - exec(command, (error, stdout, stderr) => { - if (stderr) { - core.info(`STDERR: ${stderr}`); - } - if (stdout) { - core.info(`STDOUT: ${stdout}`); - } - - if (error) { - // Return to avoid reject and resolve in same Promise - return reject(error); - } - - core.info('Done'); - resolve(); - }); - }) +async function main() { + try { + const git_sha = await executeAction(); + + // GitHub Action output + core.info(`dbt Cloud Job commit SHA is ${git_sha}`) + core.setOutput('git_sha', git_sha); + } catch (e) { + core.setFailed('There has been a problem with running your dbt cloud job:\n' + e.toString()); + } } -executeAction() - .then(git_sha => checkoutTargetBranch(git_sha)) - .catch(e => { - core.setFailed('There has been a problem with running your dbt cloud job: ' + e.toString()); - }); +main();