Skip to content

Commit

Permalink
Merge tag '2.4.2' into upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasnain Yousuf - @codvlpr committed Jul 10, 2023
2 parents 80d47e1 + adf7358 commit bd55e57
Show file tree
Hide file tree
Showing 65 changed files with 1,142 additions and 396 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/ci_lint_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI lint package

on:
workflow_dispatch:
# all PRs, important to note that `pull_request_target` workflows
# will run in the context of the target branch of a PR
pull_request_target:

env:
# These are configured in GitHub secrets
DBT_PROFILES_DIR: ${{ github.workspace }}/integration_test_project
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_SNOWFLAKE_TEST_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_USER: ${{ secrets.SNOWFLAKE_TEST_USER }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_PASSWORD: ${{ secrets.SNOWFLAKE_TEST_PASSWORD }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_ROLE: ${{ secrets.SNOWFLAKE_TEST_ROLE }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_DATABASE: ${{ secrets.SNOWFLAKE_TEST_DATABASE }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_WAREHOUSE }}
DBT_ENV_SECRET_DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
DBT_ENV_SECRET_DATABRICKS_HTTP_PATH: ${{ secrets.DATABRICKS_HTTP_PATH }}
DBT_ENV_SECRET_DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
DBT_ENV_SECRET_GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
# Env vars to test invocations model
DBT_CLOUD_PROJECT_ID: 123
DBT_CLOUD_JOB_ID: ABC
DBT_CLOUD_RUN_REASON: "String with 'quotes' !"
TEST_ENV_VAR_1: TEST_VALUE
TEST_ENV_VAR_NUMBER: 3
TEST_ENV_VAR_EMPTY: ""
TEST_ENV_VAR_WITH_QUOTE: "Triggered via Apache Airflow by task 'trigger_dbt_cloud_job_run' in the airtable_ingest DAG."
DBT_ENV_CUSTOM_ENV_FAVOURITE_DBT_PACKAGE: dbt_artifacts

jobs:
sqlfluff-lint-models:
name: Lint dbt models using SQLFluff
runs-on: ubuntu-latest
environment:
name: Approve Integration Tests

steps:
- name: Checkout Branch
uses: actions/checkout@v3
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-snowflake~=1.5.0 sqlfluff-templater-dbt

- name: Test database connection
run: dbt debug

- name: Install dbt packages
run: dbt deps

- name: Get changed files
id: get_file_changes
uses: trilom/file-changes-action@v1.2.4
with:
output: " "

- name: Get new and changed .sql files in /models to lint
id: get_files_to_lint
shell: bash -l {0}
run: |
# Set the command in the $() brackets as an output to use in later steps
echo "lintees=$(
# Issue where grep regular expressions don't work as expected on the
# Github Actions shell, check dbt/models/ folder
echo \
$(echo ${{ steps.get_file_changes.outputs.files_modified }} |
tr -s ' ' '\n' |
grep -E '^models.*[.]sql$' |
tr -s '\n' ' ') \
$(echo ${{ steps.get_file_changes.outputs.files_added }} |
tr -s ' ' '\n' |
grep -E '^models.*[.]sql$' |
tr -s '\n' ' ')
)" >> $GITHUB_OUTPUT
- name: Lint dbt models
if: steps.get_files_to_lint.outputs.lintees != ''
shell: bash -l {0}
run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} --write-output annotations.json

- name: Annotate
uses: yuzutech/annotations-action@v0.4.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
title: "SQLFluff Lint"
input: "./annotations.json"
199 changes: 98 additions & 101 deletions .github/workflows/ci_test_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
# These are configured in GitHub secrets
DBT_PROFILES_DIR: /home/runner/work/${{ github.event.repository.name }}/${{ github.event.repository.name }}/integration_test_project
DBT_PROFILES_DIR: ${{ github.workspace }}/integration_test_project
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_SNOWFLAKE_TEST_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_USER: ${{ secrets.SNOWFLAKE_TEST_USER }}
Expand All @@ -20,147 +20,144 @@ env:
DBT_ENV_SECRET_DATABRICKS_HTTP_PATH: ${{ secrets.DATABRICKS_HTTP_PATH }}
DBT_ENV_SECRET_DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
DBT_ENV_SECRET_GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
# Env var to test version
LAST_RELEASE_SUPPORTED_DBT_VERSION: 1_4_0 # A dbt version supported by both the last release and this one
# Env vars to test invocations model
DBT_CLOUD_PROJECT_ID: 123
DBT_CLOUD_JOB_ID: ABC
DBT_CLOUD_RUN_REASON: "String with 'quotes' !"
TEST_ENV_VAR_1: TEST_VALUE
TEST_ENV_VAR_NUMBER: 3
TEST_ENV_VAR_EMPTY: ""
TEST_ENV_VAR_WITH_QUOTE: "Triggered via Apache Airflow by task 'trigger_dbt_cloud_job_run' in the airtable_ingest DAG."
DBT_ENV_CUSTOM_ENV_FAVOURITE_DBT_PACKAGE: dbt_artifacts


jobs:
integration-snowflake:
integration:
strategy:
fail-fast: false # Don't fail one DWH if the others fail
matrix:
warehouse: ["snowflake", "bigquery"]
runs-on: ubuntu-latest
environment:
name: Approve Integration Tests
permissions:
contents: "read"
id-token: "write"

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get latest release
uses: rez0n/actions-github-release@main
id: latest_release
env:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
type: "stable"

- name: Checkout latest release
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR
ref: ${{ steps.latest_release.outputs.release }}

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '3.8.x'
architecture: 'x64'
python-version: "3.8.x"
architecture: "x64"

- name: Install tox
run: python3 -m pip install tox

- name: Run Snowflake Tests
run: tox -e integration_snowflake
- id: auth-on-release
if: ${{ matrix.warehouse == 'bigquery' }}
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}

integration-databricks:
runs-on: ubuntu-latest
environment:
name: Approve Integration Tests
- name: Build tables for latest release
env:
DBT_VERSION: "noversion"
run: tox -e integration_${{ matrix.warehouse }}

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR

- uses: actions/setup-python@v2
# Need to get the auth file again
- id: auth-on-pr
if: ${{ matrix.warehouse == 'bigquery' }}
uses: google-github-actions/auth@v1
with:
python-version: '3.8.x'
architecture: 'x64'

- name: Install tox
run: python3 -m pip install tox

- name: Run Databricks Tests
run: tox -e integration_databricks
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}

integration-bigquery:
- name: Run Tests on PR
run: tox -e integration_${{ matrix.warehouse }}_${{ env.LAST_RELEASE_SUPPORTED_DBT_VERSION }}

single-run-different-versions:
needs: integration
strategy:
fail-fast: false # Don't fail one DWH if the others fail
matrix:
warehouse: ["snowflake", "bigquery"]
# When supporting a new version, update the list here
version: ["1_3_0", "1_4_0", "1_5_0"]
runs-on: ubuntu-latest
environment:
name: Approve Integration Tests
permissions:
contents: 'read'
id-token: 'write'
contents: "read"
id-token: "write"

steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '3.8.x'
architecture: 'x64'
python-version: "3.8.x"
architecture: "x64"

- name: Install tox
run: python3 -m pip install tox

- id: auth
uses: google-github-actions/auth@v0.4.0
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}

- name: Run BigQuery Tests
run: tox -e integration_bigquery

sqlfluff-lint-models:
name: Lint dbt models using SQLFluff
runs-on: ubuntu-latest
environment:
name: Approve Integration Tests

steps:
- name: Checkout Branch
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
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-snowflake~=1.3.0 sqlfluff-templater-dbt

- name: Test database connection
run: dbt debug

- name: Install dbt packages
run: dbt deps

- name: Get changed files
id: get_file_changes
uses: trilom/file-changes-action@v1.2.4
with:
output: ' '

- name: Get new and changed .sql files in /models to lint
id: get_files_to_lint
shell: bash -l {0}
run: |
# Set the command in the $() brackets as an output to use in later steps
echo "::set-output name=lintees::$(
# Issue where grep regular expressions don't work as expected on the
# Github Actions shell, check dbt/models/ folder
echo \
$(echo ${{ steps.get_file_changes.outputs.files_modified }} |
tr -s ' ' '\n' |
grep -E '^models.*[.]sql$' |
tr -s '\n' ' ') \
$(echo ${{ steps.get_file_changes.outputs.files_added }} |
tr -s ' ' '\n' |
grep -E '^models.*[.]sql$' |
tr -s '\n' ' ')
)"
- name: Lint dbt models
if: steps.get_files_to_lint.outputs.lintees != ''
shell: bash -l {0}
run: |
sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json
sed -i '/^\[/!d' annotations.json # see https://github.com/sqlfluff/sqlfluff/issues/2244
- name: Annotate
uses: yuzutech/annotations-action@v0.3.0
# Need to get the auth file again
- id: auth-on-pr
if: ${{ matrix.warehouse == 'bigquery' }}
uses: google-github-actions/auth@v1
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
title: "SQLFluff Lint"
input: "./annotations.json"
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}

- name: Run Tests on PR
env:
DBT_VERSION: ${{ matrix.version }}
run: tox -e integration_${{ matrix.warehouse }}_${{ matrix.version }}

# Databricks doesn't like the matrix strategy, so moving back to the old integration testing without versioning
# integration-databricks:
# runs-on: ubuntu-latest
# environment:
# name: Approve Integration Tests

# steps:
# - name: Checkout
# uses: actions/checkout@v3
# with:
# ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR

# - uses: actions/setup-python@v4
# with:
# python-version: '3.8.x'
# architecture: 'x64'

# - name: Install tox
# run: python3 -m pip install tox

# - name: Run Databricks Tests
# env:
# DBT_VERSION: ''
# run: tox -e integration_databricks
52 changes: 52 additions & 0 deletions .github/workflows/main_lint_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Main branch lint package

# triggers for the workflow
on:
workflow_dispatch:
push:
branches:
- main

env:
# These are configured in GitHub secrets
DBT_PROFILES_DIR: ${{ github.workspace }}/integration_test_project
DBT_ENV_SECRET_SNOWFLAKE_TEST_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_USER: ${{ secrets.SNOWFLAKE_TEST_USER }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_PASSWORD: ${{ secrets.SNOWFLAKE_TEST_PASSWORD }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_ROLE: ${{ secrets.SNOWFLAKE_TEST_ROLE }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_DATABASE: ${{ secrets.SNOWFLAKE_TEST_DATABASE }}
DBT_ENV_SECRET_SNOWFLAKE_TEST_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_WAREHOUSE }}
DBT_ENV_SECRET_DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
DBT_ENV_SECRET_DATABRICKS_HTTP_PATH: ${{ secrets.DATABRICKS_HTTP_PATH }}
DBT_ENV_SECRET_DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
DBT_ENV_SECRET_GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
# Env vars to test invocations model
DBT_CLOUD_PROJECT_ID: 123
DBT_CLOUD_JOB_ID: ABC
DBT_CLOUD_RUN_REASON: "String with 'quotes' !"
TEST_ENV_VAR_1: TEST_VALUE
TEST_ENV_VAR_NUMBER: 3
TEST_ENV_VAR_EMPTY: ""
TEST_ENV_VAR_WITH_QUOTE: "Triggered via Apache Airflow by task 'trigger_dbt_cloud_job_run' in the airtable_ingest DAG."
DBT_ENV_CUSTOM_ENV_FAVOURITE_DBT_PACKAGE: dbt_artifacts

jobs:
sqlfluff-lint-models:
name: Lint dbt models using SQLFluff
runs-on: ubuntu-latest

steps:
- name: Checkout branch
uses: actions/checkout@v3

- name: Install Python packages
run: python -m pip install dbt-snowflake~=1.5.0 sqlfluff-templater-dbt

- name: Test database connection
run: dbt debug

- name: Install dbt packages
run: dbt deps

- name: Lint dbt models
run: sqlfluff lint models --ignore parsing
Loading

0 comments on commit bd55e57

Please sign in to comment.