|
| 1 | +name: Setup Postgres |
| 2 | +description: Setup Postgres across operating systems |
| 3 | +inputs: |
| 4 | + postgres-version: |
| 5 | + description: Postgres Version |
| 6 | + default: 15 |
| 7 | + |
| 8 | +runs: |
| 9 | + using: composite |
| 10 | + steps: |
| 11 | + # For Windows and macOS, use the action since |
| 12 | + # PostgreSQL Docker image doesn't support Windows containers and |
| 13 | + # macOS runners do not support Docker |
| 14 | + - name: Setup postgres (Windows) |
| 15 | + if: runner.os == 'Windows' || runner.os == 'macOS' |
| 16 | + id: postgres |
| 17 | + uses: ikalnytskyi/action-setup-postgres@v7 |
| 18 | + with: |
| 19 | + postgres-version: ${{ inputs.postgres-version }} |
| 20 | + username: postgres |
| 21 | + password: postgres |
| 22 | + database: postgres |
| 23 | + port: 5432 |
| 24 | + |
| 25 | + # Install the pglpgsql_check extension on macOS (Part 1) |
| 26 | + - name: Install and compile plpgsql_check |
| 27 | + if: runner.os == 'macOS' |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + # First, ensure we're using the same PostgreSQL that the action installed |
| 31 | + export PATH="$(pg_config --bindir):$PATH" |
| 32 | +
|
| 33 | + # Verify we're targeting the right PostgreSQL installation |
| 34 | + echo "PostgreSQL version: $(pg_config --version)" |
| 35 | + echo "Extension directory: $(pg_config --sharedir)/extension" |
| 36 | + echo "Library directory: $(pg_config --pkglibdir)" |
| 37 | +
|
| 38 | + # Clone and build plpgsql_check |
| 39 | + git clone https://github.com/okbob/plpgsql_check.git |
| 40 | + cd plpgsql_check |
| 41 | +
|
| 42 | + # Clean and compile |
| 43 | + make USE_PGXS=1 clean |
| 44 | + make USE_PGXS=1 all |
| 45 | +
|
| 46 | + # Install (may need sudo depending on permissions) |
| 47 | + sudo make USE_PGXS=1 install |
| 48 | +
|
| 49 | + # Verify installation |
| 50 | + echo "Extension control files:" |
| 51 | + ls -la "$(pg_config --sharedir)/extension/" | grep plpgsql || echo "No plpgsql_check found" |
| 52 | +
|
| 53 | + echo "Extension library files:" |
| 54 | + ls -la "$(pg_config --pkglibdir)/" | grep plpgsql || echo "No plpgsql_check library found" |
| 55 | +
|
| 56 | + # Install the pglpgsql_check extension on macOS (Part 2) |
| 57 | + - name: Create extension in database |
| 58 | + if: runner.os == 'macOS' |
| 59 | + shell: bash |
| 60 | + env: |
| 61 | + PGSERVICE: ${{ steps.postgres.outputs.service-name }} |
| 62 | + run: | |
| 63 | + psql -c "CREATE EXTENSION plpgsql_check;" |
| 64 | +
|
| 65 | + # Verify installation |
| 66 | + psql -c "SELECT extname, extversion FROM pg_extension WHERE extname = 'plpgsql_check';" |
| 67 | +
|
| 68 | + # For Linux, use custom Docker image with plpgsql_check |
| 69 | + - name: Build and start PostgreSQL with plpgsql_check |
| 70 | + if: runner.os == 'Linux' |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + docker build -t postgres-plpgsql-check:latest . |
| 74 | + docker run -d --name postgres \ |
| 75 | + -e POSTGRES_USER=postgres \ |
| 76 | + -e POSTGRES_PASSWORD=postgres \ |
| 77 | + -e POSTGRES_DB=postgres \ |
| 78 | + -p 5432:5432 \ |
| 79 | + postgres-plpgsql-check:latest |
| 80 | + # Wait for postgres to be ready |
| 81 | + for _ in {1..30}; do |
| 82 | + if docker exec postgres pg_isready -U postgres; then |
| 83 | + break |
| 84 | + fi |
| 85 | + sleep 1 |
| 86 | + done |
| 87 | +
|
0 commit comments