1717 uses : actions/checkout@v4
1818
1919 - uses : DeterminateSystems/nix-installer-action@main
20+ with :
21+ extra-conf : |
22+ substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
23+ trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
2024
2125 - name : Set PostgreSQL versions
2226 id : set-versions
@@ -30,19 +34,24 @@ jobs:
3034 matrix :
3135 postgres_version : ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
3236 include :
33- - runner : [self-hosted, X64]
37+ - runner : ubuntu-22.04
3438 arch : amd64
35- - runner : arm-runner
39+ - runner : ubuntu-22.04
3640 arch : arm64
3741 runs-on : ${{ matrix.runner }}
3842 timeout-minutes : 180
3943 env :
4044 POSTGRES_PORT : 5478
4145 POSTGRES_PASSWORD : password
4246 steps :
43- - uses : actions/checkout@v3
47+ - uses : actions/checkout@v4
4448
4549 - uses : DeterminateSystems/nix-installer-action@main
50+ with :
51+ extra-conf : |
52+ substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
53+ trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
54+
4655
4756 - name : Set PostgreSQL version environment variable
4857 run : echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
5463
5564 - name : Generate common-nix.vars.pkr.hcl
5665 run : |
57- PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
66+ PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
5867 PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
5968 echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
6069 # Ensure there's a newline at the end of the file
@@ -67,96 +76,16 @@ jobs:
6776 - name : Generate args
6877 id : args
6978 run : |
70- ARGS=$(sudo nix run nixpkgs#yq -- 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' ansible/vars.yml)
79+ ARGS=$(nix run nixpkgs#yq -- 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' ansible/vars.yml)
7180 echo "result<<EOF" >> $GITHUB_OUTPUT
7281 echo "$ARGS" >> $GITHUB_OUTPUT
7382 echo "EOF" >> $GITHUB_OUTPUT
7483
75- - run : docker context create builders
76- - uses : docker/setup-buildx-action@v3
77- with :
78- endpoint : builders
79- - uses : docker/build-push-action@v5
80- with :
81- load : true
82- context : .
83- file : Dockerfile-${{ env.PGMAJOR }}
84- target : production
85- build-args : |
86- ${{ steps.args.outputs.result }}
87- tags : supabase/postgres:${{ steps.settings.outputs.postgres-version }},supabase_postgres
88- cache-from : |
89- type=gha,scope=${{ github.ref_name }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
90- type=gha,scope=${{ github.base_ref }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
91- cache-to : type=gha,mode=max,scope=${{ github.ref_name }}-${{ steps.settings.outputs.postgres-version }}-${{ matrix.arch }}
92-
93- - name : Start Postgres
94- run : |
95- docker run --rm --pull=never \
96- -e POSTGRES_PASSWORD=${{ env.POSTGRES_PASSWORD }} \
97- -p ${{ env.POSTGRES_PORT }}:5432 \
98- --name supabase_postgres \
99- -d supabase/postgres:${{ steps.settings.outputs.postgres-version }}
100-
101- - name : Install psql
102- run : |
103- sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
104- wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
105- sudo apt update
106- sudo apt install -y --no-install-recommends postgresql-client-${{ env.PGMAJOR }}
107-
108- - name : Install pg_prove
109- run : sudo cpan -T TAP::Parser::SourceHandler::pgTAP
110- env :
111- SHELL : /bin/bash
112-
113- - name : Wait for healthy database
114- run : |
115- count=0
116- until [ "$(docker inspect -f '{{.State.Health.Status}}' "$container")" == "healthy" ]; do
117- exit=$?
118- count=$((count + 1))
119- if [ $count -ge "$retries" ]; then
120- echo "Retry $count/$retries exited $exit, no more retries left."
121- docker stop -t 2 "$container"
122- return $exit
123- fi
124- sleep 1;
125- done;
126- echo "$container container is healthy"
127- env :
128- retries : 20
129- container : supabase_postgres
130-
131- - name : Run tests
132- run : pg_prove migrations/tests/test.sql
133- env :
134- PGHOST : localhost
135- PGPORT : ${{ env.POSTGRES_PORT }}
136- PGDATABASE : postgres
137- PGUSER : supabase_admin
138- PGPASSWORD : ${{ env.POSTGRES_PASSWORD }}
139-
140- - name : Check migrations are idempotent
141- run : |
142- for sql in ./migrations/db/migrations/*.sql; do
143- echo "$0: running $sql"
144- psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -f "$sql"
145- done
146- env :
147- PGHOST : localhost
148- PGPORT : ${{ env.POSTGRES_PORT }}
149- PGDATABASE : postgres
150- PGUSER : supabase_admin
151- PGPASSWORD : ${{ env.POSTGRES_PASSWORD }}
152-
153- - name : Update Dockerfile.dbmate version
154- run : |
155- sed -i 's/%VERSION%/${{ env.PGMAJOR }}/g' migrations/Dockerfile.dbmate
156-
84+ # TODO PR Convert to develop branch flakeurl
15785 - name : verify schema.sql is committed
15886 run : |
159- docker compose -f migrations/docker-compose.yaml up db dbmate --abort-on-container-exit
87+ GIT_SHA=${{github.sha}}
88+ nix run github:supabase/postgres/${GIT_SHA}#dbmate-tool -- --version ${{ env.PGMAJOR }}
16089 if ! git diff --exit-code --quiet migrations/schema-${{ env.PGMAJOR }}.sql; then
16190 echo "Detected changes in schema.sql:"
16291 git diff migrations/schema-${{ env.PGMAJOR }}.sql
0 commit comments