Skip to content

Use docker for CI

Use docker for CI #37

Workflow file for this run

name: Pull Request testing - Run dbt models on BigQuery
on:
pull_request:
paths:
- 'macros/**'
- 'models/**'
- 'integration_tests/**'
- 'dbt_project.yml'
- 'packages.yml'
- 'config.py'
workflow_dispatch:
# GitHub secrets
env:
GITHUB_SHA_OVERRIDE: ${{ github.event.pull_request.head.sha }} # We need the commit hash of the pull request branch's head, the GITHUB_SHA env var is always the base branch in a pull_request_target trigger
DBT_ENV_SECRET_BIGQUERY_TEST_SERVICE_ACCOUNT: ${{ secrets.DBT_ENV_SECRET_BIGQUERY_TEST_SERVICE_ACCOUNT }}
DBT_ENV_SECRET_BIGQUERY_TEST_STORAGE_PROJECT: ${{ secrets.DBT_ENV_SECRET_BIGQUERY_TEST_STORAGE_PROJECT }}
DBT_ENV_SECRET_BIGQUERY_TEST_EXECUTION_PROJECT: ${{ secrets.DBT_ENV_SECRET_BIGQUERY_TEST_EXECUTION_PROJECT }}
DBT_ENV_SECRET_BIGQUERY_TEST_LOCATION: ${{ secrets.DBT_ENV_SECRET_BIGQUERY_TEST_LOCATION }}
DBT_BQ_MONITORING_GCP_PROJECTS: ${{ secrets.DBT_BQ_MONITORING_GCP_PROJECTS }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
concurrency:
cancel-in-progress: true
group: pr-run-models-${{ github.workflow }}-${{ github.ref }}
jobs:
integration-bigquery:
name: Run dbt models on BigQuery to test model validity
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR
- name: Install Python packages
run: python -m pip install dbt-bigquery~=1.8.2 sqlfluff-templater-dbt
- name: Write keyfile if secret is defined
run: |
if [ -z "${{ secrets.DBT_ENV_SECRET_BIGQUERY_TEST_SERVICE_ACCOUNT }}" ]; then
echo "Error: DBT_ENV_SECRET_BIGQUERY_TEST_SERVICE_ACCOUNT is not defined."
else
echo ${{ secrets.DBT_ENV_SECRET_BIGQUERY_TEST_SERVICE_ACCOUNT }} | base64 -d > ./integration_tests/keyfile.json
fi
- name: Setup dbt dependencies
run: |
docker run -i \
-v $(pwd)/integration_tests:/usr/app/ \
-v $(pwd)/keyfile.json:/usr/app/keyfile.json \
$DOCKER_REGISTRY/dbt-bigquery-monitoring-base:main \
-c "dbt deps"
- name: Setup dbt fixtures
run: |
docker run -i \
-v $(pwd)/integration_tests:/usr/app/ \
-v $(pwd)/keyfile.json:/usr/app/keyfile.json \
$DOCKER_REGISTRY/dbt-bigquery-monitoring-base:main \
-c "dbt run -s tag:fixtures"
- name: Run all models once
run: |
docker run -i \
-v $(pwd)/integration_tests:/usr/app/ \
-v $(pwd)/keyfile.json:/usr/app/keyfile.json \
$DOCKER_REGISTRY/dbt-bigquery-monitoring-base:main \
-c "dbt build -s dbt_bigquery_monitoring --full-refresh --empty"
- name: Run all models again to test incremental
run: |
docker run -i \
-v $(pwd)/integration_tests:/usr/app/ \
-v $(pwd)/keyfile.json:/usr/app/keyfile.json \
$DOCKER_REGISTRY/dbt-bigquery-monitoring-base:main \
-c "dbt build -s dbt_bigquery_monitoring --empty"
- name: Run all models again with cloud audit logs
run: |
docker run -i \
-e DBT_BQ_MONITORING_SHOULD_COMBINE_AUDIT_LOGS_AND_INFORMATION_SCHEMA=true \
-e DBT_BQ_MONITORING_GCP_BIGQUERY_AUDIT_LOGS=true \
-v $(pwd)/integration_tests:/usr/app/ \
-v $(pwd)/keyfile.json:/usr/app/keyfile.json \
$DOCKER_REGISTRY/dbt-bigquery-monitoring-base:main \
-c "dbt run -s jobs_from_audit_logs+ --full-refresh --empty"
- name: Run all models again to test incremental with cloud audit logs
run: |
docker run -i \
-e DBT_BQ_MONITORING_SHOULD_COMBINE_AUDIT_LOGS_AND_INFORMATION_SCHEMA=true \
-e DBT_BQ_MONITORING_GCP_BIGQUERY_AUDIT_LOGS=true \
-v $(pwd)/integration_tests:/usr/app/ \
-v $(pwd)/keyfile.json:/usr/app/keyfile.json \
$DOCKER_REGISTRY/dbt-bigquery-monitoring-base:main \
-c "dbt run -s jobs_from_audit_logs+ --empty"