👷 use migration files as cache key for database cache #14
Workflow file for this run
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
| name: Create database cache | |
| on: | |
| push: | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| cache_hit: ${{ steps.db_cache.outputs.cache-hit }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Restore database cache | |
| uses: actions/cache/restore@v5 | |
| id: db_cache | |
| with: | |
| path: cache-dump.sql | |
| key: db-${{ runner.os }}-${{ hashFiles('fragdenstaat_de/**/migrations/*.py') }} | |
| dump: | |
| runs-on: ubuntu-latest | |
| needs: check | |
| if: needs.check.outputs.cache_hit != 'true' # don't use == 'false'! | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Start database | |
| run: docker compose -f compose-dev.yaml up --wait db | |
| - name: Setup uv | |
| uses: astral-sh/setup-uv@v8.1.0 | |
| with: | |
| python-version: '3.13' | |
| activate-environment: true | |
| - name: Install system-level dependencies | |
| run: sudo apt-get update && sudo apt-get install libgdal-dev gdal-bin | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Run migrations | |
| run: python manage.py migrate --skip-checks # due to django-cms issue | |
| - name: Create database dump | |
| run: docker compose -f compose-dev.yaml exec db pg_dump -U fragdenstaat_de fragdenstaat_de > cache-dump.sql | |
| - name: Save dump | |
| uses: actions/cache/save@v5 | |
| with: | |
| path: cache-dump.sql | |
| key: db-${{ runner.os }}-${{ hashFiles('fragdenstaat_de/**/migrations/*.py') }} |