📖 Scenario: You work on a data team that uses dbt to manage data transformations. Your team wants to ensure that every change to the dbt project is reviewed carefully before merging. This helps keep the data models accurate and reliable.
🎯 Goal: You will create a simple PR review workflow for dbt changes. This workflow will run dbt commands to check the changes and show the results in the pull request. This helps your team catch errors early and keep the data pipeline healthy.
📋 What You'll Learn
Create a GitHub Actions workflow file named dbt-pr-review.yml
Set the workflow to run on pull requests to the main branch
Add a job that sets up Python and installs dbt
Run dbt compile to check for syntax errors
Run dbt test to run tests on the changed models
Output the results so reviewers can see if the changes pass
💡 Why This Matters
🌍 Real World
Teams use PR review workflows to catch errors in dbt projects before merging changes. This keeps data models accurate and prevents broken pipelines.
💼 Career
Data engineers and analytics engineers often create and maintain CI/CD workflows for dbt to ensure data quality and reliability.
Progress0 / 4 steps
1
Create the workflow file and trigger
Create a file named .github/workflows/dbt-pr-review.yml. Inside it, start a workflow with the name dbt PR Review that triggers on pull requests to the main branch. Write the YAML lines to set this up.
dbt
Hint
Use name: to name the workflow. Use on: pull_request: branches: - main to trigger on PRs to main.
2
Add a job to set up Python and install dbt
Add a job named dbt-check that runs on ubuntu-latest. Inside the job, add steps to check out the code, set up Python 3.12, and install dbt using pip install dbt-core.
dbt
Hint
Use actions/checkout@v3 to get the code. Use actions/setup-python@v4 with python-version: '3.12'. Then run pip install dbt-core.
3
Add steps to run dbt compile and dbt test
Inside the dbt-check job's steps, add two run commands: one to run dbt compile and one to run dbt test. These commands check the syntax and run tests on the dbt models.
dbt
Hint
Add two steps with run: dbt compile and run: dbt test to check your dbt models.
4
Print the workflow summary output
Add a final step in the dbt-check job to print a message dbt PR review completed. Use a run command with echo to display this message in the workflow logs.
dbt
Hint
Use echo "dbt PR review completed" in a run step to print the message.
Practice
(1/5)
1. What is the main purpose of using a PR (Pull Request) review workflow in dbt projects?
easy
A. To ensure changes are reviewed and tested before merging
B. To speed up merging without checks
C. To delete old branches automatically
D. To create new dbt models without review
Solution
Step 1: Understand PR review workflow purpose
PR review workflows are designed to check code changes carefully before they become part of the main project.
Step 2: Identify the correct purpose in dbt context
In dbt, this means reviewing and testing data models to avoid errors and keep the project reliable.
Final Answer:
To ensure changes are reviewed and tested before merging -> Option A
Quick Check:
PR review = review and test before merge [OK]
Hint: PR reviews catch errors before merging [OK]
Common Mistakes:
Thinking PRs speed up merging without checks
Confusing PR reviews with branch deletion
Assuming PRs create models automatically
2. Which of the following is the correct syntax to create a new branch for a dbt PR workflow using Git?
easy
A. git branch new-feature
B. git merge new-feature
C. git push new-feature
D. git checkout -b new-feature
Solution
Step 1: Understand Git branch creation commands
To create and switch to a new branch in one step, use git checkout -b branch-name.
Step 2: Identify the correct command for new branch creation
git checkout -b new-feature uses git checkout -b new-feature, which creates and switches to the branch.
Final Answer:
git checkout -b new-feature -> Option D
Quick Check:
New branch creation = git checkout -b [OK]
Hint: Use git checkout -b to create and switch branch [OK]
Common Mistakes:
Using git branch without switching
Confusing merge with branch creation
Trying to push before creating branch
3. Given this simplified dbt test command in a PR workflow:
dbt test --models my_model
What will happen if the model my_model has a failing test?
medium
A. The command deletes the model automatically
B. The command completes successfully with no error
C. The command fails and returns a non-zero exit code
D. The command ignores the test and continues
Solution
Step 1: Understand dbt test behavior
When a dbt test fails, the command returns a non-zero exit code indicating failure.
Step 2: Identify the effect of a failing test in PR workflow
This failure stops the PR from merging until the issue is fixed.
Final Answer:
The command fails and returns a non-zero exit code -> Option C
Quick Check:
Failing test = command fails with error code [OK]
Hint: Failing dbt tests cause command to fail [OK]
Common Mistakes:
Assuming tests pass silently
Thinking dbt deletes models on failure
Believing tests are ignored automatically
4. You wrote a dbt model and created a PR, but the automated tests fail. Which of the following is the best way to debug the issue?
medium
A. Ignore the test failures and merge the PR
B. Check the test logs and fix the model SQL accordingly
C. Delete the model file and close the PR
D. Merge the PR and fix errors later in production
Solution
Step 1: Understand the role of test logs in debugging
Test logs show which tests failed and why, helping identify SQL errors or data issues.
Step 2: Choose the correct debugging approach
Fixing the model SQL based on logs ensures the PR passes tests before merging.
Final Answer:
Check the test logs and fix the model SQL accordingly -> Option B
Quick Check:
Debug by reviewing logs and fixing code [OK]
Hint: Use test logs to find and fix errors [OK]
Common Mistakes:
Ignoring test failures
Deleting models unnecessarily
Merging broken code into main branch
5. In a team using dbt with PR review workflows, which combination of practices best ensures data model quality before merging?
hard
A. Create feature branches, run automated tests, and require team approval
B. Directly commit to main branch and run tests after merging
C. Skip tests and rely on manual checks only
D. Merge PRs without reviews to speed up deployment
Solution
Step 1: Identify best practices in PR workflows
Using feature branches isolates changes, automated tests catch errors early, and team approval ensures quality review.
Step 2: Compare options to find the best combination
Create feature branches, run automated tests, and require team approval includes all these practices, while others skip important steps or risk errors.
Final Answer:
Create feature branches, run automated tests, and require team approval -> Option A
Quick Check:
Branch + tests + review = quality assurance [OK]
Hint: Combine branches, tests, and reviews for quality [OK]
Common Mistakes:
Committing directly to main branch
Skipping automated tests
Merging without team review
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.