Skip to content

Add iasWorld dbt tests and namespace all tests #779

Add iasWorld dbt tests and namespace all tests

Add iasWorld dbt tests and namespace all tests #779

name: build-and-test-dbt
on:
pull_request:
branches: [master]
push:
branches: [master]
workflow_dispatch:
inputs:
models:
required: true
description: A space-separated list of dbt models
default: 'default.vw_pin_sale default.vw_pin_universe'
type: string
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 }}
- name: Set command args for building/testing resources
run: |
if [[ $CACHE_HIT == 'true' ]]; then
echo "MODIFIED_RESOURCES_ONLY=true" >> "$GITHUB_ENV"
fi
if [[ $EVENT_NAME == 'workflow_dispatch' ]]; then
echo "MANUALLY_DISPATCHED=true" >> "$GITHUB_ENV"
fi
shell: bash
env:
CACHE_HIT: ${{ steps.cache.outputs.cache-hit }}
EVENT_NAME: ${{ github.event_name }}
- 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
if [[ $MANUALLY_DISPATCHED == 'true' ]]; then
echo "Running build on manually selected resources"
dbt run -t "$TARGET" -s ${{ inputs.models }} --defer --state "$STATE_DIR"
else
echo "Running build on modified/new resources only"
dbt run -t "$TARGET" -s state:modified state:new --defer --state "$STATE_DIR"
fi
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
if [[ $MANUALLY_DISPATCHED == 'true' ]]; then
echo "Running tests on manually selected resources"
dbt test -t "$TARGET" -s ${{ inputs.models }} --exclude "tag:test_qc*" --defer --state "$STATE_DIR"
else
echo "Running tests on modified/new resources only"
dbt test -t "$TARGET" -s state:modified state:new --exclude "tag:test_qc*" --defer --state "$STATE_DIR"
fi
else
echo "Running tests on all resources"
dbt test -t "$TARGET" --exclude "tag:test_qc*"
fi
working-directory: ${{ env.PROJECT_DIR }}
shell: bash
- if: github.ref == 'refs/heads/master' && success()
name: Update dbt state cache
uses: ./.github/actions/save_dbt_cache
with:
path: ${{ env.PROJECT_DIR }}/${{ env.TARGET_DIR }}
key: ${{ env.CACHE_KEY }}