Skip to content

Commit

Permalink
Remove git sha checkout and return as output
Browse files Browse the repository at this point in the history
  • Loading branch information
chamini2 committed Jul 21, 2022
1 parent 45c99c4 commit 061ff3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
11 changes: 7 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
37 changes: 11 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 061ff3b

Please sign in to comment.