Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate dbt target and state directories to properly support slim CI #69

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/variables/dbt.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CACHE_NAME=dbt-cache
MANIFEST_DIR=dbt/target
PROJECT_DIR=dbt
STATE_DIR=state
TARGET_DIR=target
21 changes: 13 additions & 8 deletions .github/workflows/build_and_test_dbt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
- name: Configure dbt environment
uses: ./.github/actions/configure_dbt_environment

- name: Cache dbt manifest
- name: Cache dbt state directory
id: cache
uses: actions/cache@v3
with:
path: ${{ env.MANIFEST_DIR }}
path: ${{ env.PROJECT_DIR }}/${{ env.STATE_DIR }}
key: ${{ env.CACHE_NAME }}-${{ env.CACHE_KEY }}
restore-keys: |
${{ env.CACHE_NAME }}-data-catalog
Expand All @@ -61,23 +61,28 @@ jobs:
- name: Build models
run: |
if [[ $MODIFIED_RESOURCES_ONLY == 'true' ]]; then
echo "Running build on modified resources only"
dbt run --target "$TARGET" -s state:modified --defer --state target/
echo "Running build on modified/new resources only"
dbt run -t "$TARGET" -s state:modified state:new --defer --state "$STATE_DIR"
else
echo "Running build on all resources"
dbt run --target "$TARGET"
dbt run -t "$TARGET"
fi
working-directory: ${{ env.PROJECT_DIR }}
shell: bash

- name: Test models
run: |
if [[ $MODIFIED_RESOURCES_ONLY == 'true' ]]; then
echo "Running tests on modified resources only"
dbt test --target "$TARGET" -s state:modified --state target/
echo "Running tests on modified/new resources only"
dbt test -t "$TARGET" -s state:modified state:new --state "$STATE_DIR"
else
echo "Running tests on all resources"
dbt test --target "$TARGET"
dbt test -t "$TARGET"
fi
working-directory: ${{ env.PROJECT_DIR }}
shell: bash

- name: Move dbt manifest directory to update cache
run: mv "$TARGET_DIR" "$STATE_DIR"
working-directory: ${{ env.PROJECT_DIR }}
shell: bash
4 changes: 2 additions & 2 deletions dbt/models/default/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ models:
- pin
- year
config:
error_if: ">280662"
error_if: ">280679"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per usual these days, I also had to bump these thresholds to get tests to pass. Billy is still investigating but his hunch is that the assumptions behind these two tests are not actually correct.

# Unique by case number and year
- unique_combination_of_columns:
name: vw_pin_appeal_unique_by_case_number_and_year
combination_of_columns:
- year
- case_no
config:
error_if: ">365929"
error_if: ">366017"
# `change` should be an enum
- expression_is_true:
name: vw_pin_appeal_no_unexpected_change_values
Expand Down