-
Notifications
You must be signed in to change notification settings - Fork 210
feat: add daily cleanup workflow for stale CI schemas #2128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5447b19
feat: add weekly cleanup workflow for stale CI schemas
devin-ai-integration[bot] d70c86b
fix: update workflow to call macro without elementary. prefix
devin-ai-integration[bot] 225a5fb
chore: change cleanup schedule from weekly to daily
devin-ai-integration[bot] c208087
fix: address CodeRabbit review comments
devin-ai-integration[bot] a495427
fix: remove dbt version pin to match other workflows
devin-ai-integration[bot] 3cf52fa
Merge branch 'master' into devin/1772278180-cleanup-stale-ci-schemas
haritamar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| name: Cleanup stale CI schemas | ||
|
|
||
| on: | ||
| schedule: | ||
| # Daily at 03:00 UTC | ||
| - cron: "0 3 * * *" | ||
| workflow_dispatch: | ||
| inputs: | ||
| max-age-hours: | ||
| type: string | ||
| required: false | ||
| default: "24" | ||
| description: Drop schemas older than this many hours | ||
|
|
||
| env: | ||
| # Re-use the dbt-data-reliability integration-test project so we get the | ||
| # cleanup macro (drop_stale_ci_schemas) without duplicating it. | ||
| TESTS_DIR: ${{ github.workspace }}/dbt-data-reliability/integration_tests | ||
|
|
||
| jobs: | ||
| cleanup: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| warehouse-type: | ||
| - snowflake | ||
| - bigquery | ||
| - redshift | ||
| - databricks_catalog | ||
| - athena | ||
| steps: | ||
| - name: Checkout dbt package | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: elementary-data/dbt-data-reliability | ||
| path: dbt-data-reliability | ||
|
|
||
| - name: Setup Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.10" | ||
| cache: "pip" | ||
|
|
||
| - name: Install dbt | ||
| run: > | ||
| pip install | ||
| "dbt-core" | ||
| "dbt-${{ (matrix.warehouse-type == 'databricks_catalog' && 'databricks') || (matrix.warehouse-type == 'athena' && 'athena-community') || matrix.warehouse-type }}" | ||
haritamar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Write dbt profiles | ||
| env: | ||
| CI_WAREHOUSE_SECRETS: ${{ secrets.CI_WAREHOUSE_SECRETS || '' }} | ||
| run: | | ||
| if [ -z "$CI_WAREHOUSE_SECRETS" ]; then | ||
| echo "::error::Missing required secret: CI_WAREHOUSE_SECRETS" | ||
| exit 1 | ||
| fi | ||
| # The cleanup job doesn't create schemas, but generate_profiles.py | ||
| # requires --schema-name. Use a dummy value. | ||
| python "${{ github.workspace }}/dbt-data-reliability/integration_tests/profiles/generate_profiles.py" \ | ||
| --template "${{ github.workspace }}/dbt-data-reliability/integration_tests/profiles/profiles.yml.j2" \ | ||
| --output ~/.dbt/profiles.yml \ | ||
| --schema-name "cleanup_placeholder" | ||
|
|
||
| - name: Install dbt deps | ||
| working-directory: ${{ env.TESTS_DIR }}/dbt_project | ||
| run: dbt deps | ||
|
|
||
| - name: Symlink local elementary package | ||
| run: ln -sfn ${{ github.workspace }}/dbt-data-reliability ${{ env.TESTS_DIR }}/dbt_project/dbt_packages/elementary | ||
|
|
||
| - name: Drop stale CI schemas | ||
| working-directory: ${{ env.TESTS_DIR }}/dbt_project | ||
| env: | ||
| MAX_AGE_HOURS: ${{ inputs.max-age-hours || '24' }} | ||
| run: | | ||
| if ! [[ "$MAX_AGE_HOURS" =~ ^[0-9]+$ ]]; then | ||
| echo "::error::max-age-hours must be a non-negative integer" | ||
| exit 1 | ||
| fi | ||
| ARGS=$(printf '{"prefixes":["py_"],"max_age_hours":%s}' "$MAX_AGE_HOURS") | ||
| dbt run-operation drop_stale_ci_schemas \ | ||
| --args "$ARGS" \ | ||
| -t "${{ matrix.warehouse-type }}" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.