Skip to content

Commit

Permalink
Add workflow steps to upload dummy db artifact for tests (#2616)
Browse files Browse the repository at this point in the history
Add workflow steps to upload dummy db artifact for tests (#2616)
  • Loading branch information
sainak authored Nov 25, 2024
1 parent 7454ab9 commit d3d402d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
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

- 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
19 changes: 16 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 All @@ -19,6 +19,9 @@ re-build:
build:
docker compose -f docker-compose.yaml -f $(docker_config_file) build

pull:
docker compose -f docker-compose.yaml -f $(docker_config_file) pull

up:
docker compose -f docker-compose.yaml -f $(docker_config_file) up -d --wait

Expand All @@ -40,6 +43,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 +54,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

0 comments on commit d3d402d

Please sign in to comment.