-
-
Notifications
You must be signed in to change notification settings - Fork 146
133 lines (115 loc) · 4.22 KB
/
test-pg-upgrade.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Test pg_upgrade
on:
push:
branches:
- develop
- pcnc/pg_upgrade-test-extensions
workflow_dispatch:
permissions:
id-token: write
jobs:
test:
strategy:
matrix:
base_pg_version:
- 15.1.1.60
- 15.1.1.70
runs-on: arm-runner
timeout-minutes: 30
defaults:
run:
working-directory: ./tests/pg_upgrade
env:
PGPORT: 5478
PGPASSWORD: postgres
PGDATABASE: postgres
PGUSER: supabase_admin
PGHOST: localhost
PG_MAJOR_VERSION: 15
IS_CI: true
container: pg_upgrade_test
steps:
- uses: actions/checkout@v3
- name: Grab release version
id: process_release_version
working-directory: ./
run: |
VERSION=$(sed -e 's/postgres-version = "\(.*\)"/\1/g' common.vars.pkr.hcl)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: configure aws credentials - staging
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
aws-region: "us-east-1"
- name: Download pg_upgrade_scripts and binaries
run: |
aws s3 cp s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/pg_upgrade_scripts.tar.gz scripts/pg_upgrade_scripts.tar.gz
aws s3 cp s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz scripts/pg_upgrade_bin.tar.gz
- run: docker context create builders
- uses: docker/setup-buildx-action@v2
with:
endpoint: builders
driver-opts: image=moby/buildkit:v0.11.6
buildkitd-flags: --debug
- name: Start Postgres
run: |
docker rm -f "$container" || true
docker run --name "$container" --env-file .env \
-v "$(pwd)/scripts:/tmp/upgrade" \
--entrypoint "/tmp/upgrade/entrypoint.sh" -d \
-p ${PGPORT}:5432 \
"supabase/postgres:${{ matrix.base_pg_version }}"
- name: Install psql
run: |
sudo apt update
sudo apt install -y --no-install-recommends postgresql-client
- name: Install pg_prove
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends perl cpanminus
sudo cpanm -n App::cpanminus
sudo cpanm -n TAP::Parser::SourceHandler::pgTAP
env:
SHELL: /bin/bash
PERL_MM_USE_DEFAULT: 1
PERL_MM_NONINTERACTIVE: 1
- name: Wait for healthy database
run: |
count=0
while ! docker exec "$container" bash -c "pg_isready"; do
count=$((count + 1))
if [ $count -ge "$retries" ]; then
echo "Retry $count/$retries exited $exit, no more retries left."
docker logs "$container"
docker rm -f "$container"
exit 1
fi
done
env:
retries: 20
- name: Run migrations
run: |
docker cp ../../migrations/db/migrations "$container:/docker-entrypoint-initdb.d/"
docker exec "$container" bash -c "/docker-entrypoint-initdb.d/migrate.sh > /tmp/migrate.log 2>&1"
- name: Run initial tests
run: pg_prove "../../migrations/tests/test.sql"
env:
PERL5LIB: /usr/local/lib/perl5
- name: Apply pre-upgrade fixtures
run: |
psql -f "./tests/97-enable-extensions.sql"
psql -f "./tests/98-data-fixtures.sql"
psql -f "./tests/99-fixtures.sql"
- name: Initiate upgrade
run: docker exec "$container" bash -c '/tmp/upgrade/pg_upgrade_scripts/initiate.sh "$PG_MAJOR_VERSION"; exit $?'
- name: Complete pg_upgrade
run: docker exec pg_upgrade_test bash -c '/tmp/upgrade/pg_upgrade_scripts/complete.sh; exit $?'
- name: Run post-upgrade tests
run: |
pg_prove tests/01-schema.sql
pg_prove tests/02-data.sql
pg_prove tests/03-settings.sql
- name: Clean up container
if: ${{ always() }}
continue-on-error: true
run: docker rm -f "$container" || true