]> git.openstreetmap.org Git - nominatim.git/blob - .github/actions/setup-postgresql-windows/action.yml
prepare release 5.2.0.post11
[nominatim.git] / .github / actions / setup-postgresql-windows / action.yml
1 name: 'Setup Postgresql and Postgis on Windows'
2
3 description: 'Installs PostgreSQL and PostGIS for Windows and configures it for CI tests'
4
5 inputs:
6     postgresql-version:
7         description: 'Version of PostgreSQL to install'
8         required: true
9
10 runs:
11     using: "composite"  
12
13     steps:
14         - name: Set up PostgreSQL variables
15           shell: pwsh
16           run: |
17             $version = "${{ inputs.postgresql-version }}"
18             $root = "C:\Program Files\PostgreSQL\$version"
19             $bin = "$root\bin"
20
21             echo "PGROOT=$root" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
22             echo "PGBIN=$bin"   | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
23
24             echo "$bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
25
26         - name: Decide Postgis version (Windows)
27           id: postgis-ver
28           shell: pwsh
29           run: |
30             echo "PowerShell version: ${PSVersionTable.PSVersion}"
31             $PG_VERSION = Split-Path $env:PGROOT -Leaf
32             $postgis_page = "https://download.osgeo.org/postgis/windows/pg$PG_VERSION"
33             echo "Detecting PostGIS version from $postgis_page for PostgreSQL $PG_VERSION"
34             $pgis_bundle = (Invoke-WebRequest -Uri $postgis_page -ErrorAction Stop).Links.Where({$_.href -match "^postgis.*zip$"}).href
35             if (!$pgis_bundle) {
36               Write-Error "Could not find latest PostGIS version in $postgis_page that would match  ^postgis.*zip$  pattern"
37               exit 1
38             }
39             $pgis_bundle = [IO.Path]::ChangeExtension($pgis_bundle, [NullString]::Value)
40             $pgis_bundle_url = "$postgis_page/$pgis_bundle.zip"
41             Add-Content $env:GITHUB_OUTPUT "postgis_file=$pgis_bundle"
42             Add-Content $env:GITHUB_OUTPUT "postgis_bundle_url=$pgis_bundle_url"
43
44         - uses: actions/cache@v4
45           with:
46             path: |
47               C:/postgis.zip
48             key: postgis-cache-${{ steps.postgis-ver.outputs.postgis_file }}
49
50         - name: Download postgis
51           shell: pwsh
52           run: |
53             if (!(Test-Path "C:\postgis.zip")){(new-object net.webclient).DownloadFile($env:PGIS_BUNDLE_URL, "c:\postgis.zip")}
54             if (Test-path "c:\postgis_archive"){Remove-Item "c:\postgis_archive" -Recurse -Force}
55             7z x c:\postgis.zip -oc:\postgis_archive
56           env: 
57             PGIS_BUNDLE_URL: ${{ steps.postgis-ver.outputs.postgis_bundle_url }}
58
59         - name: Install postgis
60           shell: bash
61           run: |
62             echo "Root: $PGROOT, Bin: $PGBIN"
63             cp -r c:/postgis_archive/postgis-bundle-*/* "$PGROOT" 
64
65         - name: Start PostgreSQL on Windows
66           run: |
67             $pgService = Get-Service -Name postgresql*
68             Set-Service -InputObject $pgService -Status running -StartupType automatic
69             Start-Process -FilePath "$env:PGBIN\pg_isready" -Wait -PassThru
70           shell: pwsh
71
72         - name: Adapt postgresql configuration
73           shell: pwsh
74           env:
75             PGPASSWORD: root
76           run: |
77             & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET fsync = 'off';"
78             & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET synchronous_commit = 'off';"
79             & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET full_page_writes = 'off';"
80             & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET shared_buffers = '1GB';"
81             & "$env:PGBIN\psql" -U postgres -d postgres -c "ALTER SYSTEM SET port = 5432;"
82
83             Restart-Service -Name postgresql*
84             Start-Process -FilePath "$env:PGBIN\pg_isready" -Wait -PassThru
85
86         - name: Setup database users
87           shell: pwsh
88           env:
89             PGPASSWORD: root
90           run: |
91             & "$env:PGBIN\createuser" -U postgres -S www-data
92             & "$env:PGBIN\createuser" -U postgres -s runner
93         
94
95