-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
148 lines (137 loc) · 6.36 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Setup PostgreSQL and PostGIS for Linux/macOS/Windows
author: Yuri Astrakhan
description: Setup PostgreSQL server and install PostGIS extension.
branding:
icon: database
color: purple
inputs:
username:
description: The username of the user to setup.
default: postgres
required: false
password:
description: The password of the user to setup.
default: postgres
required: false
database:
description: The database name to setup and grant permissions to created user.
default: postgres
required: false
port:
description: The server port to listen on.
default: "5432"
required: false
cached-dir:
# TODO: move to runner's temp dir, help wanted
description: Where should the temporary downloads be placed. Used to download and cache PostGIS binary.
default: "downloads"
required: false
outputs:
connection-uri:
description: The connection URI to connect to PostgreSQL.
value: ${{ steps.pg.outputs.connection-uri }}
service-name:
description: The service name with connection parameters.
value: ${{ steps.pg.outputs.service-name }}
runs:
using: composite
steps:
- name: Install PostGIS (Linux)
if: runner.os == 'Linux'
run: |
# Detect installed PostgreSQL version
PG_VERSION=$(apt list --installed | grep -E 'postgresql-[0-9.]+' | sed -rn 's/.*postgresql-([0-9.]+).*/\1/p')
[[ "$PG_VERSION" =~ ^[0-9.]+$ ]] || (echo "Failed to detect Postgres version" && exit 1)
echo "Detected PostgreSQL version: $PG_VERSION"
# Install PostGIS
REPO_URL="https://apt.postgresql.org/pub/repos/apt/"
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] $REPO_URL $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list >/dev/null
sudo apt update
sudo apt-get install postgresql-$PG_VERSION-postgis-3
# sudo apt install curl ca-certificates gnupg
# curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null
# sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# sudo apt update
# sudo apt-get install postgis
shell: bash
- uses: tecolicom/actions-use-homebrew-tools@v1
if: runner.os == 'macOS'
with:
tools: 'postgis'
# A workaround for postgis installation bug on macOS. Might not be needed in the future
- name: Brew workaround 2 (Mac)
if: runner.os == 'macOS'
run: brew link --overwrite [email protected]
continue-on-error: true
shell: bash
- name: Decide Postgis version (Windows)
# Download the list of available Postgis versions, and decide which one to use
if: runner.os == '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 "pgis_bundle=$pgis_bundle"
Add-Content $env:GITHUB_OUTPUT "pgis_bundle_url=$pgis_bundle_url"
- name: Cache Postgis Download (Windows)
if: runner.os == 'Windows'
uses: actions/cache@v4
id: cache-downloads
with:
path: ${{ inputs.cached-dir }}
key: ${{ runner.os }}-${{ steps.postgis-ver.outputs.pgis_bundle_url }}
- name: Download Postgis (Windows)
if: runner.os == 'Windows' && steps.postgis-ver.outputs.cache-hit != 'true'
shell: pwsh
# Download Postgis bundle if not in cache
env:
PGIS_BUNDLE: ${{ steps.postgis-ver.outputs.pgis_bundle }}
PGIS_BUNDLE_URL: ${{ steps.postgis-ver.outputs.pgis_bundle_url }}
run: |
echo "Downloading $env:PGIS_BUNDLE from $env:PGIS_BUNDLE_URL"
$postgis_zip = "postgis.zip"
Invoke-WebRequest $env:PGIS_BUNDLE_URL -OutFile $postgis_zip -ErrorAction Stop
echo "Extracting ${{ inputs.cached-dir }}\$env:PGIS_BUNDLE\*"
Remove-Item ${{ inputs.cached-dir }} -Recurse -Force -ErrorAction Ignore
echo "Expanded $((Expand-Archive $postgis_zip -DestinationPath ${{ inputs.cached-dir }} -PassThru).count) files from $postgis_zip"
echo "Moved $((Move-Item -Path "${{ inputs.cached-dir }}\$env:PGIS_BUNDLE\*" -Destination ${{ inputs.cached-dir }} -Force -PassThru).count) files to ${{ inputs.cached-dir }}"
Remove-Item $postgis_zip
if (!(Test-Path "${{ inputs.cached-dir }}\*")) {
Write-Error "Could not find PostGIS files in ${{ inputs.cached-dir }}"
exit 1
}
- name: Install Postgis (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
if (!(Test-Path "${{ inputs.cached-dir }}\*")) {
Write-Error "Could not find PostGIS files in ${{ inputs.cached-dir }}"
exit 1
}
echo "Copied $((Copy-Item -Path "${{ inputs.cached-dir }}\*" -Destination $env:PGROOT -Force -Recurse -PassThru).count) PostGIS files to $env:PGROOT"
echo "Starting PostgreSQL and adding postgis extension"
$env:Path = "$env:PGBIN;" + $env:Path
& pg_ctl restart -D "$env:PGDATA"
& pg_isready
- name: Setup PostgreSQL for Linux/macOS/Windows
id: pg
uses: ikalnytskyi/action-setup-postgres@v6
with:
username: "${{ inputs.username }}"
password: "${{ inputs.password }}"
database: "${{ inputs.database }}"
port: "${{ inputs.port }}"
- name: Enable PostGIS extension
run: psql -v ON_ERROR_STOP=1 -c 'CREATE EXTENSION IF NOT EXISTS postgis;' '${{ steps.pg.outputs.connection-uri }}'
shell: bash