@@ -2,8 +2,9 @@ name: "20: 🏎️ dbt Release Branch Validations"
22
33on : # yamllint disable-line rule:truthy
44 pull_request :
5- branches :
6- - main
5+ types : [opened, synchronize, labeled, unlabeled]
6+ # No branch restrictions for validate-branch job to run on all PRs
7+ # dbt job will be conditionally run based on target branch
78 paths :
89 - transform/**/*
910
@@ -16,6 +17,83 @@ concurrency:
1617 cancel-in-progress : true
1718
1819jobs :
20+ add-deploy-marker :
21+ if : github.event.action == 'labeled' && github.event.label.name == 'full-refresh'
22+ runs-on : ubuntu-latest
23+ name : Add Deploy Marker to PR Description
24+
25+ steps :
26+ - name : Add deploy marker to PR description
27+ uses : actions/github-script@v6
28+ with :
29+ script : |
30+ const { data: pullRequest } = await github.rest.pulls.get({
31+ owner: context.repo.owner,
32+ repo: context.repo.repo,
33+ pull_number: context.issue.number
34+ });
35+
36+ let body = pullRequest.body || '';
37+
38+ // Check if marker already exists
39+ if (!body.includes('[deploy:full-refresh]')) {
40+ // Add marker to the end of the description
41+ const newBody = body + '\n\n[deploy:full-refresh]';
42+
43+ await github.rest.pulls.update({
44+ owner: context.repo.owner,
45+ repo: context.repo.repo,
46+ pull_number: context.issue.number,
47+ body: newBody
48+ });
49+
50+ // Also add a comment explaining what happened
51+ await github.rest.issues.createComment({
52+ owner: context.repo.owner,
53+ repo: context.repo.repo,
54+ issue_number: context.issue.number,
55+ body: '🚀 **Full-refresh deployment marker added to PR description**\n\nThe `[deploy:full-refresh]` marker has been automatically added to this PR description. When merged, this will trigger a full-refresh deployment.'
56+ });
57+ }
58+
59+ remove-deploy-marker :
60+ if : github.event.action == 'unlabeled' && github.event.label.name == 'full-refresh'
61+ runs-on : ubuntu-latest
62+ name : Remove Deploy Marker from PR Description
63+
64+ steps :
65+ - name : Remove deploy marker from PR description
66+ uses : actions/github-script@v6
67+ with :
68+ script : |
69+ const { data: pullRequest } = await github.rest.pulls.get({
70+ owner: context.repo.owner,
71+ repo: context.repo.repo,
72+ pull_number: context.issue.number
73+ });
74+
75+ let body = pullRequest.body || '';
76+
77+ // Remove the marker if it exists
78+ if (body.includes('[deploy:full-refresh]')) {
79+ const newBody = body.replace(/\n*\[deploy:full-refresh\]\n*/g, '').trim();
80+
81+ await github.rest.pulls.update({
82+ owner: context.repo.owner,
83+ repo: context.repo.repo,
84+ pull_number: context.issue.number,
85+ body: newBody
86+ });
87+
88+ // Add a comment explaining what happened
89+ await github.rest.issues.createComment({
90+ owner: context.repo.owner,
91+ repo: context.repo.repo,
92+ issue_number: context.issue.number,
93+ body: '✅ **Full-refresh deployment marker removed**\n\nThe `[deploy:full-refresh]` marker has been removed from this PR description. Normal deployment will occur on merge.'
94+ });
95+ }
96+
1997 validate-branch :
2098 runs-on : ubuntu-latest
2199 name : Validate Branch Names and Merge Rules and assure branch has changes from main
@@ -34,8 +112,10 @@ jobs:
34112 run : automate/git/branch_validator.py
35113
36114 dbt :
115+ if : github.base_ref == 'main' && github.event.action != 'unlabeled' && (github.event.action != 'labeled' || github.event.label.name == 'full-refresh')
37116 name : Pull Request dbt Tests
38117 runs-on : ubuntu-latest
118+ needs : [validate-branch]
39119
40120 # Set environment variables in
41121 # https://github.com//<your org>/<your repo>/settings/variables/actions
44124 # https://github.com/<org>/<repo>/settings/environments
45125 # environment: PR_ENV
46126
47- # most people should use this one
127+ # Most people should use this docker image
48128 container : datacoves/ci-basic-dbt-snowflake:3.4
49129
50130 defaults :
74154 # cannot be applied when using the Datacoves permifrost security model.
75155 DATACOVES__DROP_DB_ON_FAIL : ${{ vars.DATACOVES__DROP_DB_ON_FAIL }}
76156
157+ # Full refresh control variables
158+ FULL_REFRESH_FLAG : ${{ contains(github.event.pull_request.labels.*.name, 'full-refresh') && '--full-refresh' || '' }}
159+
77160 steps :
78161 - name : Checkout branch
79162@@ -123,12 +206,12 @@ jobs:
123206
124207 # #### Real dbt run given that we passed governance checks
125208 - name : Run dbt build slim mode
126- if : ${{ steps.prod_manifest.outputs.manifest_found == 'true' && contains(github.event.pull_request.labels.*.name, 'full-refresh') != true }}
127- run : " dbt build --fail-fast --defer --state logs --select state:modified+"
209+ if : ${{ steps.prod_manifest.outputs.manifest_found == 'true' }}
210+ run : " dbt build --fail-fast --defer --state logs --select state:modified+ ${{ env.FULL_REFRESH_FLAG }} "
128211
129212 - name : Run dbt build full run
130- if : ${{ steps.prod_manifest.outputs.manifest_found == 'false' || contains(github.event.pull_request.labels.*.name, 'full-refresh') }}
131- run : " dbt build --fail-fast"
213+ if : ${{ steps.prod_manifest.outputs.manifest_found == 'false' }}
214+ run : " dbt build --fail-fast ${{ env.FULL_REFRESH_FLAG }} "
132215
133216 - name : Grant access to QA_TEMP database
134217 if : steps.check_qa_created_today.outputs.qa_created_today != 'true'
@@ -141,6 +224,7 @@ jobs:
141224 dbt --no-write-json run-operation swap_database --args '{db1: ${{ env.DATACOVES__MAIN__DATABASE }}, db2: ${{ env.DATACOVES__MAIN__DATABASE_QA }}, create_missing_db: true}'
142225 dbt --no-write-json run-operation drop_recreate_db --args '{db_name: ${{ env.DATACOVES__MAIN__DATABASE }}, recreate: False}'
143226
227+
144228 # # We drop the database when there is a failure to grant access to the db because
145229 # # most likely the schema was not set properly in dbt_project.yml so models built to default schema
146230 # - name: Drop PR database on Failure to grant security access
@@ -149,17 +233,21 @@ jobs:
149233
150234 dbt-job-status :
151235 runs-on : ubuntu-latest
152- needs : [dbt]
236+ needs : [add-deploy-marker, remove-deploy-marker, validate-branch, dbt]
153237 if : always()
154238 steps :
155- - name : Comment PR with dbt status
239+ - name : Comment PR with workflow status
156240 uses : thollander/actions-comment-pull-request@v2
157241 with :
158242 message : |
159243 ## 🧪 dbt Workflow Status
160- - **Job**: Pull Request dbt Tests → **${{ needs.dbt.result }}**
244+ - **Branch Validation**: ${{ needs.validate-branch.result }}
245+ - **Deploy Marker Management**: ${{ (needs.add-deploy-marker.result != 'skipped' && needs.add-deploy-marker.result) || (needs.remove-deploy-marker.result != 'skipped' && needs.remove-deploy-marker.result) || 'skipped' }}
246+ - **dbt Validations**: ${{ needs.dbt.result }}
161247
162- ${{ needs.dbt.result == 'skipped' && '⏭️ _Skipped because no transform/ files were changed_' || '' }}
248+ ${{ needs.validate-branch.result == 'failure' && '❌ _Branch validation failed_' || '' }}
249+ ${{ needs.dbt.result == 'skipped' && '⏭️ _dbt validations skipped_' || '' }}
163250 ${{ needs.dbt.result == 'success' && '✅ _All dbt validations passed_' || '' }}
164251 ${{ needs.dbt.result == 'failure' && '❌ _dbt validations failed_' || '' }}
252+ ${{ (needs.add-deploy-marker.result == 'success' || needs.remove-deploy-marker.result == 'success') && '📝 _Deploy marker updated in PR description_' || '' }}
165253 comment_tag : dbt-workflow-status
0 commit comments