|
9 | 9 |
|
10 | 10 | jobs:
|
11 | 11 | build:
|
12 |
| - if: ${{ github.event_name != 'pull_request' }} |
13 | 12 | runs-on: ubuntu-latest
|
| 13 | + timeout-minutes: 180 |
| 14 | + env: |
| 15 | + POSTGRES_PORT: 5478 |
| 16 | + POSTGRES_PASSWORD: password |
14 | 17 | steps:
|
15 | 18 | - uses: actions/checkout@v3
|
| 19 | + - uses: docker/setup-buildx-action@v2 |
| 20 | + - uses: docker/build-push-action@v3 |
| 21 | + with: |
| 22 | + push: false |
| 23 | + load: true |
| 24 | + context: ansible |
| 25 | + tags: supabase/postgres:latest |
| 26 | + cache-from: type=gha |
| 27 | + cache-to: type=gha,mode=max |
16 | 28 |
|
17 |
| - - run: docker compose up --abort-on-container-exit --build |
18 |
| - |
19 |
| - migrate: |
20 |
| - runs-on: ubuntu-latest |
21 |
| - env: |
22 |
| - POSTGRES_PASSWORD: password |
| 29 | + - name: Start Postgres |
| 30 | + run: | |
| 31 | + docker run --rm --pull=never \ |
| 32 | + -e POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }} \ |
| 33 | + -p ${{ env.POSTGRES_PORT }}:5432 \ |
| 34 | + --name supabase_postgres \ |
| 35 | + -d supabase/postgres:latest |
23 | 36 |
|
24 |
| - strategy: |
25 |
| - matrix: |
26 |
| - supabase-version: ["15.1.0.11"] |
27 |
| - timeout-minutes: 10 |
| 37 | + - name: Install dbmate |
| 38 | + run: | |
| 39 | + curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64 |
| 40 | + sudo chmod +x /usr/local/bin/dbmate |
28 | 41 |
|
29 |
| - services: |
30 |
| - postgres: |
31 |
| - image: supabase/postgres:${{ matrix.supabase-version }} |
32 |
| - ports: |
33 |
| - - 5478:5432 |
34 |
| - # Set health checks to wait until postgres has started |
35 |
| - options: >- |
36 |
| - --health-cmd "pg_isready -U postgres -h localhost" |
37 |
| - --health-interval 5s |
38 |
| - --health-timeout 5s |
39 |
| - --health-retries 10 |
| 42 | + - name: Install pg_prove |
| 43 | + run: sudo cpan -T TAP::Parser::SourceHandler::pgTAP |
40 | 44 | env:
|
41 |
| - POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} |
42 |
| - volumes: |
43 |
| - # Disable migration by removing from entrypoint |
44 |
| - - /dev/null:/docker-entrypoint-initdb.d/migrate.sh |
45 |
| - |
46 |
| - steps: |
47 |
| - - name: checkout |
48 |
| - uses: actions/checkout@v3 |
| 45 | + SHELL: /bin/bash |
49 | 46 |
|
50 |
| - - name: install dbmate |
| 47 | + - name: Wait for healthy database |
51 | 48 | run: |
|
52 |
| - curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64 |
53 |
| - sudo chmod +x /usr/local/bin/dbmate |
| 49 | + count=0 |
| 50 | + until [ "$(docker inspect -f '{{.State.Health.Status}}' "$container")" == "healthy" ]; do |
| 51 | + exit=$? |
| 52 | + count=$((count + 1)) |
| 53 | + if [ $count -ge "$retries" ]; then |
| 54 | + echo "Retry $count/$retries exited $exit, no more retries left." |
| 55 | + docker stop -t 2 "$container" |
| 56 | + return $exit |
| 57 | + fi |
| 58 | + sleep 1; |
| 59 | + done; |
| 60 | + echo "$container container is healthy" |
| 61 | + env: |
| 62 | + retries: 20 |
| 63 | + container: supabase_postgres |
54 | 64 |
|
55 |
| - - name: migrate schema |
| 65 | + - name: Migrate schema |
56 | 66 | run: ./migrations/db/migrate.sh
|
57 | 67 | env:
|
58 | 68 | USE_DBMATE: 1
|
59 |
| - POSTGRES_PORT: 5478 |
| 69 | + POSTGRES_PORT: ${{ env.POSTGRES_PORT }} |
60 | 70 | POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
|
61 | 71 |
|
62 |
| - - name: install pg_prove |
63 |
| - run: sudo cpan TAP::Parser::SourceHandler::pgTAP |
64 |
| - env: |
65 |
| - SHELL: /bin/bash |
66 |
| - |
67 |
| - - name: run tests |
| 72 | + - name: Run tests |
68 | 73 | run: pg_prove migrations/tests/test.sql
|
69 | 74 | env:
|
70 | 75 | PGHOST: localhost
|
71 |
| - PGPORT: 5478 |
| 76 | + PGPORT: ${{ env.POSTGRES_PORT }} |
72 | 77 | PGUSER: postgres
|
73 | 78 | PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
|
74 | 79 |
|
75 |
| - - name: migrations should be idempotent |
| 80 | + - name: Check migrations are idempotent |
76 | 81 | run: |
|
77 | 82 | for sql in ./migrations/db/migrations/*.sql; do
|
78 | 83 | echo "$0: running $sql"
|
79 | 84 | psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -f "$sql"
|
80 | 85 | done
|
81 | 86 | env:
|
82 | 87 | PGHOST: localhost
|
83 |
| - PGPORT: 5478 |
| 88 | + PGPORT: ${{ env.POSTGRES_PORT }} |
84 | 89 | PGDATABASE: postgres
|
85 | 90 | PGUSER: supabase_admin
|
86 | 91 | PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
|
87 | 92 |
|
88 |
| - - name: run tests |
| 93 | + - name: Run tests again |
89 | 94 | run: pg_prove migrations/tests/test.sql
|
90 | 95 | env:
|
91 | 96 | PGHOST: localhost
|
92 |
| - PGPORT: 5478 |
| 97 | + PGPORT: ${{ env.POSTGRES_PORT }} |
93 | 98 | PGUSER: postgres
|
94 | 99 | PGPASSWORD: ${{ env.POSTGRES_PASSWORD }}
|
95 | 100 |
|
|
0 commit comments