name: CI on: push: branches: - main pull_request: branches: - main jobs: test: runs-on: ubuntu-latest name: Test postgres-restore services: postgres: image: postgres:latest env: POSTGRES_USER: test_user POSTGRES_PASSWORD: test_user_password POSTGRES_DB: testdb ports: - 5432:5432 # needed because the postgres container does not provide a healthcheck options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # otherwise, you will failed to push refs to dest repo persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token - name: Run pg_dump uses: ./ with: database_url: "postgres://test_user:test_user_password@localhost:5432/testdb" path: "backups/backup.sql" - name: Check changes to backup file. id: changed_backup uses: tj-actions/verify-changed-files@v16 with: files: backups/backup.sql - name: Raise error if: steps.changed_backup.outputs.files_changed == 'true' run: | exit 1; - name: Commit changes to backup file. if: failure() run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add backups/backup.sql git commit -m "Auto updated backup.sql." - name: Push changes if: failure() uses: ad-m/github-push-action@master with: github_token: ${{ secrets.PAT_TOKEN }} branch: ${{ github.head_ref }}