Skip to content
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

Add workflow steps to upload dummy db artifact for tests #2616

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
*.cache-to=type=local,dest=/tmp/.buildx-cache-new
files: docker-compose.yaml,docker-compose.local.yaml
env:
DOCKER_BUILD_NO_SUMMARY: true
DOCKER_BUILD_SUMMARY: false
sainak marked this conversation as resolved.
Show resolved Hide resolved

- name: Start services
run: |
Expand All @@ -57,6 +57,10 @@ jobs:
- name: Validate integrity of fixtures
run: make load-dummy-data

- name: Dump db
if: ${{ inputs.event_name == 'push' || github.event_name == 'push' }}
run: make dump-db

- name: Run tests
run: make test-coverage

Expand All @@ -76,3 +80,13 @@ jobs:
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('Pipfile.lock', 'docker/dev.Dockerfile') }}

- name: Upload db artifact
if: ${{ inputs.event_name == 'push' || github.event_name == 'push' }}
uses: actions/upload-artifact@v4
with:
name: care-db-dump
path: care_db.dump
retention-days: 30
compression-level: 0 # file is already compressed
overwrite: true # keep only the last artifact
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,5 @@ secrets.sh
*.rdb

jwks.b64.txt

care_db.dump
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build, re-build, up, down, list, logs, test, makemigrations, reset_db
.PHONY: logs


DOCKER_VERSION := $(shell docker --version 2>/dev/null)
Expand Down Expand Up @@ -40,6 +40,9 @@ checkmigration:
makemigrations:
docker compose exec backend bash -c "python manage.py makemigrations"

migrate:
docker compose exec backend bash -c "python manage.py migrate"

test:
docker compose exec backend bash -c "python manage.py test --keepdb --parallel --shuffle"

Expand All @@ -48,9 +51,16 @@ test-coverage:
docker compose exec backend bash -c "coverage combine || true; coverage xml"
docker compose cp backend:/app/coverage.xml coverage.xml

reset_db:
dump-db:
docker compose exec db sh -c "pg_dump -U postgres -Fc care > /tmp/care_db.dump"
docker compose cp db:/tmp/care_db.dump care_db.dump

load-db:
docker compose cp care_db.dump db:/tmp/care_db.dump
docker compose exec db sh -c "pg_restore -U postgres --clean --if-exists -d care /tmp/care_db.dump"

reset-db:
docker compose exec backend bash -c "python manage.py reset_db --noinput"
docker compose exec backend bash -c "python manage.py migrate"

ruff-all:
ruff check .
Expand Down
Loading