diff --git a/.github/actions/setup-postgres/action.yml b/.github/actions/setup-postgres/action.yml new file mode 100644 index 00000000..a07fdfbc --- /dev/null +++ b/.github/actions/setup-postgres/action.yml @@ -0,0 +1,87 @@ +name: Setup Postgres +description: Setup Postgres across operating systems +inputs: + postgres-version: + description: Postgres Version + default: 15 + +runs: + using: composite + steps: + # For Windows and macOS, use the action since + # PostgreSQL Docker image doesn't support Windows containers and + # macOS runners do not support Docker + - name: Setup postgres (Windows) + if: runner.os == 'Windows' || runner.os == 'macOS' + id: postgres + uses: ikalnytskyi/action-setup-postgres@v7 + with: + postgres-version: ${{ inputs.postgres-version }} + username: postgres + password: postgres + database: postgres + port: 5432 + + # Install the pglpgsql_check extension on macOS (Part 1) + - name: Install and compile plpgsql_check + if: runner.os == 'macOS' + shell: bash + run: | + # First, ensure we're using the same PostgreSQL that the action installed + export PATH="$(pg_config --bindir):$PATH" + + # Verify we're targeting the right PostgreSQL installation + echo "PostgreSQL version: $(pg_config --version)" + echo "Extension directory: $(pg_config --sharedir)/extension" + echo "Library directory: $(pg_config --pkglibdir)" + + # Clone and build plpgsql_check + git clone https://github.com/okbob/plpgsql_check.git + cd plpgsql_check + + # Clean and compile + make USE_PGXS=1 clean + make USE_PGXS=1 all + + # Install (may need sudo depending on permissions) + sudo make USE_PGXS=1 install + + # Verify installation + echo "Extension control files:" + ls -la "$(pg_config --sharedir)/extension/" | grep plpgsql || echo "No plpgsql_check found" + + echo "Extension library files:" + ls -la "$(pg_config --pkglibdir)/" | grep plpgsql || echo "No plpgsql_check library found" + + # Install the pglpgsql_check extension on macOS (Part 2) + - name: Create extension in database + if: runner.os == 'macOS' + shell: bash + env: + PGSERVICE: ${{ steps.postgres.outputs.service-name }} + run: | + psql -c "CREATE EXTENSION plpgsql_check;" + + # Verify installation + psql -c "SELECT extname, extversion FROM pg_extension WHERE extname = 'plpgsql_check';" + + # For Linux, use custom Docker image with plpgsql_check + - name: Build and start PostgreSQL with plpgsql_check + if: runner.os == 'Linux' + shell: bash + run: | + docker build -t postgres-plpgsql-check:latest . + docker run -d --name postgres \ + -e POSTGRES_USER=postgres \ + -e POSTGRES_PASSWORD=postgres \ + -e POSTGRES_DB=postgres \ + -p 5432:5432 \ + postgres-plpgsql-check:latest + # Wait for postgres to be ready + for _ in {1..30}; do + if docker exec postgres pg_isready -U postgres; then + break + fi + sleep 1 + done + diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 20218378..72474527 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -149,6 +149,7 @@ jobs: # use the same images we use for compiling - os: windows-2022 - os: ubuntu-22.04 + - os: macos-14 steps: - name: Checkout PR branch uses: actions/checkout@v4 @@ -163,37 +164,9 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # For Linux, use custom Docker image with plpgsql_check - - name: Build and start PostgreSQL with plpgsql_check - if: runner.os == 'Linux' - run: | - docker build -t postgres-plpgsql-check:latest . - docker run -d --name postgres \ - -e POSTGRES_USER=postgres \ - -e POSTGRES_PASSWORD=postgres \ - -e POSTGRES_DB=postgres \ - -p 5432:5432 \ - postgres-plpgsql-check:latest - # Wait for postgres to be ready - for _ in {1..30}; do - if docker exec postgres pg_isready -U postgres; then - break - fi - sleep 1 - done - # For Windows, use the action since PostgreSQL Docker image doesn't support Windows containers - - name: Setup postgres (Windows) - if: runner.os == 'Windows' - id: postgres - uses: ikalnytskyi/action-setup-postgres@v7 - - name: Print Roles - run: | - if [[ "$RUNNER_OS" == "Linux" ]]; then - docker exec postgres psql -U postgres -c "select rolname from pg_roles;" - else - psql ${{ steps.postgres.outputs.connection-uri }} -c "select rolname from pg_roles;" - fi - shell: bash + - name: Setup Postgres + uses: ./.github/actions/setup-postgres + - name: Run tests run: cargo test --workspace diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4b427889..c2f8eeff 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -67,39 +67,8 @@ jobs: sudo apt-get update sudo apt-get install -y gcc-aarch64-linux-gnu - # The Docker runtime is not available by default on macOS runners - # https://github.com/actions/runner-images/issues/2150 - # https://blog.netnerds.net/2022/11/docker-macos-github-actions/ - - name: Install Docker - if: runner.os == 'macOS' - run: | - brew install docker - colima start - - # For Linux, use custom Docker image with plpgsql_check - - name: Build and start PostgreSQL with plpgsql_check - if: runner.os == 'macOS' || runner.os == 'Linux' - run: | - docker build -t postgres-plpgsql-check:latest . - docker run -d --name postgres \ - -e POSTGRES_USER=postgres \ - -e POSTGRES_PASSWORD=postgres \ - -e POSTGRES_DB=postgres \ - -p 5432:5432 \ - postgres-plpgsql-check:latest - # Wait for postgres to be ready - for _ in {1..30}; do - if docker exec postgres pg_isready -U postgres; then - break - fi - sleep 1 - done - - # For Windows, use the action since PostgreSQL Docker image doesn't support Windows containers - - name: Setup postgres (Windows) - if: runner.os == 'Windows' - id: postgres - uses: ikalnytskyi/action-setup-postgres@v7 + - name: Setup Postgres + uses: ./.github/actions/setup-postgres - name: 🧪 Run Tests run: cargo test --release