Skip to content

Commit

Permalink
Add option to specify git_sha for cloud (#10)
Browse files Browse the repository at this point in the history
* Add option to specify git_sha for cloud

* more explaining for git_sha
  • Loading branch information
chamini2 authored Jul 25, 2022
1 parent 5c0affe commit d4c2307
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ This action lets you trigger a job run on [dbt Cloud](https://cloud.getdbt.com),
- `dbt_cloud_account_id` - dbt Cloud Account ID
- `dbt_cloud_job_id` - dbt Cloud Job ID


### Optional
- `cause` - Cause message to use [Default=`"Triggered by a GitHub Action"`]
- `interval` - The interval between polls in seconds [Default=`30`]
- `cause` - Cause message to use (Default=`"Triggered by a GitHub Action"`)
- `git_sha` - The git SHA (e.g. commit) to checkout before running dbt Cloud Job. This refers to the state your repository is when running. ([dbt API docs](https://docs.getdbt.com/dbt-cloud/api-v2#tag/Jobs/operation/triggerRun))
- `interval` - The interval between polls in seconds (Default=`30`)

We recommend passing sensitive variables as GitHub secrets. [Example usage](https://github.com/fal-ai/fal_bike_example/blob/main/.github/workflows/fal_dbt.yml).

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
description: "Job trigger cause"
required: true
default: "Triggered by a GitHub Action"
git_sha:
description: "The git SHA to execute dbt Cloud Job"
required: false
interval:
description: "Interval between polls in seconds"
required: false
Expand Down
21 changes: 13 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@ function sleep(ms) {
});
}

async function runJob(account_id, job_id, cause) {
res = await dbt_cloud_api.post(`/accounts/${account_id}/jobs/${job_id}/run/`, {
cause: cause
})
async function runJob(account_id, job_id, cause, git_sha) {
let body = { cause: cause }

if (git_sha) {
body['git_sha'] = git_sha
}

let res = await dbt_cloud_api.post(`/accounts/${account_id}/jobs/${job_id}/run/`, body)
return res.data;
}

async function getJobRun(account_id, run_id) {
res = await dbt_cloud_api.get(`/accounts/${account_id}/runs/${run_id}/`);
let res = await dbt_cloud_api.get(`/accounts/${account_id}/runs/${run_id}/`);
return res.data;
}

async function getArtifacts(account_id, run_id) {
res = await dbt_cloud_api.get(`/accounts/${account_id}/runs/${run_id}/artifacts/run_results.json`);
run_results = res.data;
let res = await dbt_cloud_api.get(`/accounts/${account_id}/runs/${run_id}/artifacts/run_results.json`);
let run_results = res.data;

core.info('Saving artifacts in target directory')
const dir = './target';
Expand All @@ -60,8 +64,9 @@ async function executeAction() {
const account_id = core.getInput('dbt_cloud_account_id');
const job_id = core.getInput('dbt_cloud_job_id');
const cause = core.getInput('cause');
const git_sha = core.getInput('git_sha') || null;

let res = await runJob(account_id, job_id, cause);
let res = await runJob(account_id, job_id, cause, git_sha);
let run_id = res.data.id;

core.info(`Triggered job. ${res.data.href}`);
Expand Down

0 comments on commit d4c2307

Please sign in to comment.