feat: add robust restort workflow. #2
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: Restore Test | |
| on: | |
| push: | |
| paths: | |
| - 'scripts/restore.sh' | |
| - '.github/workflows/restore-test.yml' | |
| workflow_dispatch: | |
| jobs: | |
| restore-test: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:16 | |
| env: | |
| POSTGRES_DB: testdb | |
| POSTGRES_USER: testuser | |
| POSTGRES_PASSWORD: testpass | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd="pg_isready -U testuser" | |
| --health-interval=5s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| env: | |
| POSTGRES_DB: testdb | |
| POSTGRES_USER: testuser | |
| POSTGRES_PASSWORD: testpass | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Install required tools | |
| run: sudo apt-get update && sudo apt-get install -y postgresql-client gzip | |
| - name: Prepare .env for restore | |
| run: | | |
| echo "POSTGRES_DB=testdb" > .env | |
| echo "POSTGRES_USER=testuser" >> .env | |
| echo "POSTGRES_PASSWORD=testpass" >> .env | |
| - name: Create test backup | |
| run: | | |
| mkdir -p backups | |
| echo "CREATE TABLE ci_test(id SERIAL PRIMARY KEY);" | gzip > backups/test-backup.sql.gz | |
| - name: Run restore script | |
| run: ./scripts/restore.sh --file backups/test-backup.sql.gz | |
| - name: Verify restore | |
| run: | | |
| psql -h localhost -U $POSTGRES_USER -d $POSTGRES_DB -c '\dt' | grep ci_test |