Skip to content

Commit 9c773ed

Browse files
committed
Use the current Git SHA for the dbt project
1 parent df090f3 commit 9c773ed

5 files changed

Lines changed: 8 additions & 4 deletions

File tree

splitgraph/cloud/project/dbt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def generate_dbt_plugin_params(repositories: List[str]) -> Tuple[Dict[str, Any],
7878
# the Git pull URL at action runtime (using GITHUB_TOKEN).
7979
credentials = {"git_url": "$THIS_REPO_URL"}
8080

81-
params = {"sources": [_make_source(r) for r in repositories]}
81+
# Same with the branch: we want to inject the current SHA we're running the action for.
82+
params = {"sources": [_make_source(r) for r in repositories], "git_branch": "$THIS_SHA"}
8283

8384
return params, credentials

splitgraph/cloud/project/github_actions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def generate_job(
3030
{
3131
"name": "Set up dbt Git URL",
3232
"run": 'echo "$CREDENTIALS_YML" > splitgraph.credentials.yml && '
33-
'sed -i "s|\\$THIS_REPO_URL|https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY|g" splitgraph.credentials.yml',
33+
'sed -i "s|\\$THIS_REPO_URL|https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY|g" splitgraph.credentials.yml && '
34+
'sed -i "s|\\$THIS_SHA|$GITHUB_SHA|g" splitgraph.yml',
3435
"shell": "bash",
3536
"env": {
3637
"CREDENTIALS_YML": "${{secrets.SPLITGRAPH_CREDENTIALS_YML}}",

test/splitgraph/cloud/project/snapshots/test_generation/test_generate_project_with_dbt/generate_project_dbt/.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
splitgraph_api_secret: ${{ secrets.SPLITGRAPH_API_SECRET }}
5959
- name: Set up dbt Git URL
6060
run: echo "$CREDENTIALS_YML" > splitgraph.credentials.yml && sed -i "s|\$THIS_REPO_URL|https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY|g"
61-
splitgraph.credentials.yml
61+
splitgraph.credentials.yml && sed -i "s|\$THIS_SHA|$GITHUB_SHA|g" splitgraph.yml
6262
shell: bash
6363
env:
6464
CREDENTIALS_YML: ${{secrets.SPLITGRAPH_CREDENTIALS_YML}}

test/splitgraph/cloud/project/snapshots/test_generation/test_generate_project_with_dbt/generate_project_dbt/splitgraph.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ repositories:
9696
namespace: myns
9797
repository: airbyte-postgres
9898
hash_or_tag: latest
99+
git_branch: $THIS_SHA
99100
is_live: false
100101
tables: {}
101102
metadata:

test/splitgraph/cloud/project/test_dbt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def test_generate_dbt_plugin_params():
1212
["some-data/source", "some-other/data-raw", "and-third/data"]
1313
) == (
1414
{
15+
"git_branch": "$THIS_SHA",
1516
"sources": [
1617
{
1718
"dbt_source_name": "some_data_source",
@@ -31,7 +32,7 @@ def test_generate_dbt_plugin_params():
3132
"repository": "data",
3233
"hash_or_tag": "latest",
3334
},
34-
]
35+
],
3536
},
3637
{"git_url": "$THIS_REPO_URL"},
3738
)

0 commit comments

Comments
 (0)