Skip to content

Add Tests and best practices #100

Add Tests and best practices

Add Tests and best practices #100

# orchestrate-workflow.yml
name: 🎯 Orchestrate Airflow Validations
on: # yamllint disable-line rule:truthy
pull_request:
paths:
- orchestrate/*
- orchestrate/**/*
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# This cancels a run if another change is pushed to the same branch
concurrency:
group: orchestrate-${{ github.ref }}
cancel-in-progress: true
jobs:
airflow:
name: Pull Request Airflow Tests
runs-on: ubuntu-latest
# container: datacoves/ci-airflow-dbt-snowflake:3.2
container: datacoves/ci-airflow-dbt-snowflake:3.3.202412101445-ad8fa694
env:
AIRFLOW__CORE__DAGS_FOLDER: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/orchestrate/dags
AIRFLOW__CORE__DAGBAG_IMPORT_TIMEOUT: 300
AIRFLOW__ARTIFACTS_PATH: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/orchestrate
DBT_PROFILES_DIR: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/automate/dbt
DATACOVES__DBT_HOME: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/transform
DATACOVES__REPO_PATH: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
PYTHONPATH: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}
FORCE_COLOR: 1
steps:
- name: Checkout branch
uses: actions/[email protected]
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
# - name: Test DAG structure integrity (DagBag Loading)
# run: "python /usr/app/load_dagbag.py"
# - name: Test DBT Sources against DAGs' YAML files
# run: "python /usr/app/test_dags.py --dag-loadtime-threshold 1 --check-variable-usage"
# - name: Custom Airflow Testss
# run: "pytest $AIRFLOW__ARTIFACTS_PATH/test_dags/validate_dags.py"
- name: Test DAGs Best Practices
id: test_dags_best_pratices
run: python /usr/app/test_dags.py --dag-loadtime-threshold 1 --check-variable-usage --write-output --filename airflow_output_best_practices.md
# if write-output is set, the following step will run
- name: Comment PR with Best Practices
uses: thollander/actions-comment-pull-request@v2
with:
filePath: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_output_best_practices.md
comment_tag: Best Practices
# - name: Custom Airflow Tests
# uses: ./.github/actions/pytest-with-warnings
# with:
# pytest_args: "$AIRFLOW__ARTIFACTS_PATH/test_dags/validate_dags.py"
- name: Custom Airflow Tests
run: pytest $AIRFLOW__ARTIFACTS_PATH/test_dags/validate_dags.py > /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_output_custom_tests.md
# - name: Custom Airflow Tests
# uses: dariocurr/pytest-summary@main
# with:
# paths: $AIRFLOW__ARTIFACTS_PATH/test_dags/validate_dags.py
# output: airflow_output_custom_tests.md
# show: all
- name: Comment PR with Custom Tests Results
uses: thollander/actions-comment-pull-request@v2
with:
filePath: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_output_custom_tests.md
comment_tag: Custom Tests
- name: Upload test summary
uses: actions/upload-artifact@v3
with:
name: test-summary
path: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_output_custom_tests.md
if: always()