|
| 1 | +name: Cleanup stale CI schemas |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Daily at 03:00 UTC |
| 6 | + - cron: "0 3 * * *" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + max-age-hours: |
| 10 | + type: string |
| 11 | + required: false |
| 12 | + default: "24" |
| 13 | + description: Drop schemas older than this many hours |
| 14 | + |
| 15 | +env: |
| 16 | + # Re-use the dbt-data-reliability integration-test project so we get the |
| 17 | + # cleanup macro (drop_stale_ci_schemas) without duplicating it. |
| 18 | + TESTS_DIR: ${{ github.workspace }}/dbt-data-reliability/integration_tests |
| 19 | + |
| 20 | +jobs: |
| 21 | + cleanup: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + warehouse-type: |
| 27 | + - snowflake |
| 28 | + - bigquery |
| 29 | + - redshift |
| 30 | + - databricks_catalog |
| 31 | + - athena |
| 32 | + steps: |
| 33 | + - name: Checkout dbt package |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + repository: elementary-data/dbt-data-reliability |
| 37 | + path: dbt-data-reliability |
| 38 | + |
| 39 | + - name: Setup Python |
| 40 | + uses: actions/setup-python@v6 |
| 41 | + with: |
| 42 | + python-version: "3.10" |
| 43 | + cache: "pip" |
| 44 | + |
| 45 | + - name: Install dbt |
| 46 | + run: > |
| 47 | + pip install |
| 48 | + "dbt-core" |
| 49 | + "dbt-${{ (matrix.warehouse-type == 'databricks_catalog' && 'databricks') || (matrix.warehouse-type == 'athena' && 'athena-community') || matrix.warehouse-type }}" |
| 50 | +
|
| 51 | + - name: Write dbt profiles |
| 52 | + env: |
| 53 | + CI_WAREHOUSE_SECRETS: ${{ secrets.CI_WAREHOUSE_SECRETS || '' }} |
| 54 | + run: | |
| 55 | + if [ -z "$CI_WAREHOUSE_SECRETS" ]; then |
| 56 | + echo "::error::Missing required secret: CI_WAREHOUSE_SECRETS" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + # The cleanup job doesn't create schemas, but generate_profiles.py |
| 60 | + # requires --schema-name. Use a dummy value. |
| 61 | + python "${{ github.workspace }}/dbt-data-reliability/integration_tests/profiles/generate_profiles.py" \ |
| 62 | + --template "${{ github.workspace }}/dbt-data-reliability/integration_tests/profiles/profiles.yml.j2" \ |
| 63 | + --output ~/.dbt/profiles.yml \ |
| 64 | + --schema-name "cleanup_placeholder" |
| 65 | +
|
| 66 | + - name: Install dbt deps |
| 67 | + working-directory: ${{ env.TESTS_DIR }}/dbt_project |
| 68 | + run: dbt deps |
| 69 | + |
| 70 | + - name: Symlink local elementary package |
| 71 | + run: ln -sfn ${{ github.workspace }}/dbt-data-reliability ${{ env.TESTS_DIR }}/dbt_project/dbt_packages/elementary |
| 72 | + |
| 73 | + - name: Drop stale CI schemas |
| 74 | + working-directory: ${{ env.TESTS_DIR }}/dbt_project |
| 75 | + env: |
| 76 | + MAX_AGE_HOURS: ${{ inputs.max-age-hours || '24' }} |
| 77 | + run: | |
| 78 | + if ! [[ "$MAX_AGE_HOURS" =~ ^[0-9]+$ ]]; then |
| 79 | + echo "::error::max-age-hours must be a non-negative integer" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | + ARGS=$(printf '{"prefixes":["py_"],"max_age_hours":%s}' "$MAX_AGE_HOURS") |
| 83 | + dbt run-operation drop_stale_ci_schemas \ |
| 84 | + --args "$ARGS" \ |
| 85 | + -t "${{ matrix.warehouse-type }}" |
0 commit comments