Add Tests and best practices #120
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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.3 | |
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 | |
OUTPUT_FILE: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_validation_tests.md | |
steps: | |
- name: Checkout branch | |
uses: actions/[email protected] | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Test DAGs Load time and variable usage at top level | |
id: test_load_time_variables | |
run: python /usr/app/test_dags.py --dag-loadtime-threshold 1 --check-variable-usage --write-output --filename airflow_test_load_time_variables.md | |
# if write-output is set in the prior step, the following step will run | |
- name: Add PR comment of results of test_load_time_variables tests | |
uses: thollander/actions-comment-pull-request@v2 | |
with: | |
filePath: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_test_load_time_variables.md | |
comment_tag: Test DAGs Load time and variable usage at top level | |
# run: pytest $AIRFLOW__ARTIFACTS_PATH/test_dags/validate_dags.py > /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_validation_tests.md | |
- name: Custom Airflow Validation Tests | |
env: | |
NO_COLOR: 1 | |
run: | | |
pytest "$AIRFLOW__ARTIFACTS_PATH/test_dags/validate_dags.py" > "$OUTPUT_FILE" 2>&1 | |
echo $? > /tmp/exit_code | |
cat "$OUTPUT_FILE" | |
exit $(cat /tmp/exit_code) | |
- name: Verify output file | |
if: always() | |
run: | | |
echo "Checking if file exists:" | |
ls -l "$OUTPUT_FILE" | |
echo "File contents:" | |
cat "$OUTPUT_FILE" | |
- name: Add PR comment of results of custom Airflow validation tests | |
if: always() | |
uses: thollander/actions-comment-pull-request@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
filePath: ${{ env.OUTPUT_FILE }} | |
comment_tag: Custom Tests | |
fail_on_error: true | |
# - name: Add PR comment of results of custom Airflow validation tests | |
# uses: thollander/actions-comment-pull-request@v2 | |
# with: | |
# filePath: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_validation_tests.md | |
# comment_tag: Custom Tests | |
# Do we need this? | |
- name: Upload test summary | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-summary | |
path: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/airflow_validation_tests.md | |
if: always() |