11name : Test Database
2-
32on :
43 push :
54 branches :
65 - develop
76 pull_request :
87 workflow_dispatch :
9-
108jobs :
119 prepare :
1210 runs-on : ubuntu-latest
@@ -15,150 +13,72 @@ jobs:
1513 steps :
1614 - name : Checkout Repo
1715 uses : actions/checkout@v4
18-
19- - uses : DeterminateSystems/nix-installer-action@main
2016
17+ - name : Clear Nix cache
18+ run : |
19+ sudo rm -rf /home/runner/.cache/nix
20+
21+ - uses : DeterminateSystems/nix-installer-action@main
22+ with :
23+ extra-conf : |
24+ substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
25+ trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
2126 - name : Set PostgreSQL versions
2227 id : set-versions
2328 run : |
24- VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
29+ VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[] | select(. != "orioledb-17") ' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
2530 echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
26-
2731 build :
2832 needs : prepare
2933 strategy :
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
44-
47+ - uses : actions/checkout@v4
48+ - name : Clear Nix cache
49+ run : |
50+ sudo rm -rf /home/runner/.cache/nix
4551 - uses : DeterminateSystems/nix-installer-action@main
46-
52+ with :
53+ extra-conf : |
54+ substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
55+ trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
4756 - name : Set PostgreSQL version environment variable
4857 run : echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
49-
5058 - name : Strip quotes from pg major and set env var
5159 run : |
5260 stripped_version=$(echo ${{ matrix.postgres_version }} | sed 's/^"\(.*\)"$/\1/')
5361 echo "PGMAJOR=$stripped_version" >> $GITHUB_ENV
54-
5562 - name : Generate common-nix.vars.pkr.hcl
5663 run : |
57- PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
64+ PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
5865 PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
5966 echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
60- # Ensure there's a newline at the end of the file
6167 echo "" >> common-nix.vars.pkr.hcl
62-
6368 - id : settings
64- # Remove spaces and quotes to get the raw version string
6569 run : sed -r 's/(\s|\")+//g' common-nix.vars.pkr.hcl >> $GITHUB_OUTPUT
66-
6770 - name : Generate args
6871 id : args
6972 run : |
70- ARGS=$(sudo nix run nixpkgs#yq -- 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' ansible/vars.yml)
73+ ARGS=$(nix run nixpkgs#yq -- 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' ansible/vars.yml)
7174 echo "result<<EOF" >> $GITHUB_OUTPUT
7275 echo "$ARGS" >> $GITHUB_OUTPUT
7376 echo "EOF" >> $GITHUB_OUTPUT
74-
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-
15777 - name : verify schema.sql is committed
15878 run : |
159- docker compose -f migrations/docker-compose.yaml up db dbmate --abort-on-container-exit
79+ nix run github:supabase/postgres/${{ github.sha }}# dbmate-tool -- --version ${{ env.PGMAJOR }}
16080 if ! git diff --exit-code --quiet migrations/schema-${{ env.PGMAJOR }}.sql; then
16181 echo "Detected changes in schema.sql:"
16282 git diff migrations/schema-${{ env.PGMAJOR }}.sql
16383 exit 1
164- fi
84+ fi
0 commit comments