From 238f3dd1d940f43ede8d07d43c7d4bec6990952d Mon Sep 17 00:00:00 2001 From: Sri CHaRan Date: Thu, 29 Jan 2026 21:49:59 +0530 Subject: [PATCH] ci/windows: add Postgresql setup action to tests --- .../setup-postgresql-windows/action.yml | 83 +++++++++++++++++++ .github/actions/setup-postgresql/action.yml | 2 + .github/workflows/ci-tests.yml | 4 + 3 files changed, 89 insertions(+) create mode 100644 .github/actions/setup-postgresql-windows/action.yml diff --git a/.github/actions/setup-postgresql-windows/action.yml b/.github/actions/setup-postgresql-windows/action.yml new file mode 100644 index 00000000..41256435 --- /dev/null +++ b/.github/actions/setup-postgresql-windows/action.yml @@ -0,0 +1,83 @@ +name: 'Setup Postgresql and Postgis on Windows' + +description: 'Installs PostgreSQL and PostGIS for Windows and configures it for CI tests' + +inputs: + postgresql-version: + description: 'Version of PostgreSQL to install' + required: true + +runs: + using: "composite" + + steps: + - name: Decide Postgis version (Windows) + id: postgis-ver + shell: pwsh + run: | + echo "PowerShell version: ${PSVersionTable.PSVersion}" + $PG_VERSION = Split-Path $env:PGROOT -Leaf + $postgis_page = "https://download.osgeo.org/postgis/windows/pg$PG_VERSION" + echo "Detecting PostGIS version from $postgis_page for PostgreSQL $PG_VERSION" + $pgis_bundle = (Invoke-WebRequest -Uri $postgis_page -ErrorAction Stop).Links.Where({$_.href -match "^postgis.*zip$"}).href + if (!$pgis_bundle) { + Write-Error "Could not find latest PostGIS version in $postgis_page that would match ^postgis.*zip$ pattern" + exit 1 + } + $pgis_bundle = [IO.Path]::ChangeExtension($pgis_bundle, [NullString]::Value) + $pgis_bundle_url = "$postgis_page/$pgis_bundle.zip" + Add-Content $env:GITHUB_OUTPUT "postgis_file=$pgis_bundle" + Add-Content $env:GITHUB_OUTPUT "postgis_bundle_url=$pgis_bundle_url" + + - uses: actions/cache@v4 + with: + path: | + C:/postgis.zip + key: postgis-cache-${{ steps.postgis-ver.outputs.postgis_file }} + + - name: Download postgis + run: | + if (!(Test-Path "C:\postgis.zip")){(new-object net.webclient).DownloadFile($env:PGIS_BUNDLE_URL, "c:\postgis.zip")} + if (Test-path "c:\postgis_archive"){Remove-Item "c:\postgis_archive" -Recurse -Force} + 7z x c:\postgis.zip -oc:\postgis_archive + shell: pwsh + env: + PGIS_BUNDLE_URL: ${{ steps.postgis-ver.outputs.postgis_bundle_url }} + + - name: Install postgis + run: | + echo "Root: $PGROOT, Bin: $PGBIN" + cp -r c:/postgis_archive/postgis-bundle-*/* "$PGROOT" + shell: bash + + - name: Start PostgreSQL on Windows + run: | + $pgService = Get-Service -Name postgresql* + Set-Service -InputObject $pgService -Status running -StartupType automatic + Start-Process -FilePath "$env:PGBIN\pg_isready" -Wait -PassThru + shell: pwsh + + - name: Adapt postgresql configuration + shell: pwsh + env: + PGPASSWORD: root + run: | + & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET fsync = 'off';" + & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET synchronous_commit = 'off';" + & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET full_page_writes = 'off';" + & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET shared_buffers = '1GB';" + & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET port = 5432;" + + Restart-Service -Name postgresql* + Start-Process -FilePath "$env:PGBIN\pg_isready" -Wait -PassThru + + - name: Setup database users + shell: pwsh + env: + PGPASSWORD: root + run: | + & "$env:PGBIN\createuser" -U postgres -S www-data + & "$env:PGBIN\createuser" -U postgres -s runner + + + diff --git a/.github/actions/setup-postgresql/action.yml b/.github/actions/setup-postgresql/action.yml index 7a9590c1..b868546b 100644 --- a/.github/actions/setup-postgresql/action.yml +++ b/.github/actions/setup-postgresql/action.yml @@ -1,5 +1,7 @@ name: 'Setup Postgresql and Postgis' +description: 'Installs PostgreSQL and PostGIS and configures it for CI tests' + inputs: postgresql-version: description: 'Version of PostgreSQL to install' diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 9b6c6b99..3d2d1090 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -152,6 +152,10 @@ jobs: - name: Unpack Nominatim run: tar xf nominatim-src.tar.bz2 + - uses: ./Nominatim/.github/actions/setup-postgresql-windows + with: + postgresql-version: 16 + - name: Set up Python uses: actions/setup-python@v5 with: