-
Notifications
You must be signed in to change notification settings - Fork 4
78 lines (68 loc) · 2.45 KB
/
build_and_test_dbt.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: build-and-test-dbt
on:
pull_request:
branches: [master]
push:
branches: [master]
jobs:
build-and-test-dbt:
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint
# so that we can authenticate with AWS
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup dbt
uses: ./.github/actions/setup_dbt
with:
role-to-assume: ${{ secrets.AWS_IAM_ROLE_TO_ASSUME_ARN }}
role-duration-seconds: 14400 # Worst-case time for full build
- name: Restore dbt state cache
id: cache
uses: ./.github/actions/restore_dbt_cache
with:
path: ${{ env.PROJECT_DIR }}/${{ env.STATE_DIR }}
key: ${{ env.CACHE_KEY }}
restore-key: ${{ env.CACHE_RESTORE_KEY }}
- if: steps.cache.outputs.cache-hit == 'true'
name: Set command args to build/test modified resources
run: echo "MODIFIED_RESOURCES_ONLY=true" >> "$GITHUB_ENV"
shell: bash
- if: steps.cache.outputs.cache-hit != 'true'
name: Set command args to build/test all resources
run: echo "MODIFIED_RESOURCES_ONLY=false" >> "$GITHUB_ENV"
shell: bash
- name: Test dbt macros
run: dbt run-operation test_all
working-directory: ${{ env.PROJECT_DIR }}
shell: bash
- name: Build models
run: |
if [[ $MODIFIED_RESOURCES_ONLY == 'true' ]]; then
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 -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/new resources only"
dbt test -t "$TARGET" -s state:modified state:new --state "$STATE_DIR"
else
echo "Running tests on all resources"
dbt test -t "$TARGET"
fi
working-directory: ${{ env.PROJECT_DIR }}
shell: bash
- name: Update dbt state cache
uses: ./.github/actions/save_dbt_cache
with:
path: ${{ env.PROJECT_DIR }}/${{ env.TARGET_DIR }}
key: ${{ env.CACHE_KEY }}