This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
Update README.md #12
Workflow file for this run
This file contains 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: Test database backup | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
PYTEST_ADDOPTS: '--color=yes' | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
# https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers | |
# See also https://remarkablemark.org/blog/2021/03/14/setup-postgresql-in-github-actions/ | |
# and https://github.com/actions/example-services/blob/master/.github/workflows/postgres-service.yml | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_DB: postgres_db | |
POSTGRES_PASSWORD: postgres_password | |
POSTGRES_PORT: 5432 | |
POSTGRES_USER: postgres_user | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install python deps | |
run: | | |
python -m pip install pytest sqlmodel psycopg2-binary | |
python -m pip install . --no-deps | |
- name: Install PostgreSQL client | |
run: | | |
sudo apt-get update | |
sudo apt-get install --yes postgresql-client | |
# https://devcenter.heroku.com/articles/heroku-postgres-import-export#restore-to-local-database | |
- name: Restore database from file | |
# exit code is 1, but it does actually work, so just continue | |
continue-on-error: true | |
run: | | |
pg_restore --verbose --clean --no-acl --no-owner \ | |
-h localhost -U postgres_user -d postgres_db \ | |
db-backup/810fa5e1-9b78-4f3c-97e0-a1847b3a65e6 | |
env: | |
PGPASSWORD: postgres_password | |
- name: Test restored database | |
run: | | |
pytest -vvxs db-backup/test_db_backup.py | |
env: | |
DATABASE_URL: postgresql://postgres_user:postgres_password@localhost:5432/postgres_db |