From f948d6f2acd84fa57292aa2f093f9454b7eb57c5 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Wed, 22 Jan 2025 11:55:26 +0800 Subject: [PATCH 01/22] allows set postgis version for macos --- action.yml | 18 +++++++++++++++++- postgis-macos-versions.json | 8 ++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 postgis-macos-versions.json diff --git a/action.yml b/action.yml index 84ba93e..90f6de4 100644 --- a/action.yml +++ b/action.yml @@ -73,8 +73,24 @@ runs: - name: Install PostGIS on macOS if: runner.os == 'macOS' shell: bash - run: brew install postgis + run: | + # If no version specified, install latest + if [[ -z "${{ inputs.postgis_version }}" ]]; then + brew install postgis + exit 0 + fi + + # Read version mapping from JSON file + FORMULA_URL=$(jq -r '."${{ inputs.postgis_version }}"' ${GITHUB_ACTION_PATH}/postgis-macos-versions.json) + if [[ "$FORMULA_URL" == "null" ]]; then + echo "Error: PostGIS version ${{ inputs.postgis_version }} is not supported on macOS" + exit 1 + fi + + # Install specific version + brew install "$FORMULA_URL" + - name: Detect PostgreSQL Version (Windows) if: runner.os == 'Windows' id: pg-version diff --git a/postgis-macos-versions.json b/postgis-macos-versions.json new file mode 100644 index 0000000..3de9635 --- /dev/null +++ b/postgis-macos-versions.json @@ -0,0 +1,8 @@ +{ + "3.5.2": "https://raw.githubusercontent.com/Homebrew/homebrew-core/0e8cf73743fc1b148182ada18cbd1ea586e8b638/Formula/p/postgis.rb", + "3.5.1": "https://github.com/Homebrew/homebrew-core/raw/a78958a211e79d151309de3038d20add73306d6c/Formula/p/postgis.rb", + "3.5.0": "https://github.com/Homebrew/homebrew-core/raw/3c9711ac5aaa062e65960e4ee8286471782fbf6e/Formula/p/postgis.rb", + "3.4.3": "https://github.com/Homebrew/homebrew-core/raw/2858d71fabde44101eeb2a7bfbcf3b5ca2c2aa76/Formula/p/postgis.rb", + "3.4.2": "https://github.com/Homebrew/homebrew-core/raw/b1dbe7afb89d1860ed459b57d4e631de7c902462/Formula/p/postgis.rb", + "3.3.4": "https://github.com/Homebrew/homebrew-core/raw/e2bd03ca96b36d128fea8f72efe288269fe80fc6/Formula/p/postgis.rb" +} From 63c645f443a037ed30a848ff2387b7de41c10a45 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Wed, 22 Jan 2025 13:30:27 +0800 Subject: [PATCH 02/22] download formula to disk --- action.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 90f6de4..a1d2ca4 100644 --- a/action.yml +++ b/action.yml @@ -87,9 +87,18 @@ runs: echo "Error: PostGIS version ${{ inputs.postgis_version }} is not supported on macOS" exit 1 fi - - # Install specific version - brew install "$FORMULA_URL" + + # Download formula file + if ! wget "$FORMULA_URL" -O ./postgis.rb; then + echo "Error: Failed to download formula from $FORMULA_URL" + exit 1 + fi + + # Install from local file + brew install --HEAD -s ./postgis.rb + + # Cleanup + rm -f ./postgis.rb - name: Detect PostgreSQL Version (Windows) if: runner.os == 'Windows' From ed45ebb8dcaf684b793463ce61c590833e8cb4e3 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Wed, 22 Jan 2025 14:23:32 +0800 Subject: [PATCH 03/22] brew install without -s --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a1d2ca4..89a2d0d 100644 --- a/action.yml +++ b/action.yml @@ -95,7 +95,7 @@ runs: fi # Install from local file - brew install --HEAD -s ./postgis.rb + brew install --HEAD ./postgis.rb # Cleanup rm -f ./postgis.rb From 71315fcb5872a622544372db4d1b066c79c5c126 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 10:58:59 +0800 Subject: [PATCH 04/22] check pg version in macos runner --- action.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/action.yml b/action.yml index 89a2d0d..5f4fd02 100644 --- a/action.yml +++ b/action.yml @@ -70,6 +70,18 @@ runs: sudo apt-get install postgresql-$PG_VERSION-postgis-3 shell: bash + - name: Check PostgreSQL version (macOS) + if: runner.os == 'macOS' + id: pg-version-mac + shell: bash + run: | + # Get major version using psql + PG_VERSION=$(psql -t -A -c "SELECT split_part(version(), ' ', 2)" '${{ steps.pg.outputs.connection-uri }}' | cut -d. -f1) + echo "Found PostgreSQL major version: $PG_VERSION" + + # Output version for next steps + echo "version=$PG_VERSION" >> $GITHUB_OUTPUT + - name: Install PostGIS on macOS if: runner.os == 'macOS' shell: bash From c8f2a9c8cdacea99d3acc2dcc09e03149a6d09b3 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 11:10:37 +0800 Subject: [PATCH 05/22] update dependecy on pg before install --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index 5f4fd02..f15d8fa 100644 --- a/action.yml +++ b/action.yml @@ -106,6 +106,10 @@ runs: exit 1 fi + # Modify formula to depend on specific PostgreSQL version + PG_VERSION="${{ steps.pg-version-mac.outputs.version }}" + sed -i '' "s/depends_on \"postgresql\"/depends_on \"postgresql@${PG_VERSION}\"/" ./postgis.rb + # Install from local file brew install --HEAD ./postgis.rb From 45d71dce8b3f1525ad79caab60d0240ef83888cf Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 11:23:33 +0800 Subject: [PATCH 06/22] print out the new postgis.rb --- action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/action.yml b/action.yml index f15d8fa..1ef39a6 100644 --- a/action.yml +++ b/action.yml @@ -109,6 +109,11 @@ runs: # Modify formula to depend on specific PostgreSQL version PG_VERSION="${{ steps.pg-version-mac.outputs.version }}" sed -i '' "s/depends_on \"postgresql\"/depends_on \"postgresql@${PG_VERSION}\"/" ./postgis.rb + + # Show the entire modified formula + echo "=== Modified formula content ===" + cat ./postgis.rb + echo "===========================" # Install from local file brew install --HEAD ./postgis.rb From 21b14a282fdde9491d34b821aee68d4bec8b910e Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 11:43:54 +0800 Subject: [PATCH 07/22] wip --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 1ef39a6..b859e50 100644 --- a/action.yml +++ b/action.yml @@ -108,7 +108,7 @@ runs: # Modify formula to depend on specific PostgreSQL version PG_VERSION="${{ steps.pg-version-mac.outputs.version }}" - sed -i '' "s/depends_on \"postgresql\"/depends_on \"postgresql@${PG_VERSION}\"/" ./postgis.rb + sed -i '' '/depends_on/ s/"postgresql[^"]*"/"postgresql@'"${PG_VERSION}"'"/' ./postgis.rb # Show the entire modified formula echo "=== Modified formula content ===" From 1e6bce6591f1277417c57dde653673419b46290e Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 12:24:33 +0800 Subject: [PATCH 08/22] update test --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f2604a..a668bc2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,6 @@ jobs: PGSERVICE: ${{ steps.postgres.outputs.service-name }} - name: Verify PostGIS 3.5.0 installation on Windows - if: matrix.os == 'windows-latest' + if: matrix.os == 'windows-latest' || matrix.os == 'macos-latest' run: | psql -v ON_ERROR_STOP=1 -c "SELECT PostGIS_Full_Version();" "${{ steps.postgres.outputs.connection-uri }}" | findstr /C:"POSTGIS=3.5.0 3.5.0" From 97b067c97f8f021f5a3b7d2ee24b624e966d8472 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 12:27:30 +0800 Subject: [PATCH 09/22] update doc --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 20e6840..14b0be1 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ steps: | database | The database name to setup and grant permissions to created user. | `postgres` | | port | The server port to listen on. | `5432` | | postgres-version | The PostgreSQL version to install. | `17` | -| postgis_version | **(Windows only)** The PostGIS version to installed. | By default (empty), will use the latest. See available versions [here](https://download.osgeo.org/postgis/windows/). If set, must use the entire version string like `3.3.3` | +| postgis_version | **(Windows and macOS only)** The PostGIS version to install. | By default (empty), will use the latest. See available versions [here](https://download.osgeo.org/postgis/windows/). If set, must use the entire version string like `3.3.3` | | cached-dir | Where should the temporary downloads be placed. Used to download and cache PostGIS binary. | `downloads` | #### Outputs From 19ff73a04f24c96946bc6fa75508dd8809cdfedb Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 12:28:27 +0800 Subject: [PATCH 10/22] do not use the latest version in test --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a668bc2..1b3a5cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: password: GrandMaster database: jedi_order port: 34837 - postgres-version: 17 + postgres-version: 15 postgis_version: 3.5.0 id: postgres From 9020d6f635e582f20eadace496541745a3d0e492 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 13:35:35 +0800 Subject: [PATCH 11/22] update test --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b3a5cc..fe27e49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,12 @@ jobs: PGSERVICE: ${{ steps.postgres.outputs.service-name }} - name: Verify PostGIS 3.5.0 installation on Windows - if: matrix.os == 'windows-latest' || matrix.os == 'macos-latest' + if: matrix.os == 'windows-latest' run: | psql -v ON_ERROR_STOP=1 -c "SELECT PostGIS_Full_Version();" "${{ steps.postgres.outputs.connection-uri }}" | findstr /C:"POSTGIS=3.5.0 3.5.0" + + - name: Verify PostGIS 3.5.0 installation on macOS + if: matrix.os == 'macos-latest' + run: | + psql -v ON_ERROR_STOP=1 -c "SELECT PostGIS_Full_Version();" "${{ steps.postgres.outputs.connection-uri }}" | grep "3.5.0" + \ No newline at end of file From e3e3d72f89e2a5f0f49c2c8f9f2d417d4e200a4b Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 13:50:28 +0800 Subject: [PATCH 12/22] remove --head --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b859e50..3aa03b7 100644 --- a/action.yml +++ b/action.yml @@ -116,7 +116,7 @@ runs: echo "===========================" # Install from local file - brew install --HEAD ./postgis.rb + brew install ./postgis.rb # Cleanup rm -f ./postgis.rb From 857f58681482e145b699641fda9c7f46ba3fd8d3 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 14:16:47 +0800 Subject: [PATCH 13/22] disable auto upgrade --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 3aa03b7..47d99d3 100644 --- a/action.yml +++ b/action.yml @@ -85,6 +85,9 @@ runs: - name: Install PostGIS on macOS if: runner.os == 'macOS' shell: bash + env: + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: true + HOMEBREW_NO_INSTALL_UPGRADE: true run: | # If no version specified, install latest if [[ -z "${{ inputs.postgis_version }}" ]]; then From 1901118f0cb4cd1b664f5a9d932210b02e3bfc0b Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 14:23:33 +0800 Subject: [PATCH 14/22] brew install -v --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 47d99d3..9170213 100644 --- a/action.yml +++ b/action.yml @@ -91,7 +91,7 @@ runs: run: | # If no version specified, install latest if [[ -z "${{ inputs.postgis_version }}" ]]; then - brew install postgis + brew install postgis -v exit 0 fi @@ -119,7 +119,7 @@ runs: echo "===========================" # Install from local file - brew install ./postgis.rb + brew install ./postgis.rb -v # Cleanup rm -f ./postgis.rb From ec26310ff9cde607ce917d5526bd8f2f97ddba7b Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 15:57:13 +0800 Subject: [PATCH 15/22] update links --- postgis-macos-versions.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/postgis-macos-versions.json b/postgis-macos-versions.json index 3de9635..9c461cc 100644 --- a/postgis-macos-versions.json +++ b/postgis-macos-versions.json @@ -1,8 +1,8 @@ { - "3.5.2": "https://raw.githubusercontent.com/Homebrew/homebrew-core/0e8cf73743fc1b148182ada18cbd1ea586e8b638/Formula/p/postgis.rb", + "3.5.2": "https://github.com/Homebrew/homebrew-core/raw/0e8cf73743fc1b148182ada18cbd1ea586e8b638/Formula/p/postgis.rb", "3.5.1": "https://github.com/Homebrew/homebrew-core/raw/a78958a211e79d151309de3038d20add73306d6c/Formula/p/postgis.rb", - "3.5.0": "https://github.com/Homebrew/homebrew-core/raw/3c9711ac5aaa062e65960e4ee8286471782fbf6e/Formula/p/postgis.rb", + "3.5.0": "https://github.com/Homebrew/homebrew-core/raw/5975ad00882d998b3e1ef1fb2906000f23f18466/Formula/p/postgis.rb", "3.4.3": "https://github.com/Homebrew/homebrew-core/raw/2858d71fabde44101eeb2a7bfbcf3b5ca2c2aa76/Formula/p/postgis.rb", "3.4.2": "https://github.com/Homebrew/homebrew-core/raw/b1dbe7afb89d1860ed459b57d4e631de7c902462/Formula/p/postgis.rb", - "3.3.4": "https://github.com/Homebrew/homebrew-core/raw/e2bd03ca96b36d128fea8f72efe288269fe80fc6/Formula/p/postgis.rb" + "3.3.4": "https://github.com/Homebrew/homebrew-core/raw/fc8e7c36c7906eddd94ebf5109d57756a073f50f/Formula/p/postgis.rb" } From 41ef278f29d7c1bd173f5a8289747e6626856417 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 15:57:45 +0800 Subject: [PATCH 16/22] brew install with -s --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9170213..76ffdcd 100644 --- a/action.yml +++ b/action.yml @@ -119,7 +119,7 @@ runs: echo "===========================" # Install from local file - brew install ./postgis.rb -v + brew install ./postgis.rb -v -s # Cleanup rm -f ./postgis.rb From 39a43c9b8971d4019bdac1e99d4f6c83be1261e8 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 16:16:00 +0800 Subject: [PATCH 17/22] add some envs for postgis installation --- action.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/action.yml b/action.yml index 76ffdcd..0d7bf10 100644 --- a/action.yml +++ b/action.yml @@ -82,6 +82,20 @@ runs: # Output version for next steps echo "version=$PG_VERSION" >> $GITHUB_OUTPUT + - name: Setup PostgreSQL environment (macOS) + if: runner.os == 'macOS' + shell: bash + run: | + # Get PostgreSQL installation path using brew + PG_PREFIX=$(brew --prefix postgresql@${{ steps.pg-version-mac.outputs.version }}) + echo "PostgreSQL prefix: $PG_PREFIX" + + # Set environment variables + echo "PATH=$PG_PREFIX/bin:$PATH" >> $GITHUB_ENV + echo "LDFLAGS=-L$PG_PREFIX/lib" >> $GITHUB_ENV + echo "CPPFLAGS=-I$PG_PREFIX/include" >> $GITHUB_ENV + echo "PKG_CONFIG_PATH=$PG_PREFIX/lib/pkgconfig" >> $GITHUB_ENV + - name: Install PostGIS on macOS if: runner.os == 'macOS' shell: bash From bdb9327ff62c0e138eb97351ba885022ef7e8337 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 23 Jan 2025 16:30:26 +0800 Subject: [PATCH 18/22] update sed command --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 0d7bf10..9468e39 100644 --- a/action.yml +++ b/action.yml @@ -125,7 +125,7 @@ runs: # Modify formula to depend on specific PostgreSQL version PG_VERSION="${{ steps.pg-version-mac.outputs.version }}" - sed -i '' '/depends_on/ s/"postgresql[^"]*"/"postgresql@'"${PG_VERSION}"'"/' ./postgis.rb + sed -i '' 's/postgresql@[0-9]\+/postgresql@'"${PG_VERSION}"'/g' ./postgis.rb # Show the entire modified formula echo "=== Modified formula content ===" From 4ea04f4c06f3f3f631f74662c15fb2f928f458c9 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 23 Jan 2025 23:22:13 +0800 Subject: [PATCH 19/22] use perl instead of sed --- action.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 9468e39..e7f9923 100644 --- a/action.yml +++ b/action.yml @@ -125,8 +125,7 @@ runs: # Modify formula to depend on specific PostgreSQL version PG_VERSION="${{ steps.pg-version-mac.outputs.version }}" - sed -i '' 's/postgresql@[0-9]\+/postgresql@'"${PG_VERSION}"'/g' ./postgis.rb - + perl -i -pe 's/postgresql@\d+/postgresql@'"${PG_VERSION}"'/g' ./postgis.rb # Show the entire modified formula echo "=== Modified formula content ===" cat ./postgis.rb From 6b6328405ced49a945b5abd39e34324ce684155d Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 23 Jan 2025 23:34:51 +0800 Subject: [PATCH 20/22] update perl command --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index e7f9923..f10a6e5 100644 --- a/action.yml +++ b/action.yml @@ -125,7 +125,8 @@ runs: # Modify formula to depend on specific PostgreSQL version PG_VERSION="${{ steps.pg-version-mac.outputs.version }}" - perl -i -pe 's/postgresql@\d+/postgresql@'"${PG_VERSION}"'/g' ./postgis.rb + # Replace all postgresql@X occurrences with our version + perl -i -pe 's/postgresql@[0-9]+/postgresql@'"${PG_VERSION}"'/g' ./postgis.rb # Show the entire modified formula echo "=== Modified formula content ===" cat ./postgis.rb From e99850405db81f7b4492d0c8b70469f8ff145a45 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 23 Jan 2025 23:53:06 +0800 Subject: [PATCH 21/22] wip --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index f10a6e5..a671955 100644 --- a/action.yml +++ b/action.yml @@ -125,8 +125,8 @@ runs: # Modify formula to depend on specific PostgreSQL version PG_VERSION="${{ steps.pg-version-mac.outputs.version }}" - # Replace all postgresql@X occurrences with our version - perl -i -pe 's/postgresql@[0-9]+/postgresql@'"${PG_VERSION}"'/g' ./postgis.rb + # Replace all postgresql@X occurrences with our version, using double quotes to allow variable expansion + perl -i -pe "s/postgresql@[0-9]+/postgresql@${PG_VERSION}/g" ./postgis.rb # Show the entire modified formula echo "=== Modified formula content ===" cat ./postgis.rb From ed5a9f52ec6a0778634d04fcb5d3ee305f202d08 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 24 Jan 2025 00:21:12 +0800 Subject: [PATCH 22/22] wip --- action.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index a671955..c095675 100644 --- a/action.yml +++ b/action.yml @@ -123,10 +123,9 @@ runs: exit 1 fi - # Modify formula to depend on specific PostgreSQL version - PG_VERSION="${{ steps.pg-version-mac.outputs.version }}" - # Replace all postgresql@X occurrences with our version, using double quotes to allow variable expansion - perl -i -pe "s/postgresql@[0-9]+/postgresql@${PG_VERSION}/g" ./postgis.rb + # Replace all postgresql@X references with detected version + sed -i '' 's/postgresql@[0-9]*/postgresql@${{ steps.pg-version-mac.outputs.version }}/g' ./postgis.rb + # Show the entire modified formula echo "=== Modified formula content ===" cat ./postgis.rb