dbmate migration running and testing tool #3349
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test Database | |
on: | |
push: | |
branches: | |
- develop | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
postgres_versions: ${{ steps.set-versions.outputs.postgres_versions }} | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v4 | |
- uses: DeterminateSystems/nix-installer-action@main | |
with: | |
extra-conf: | | |
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com | |
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= | |
- name: Set PostgreSQL versions | |
id: set-versions | |
run: | | |
VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]') | |
echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT | |
build: | |
needs: prepare | |
strategy: | |
matrix: | |
postgres_version: ${{ fromJson(needs.prepare.outputs.postgres_versions) }} | |
include: | |
- runner: ubuntu-22.04 | |
arch: amd64 | |
- runner: ubuntu-22.04 | |
arch: arm64 | |
runs-on: ${{ matrix.runner }} | |
timeout-minutes: 180 | |
env: | |
POSTGRES_PORT: 5478 | |
POSTGRES_PASSWORD: password | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: DeterminateSystems/nix-installer-action@main | |
with: | |
extra-conf: | | |
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com | |
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= | |
- name: Set PostgreSQL version environment variable | |
run: echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV | |
- name: Strip quotes from pg major and set env var | |
run: | | |
stripped_version=$(echo ${{ matrix.postgres_version }} | sed 's/^"\(.*\)"$/\1/') | |
echo "PGMAJOR=$stripped_version" >> $GITHUB_ENV | |
- name: Generate common-nix.vars.pkr.hcl | |
run: | | |
PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml) | |
PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes | |
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl | |
# Ensure there's a newline at the end of the file | |
echo "" >> common-nix.vars.pkr.hcl | |
- id: settings | |
# Remove spaces and quotes to get the raw version string | |
run: sed -r 's/(\s|\")+//g' common-nix.vars.pkr.hcl >> $GITHUB_OUTPUT | |
- name: Generate args | |
id: args | |
run: | | |
ARGS=$(nix run nixpkgs#yq -- 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' ansible/vars.yml) | |
echo "result<<EOF" >> $GITHUB_OUTPUT | |
echo "$ARGS" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
#TODO PR Convert to develop branch flakeurl | |
- name: verify schema.sql is committed | |
run: | | |
GIT_SHA=${{github.sha}} | |
nix run github:supabase/postgres/${GIT_SHA}#dbmate-tool -- --version ${{ env.PGMAJOR }} | |
if ! git diff --exit-code --quiet migrations/schema-${{ env.PGMAJOR }}.sql; then | |
echo "Detected changes in schema.sql:" | |
git diff migrations/schema-${{ env.PGMAJOR }}.sql | |
exit 1 | |
fi |