Skip to content

Commit 2fbf0f3

Browse files
committed
👷 use migration files as cache key for database cache
1 parent 6c04bb9 commit 2fbf0f3

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎.github/workflows/database-cache.yml‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@ on:
44
workflow_dispatch:
55
schedule:
66
- cron: 0 14 * * 0
7+
push:
78

89
jobs:
10+
# check if cache key already exists, only create dump if not
11+
check:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
cache_count: ${{ steps.cache_count.outputs.cache_count }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Check if database cache should be created
18+
id: cache_count
19+
run: echo "cache_count=$(gh cache list -k "$CACHE_KEY" --json id --jq ".| length")" >> $GITHUB_OUTPUT
20+
env:
21+
CACHE_KEY: db-${{ runner.os }}-${{ hashFiles('**/migrations/*.py') }}
22+
923
dump:
1024
runs-on: ubuntu-latest
25+
needs: check
26+
if: needs.check.outputs.cache_count == '0'
1127
steps:
1228
- uses: actions/checkout@v4
1329
- name: Start database
@@ -24,9 +40,9 @@ jobs:
2440
- name: Run migrations
2541
run: python manage.py migrate --skip-checks # due to django-cms issue
2642
- name: Create database dump
27-
run: docker compose -f compose-dev.yaml exec db pg_dump -U fragdenstaat_de fragdenstaat_de | gzip > dump.gz
43+
run: docker compose -f compose-dev.yaml exec db pg_dump -U fragdenstaat_de fragdenstaat_de | gzip > cache-dump.sql
2844
- name: Save dump
2945
uses: actions/cache/save@v5
3046
with:
31-
path: dump.gz
32-
key: ${{ runner.os }}-${{ hashFiles('compose-dev.yaml') }}
47+
path: cache-dump.sql
48+
key: db-${{ runner.os }}-${{ hashFiles('**/migrations/*.py') }}

0 commit comments

Comments
 (0)