Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
118 lines (109 loc) · 5.1 KB
/
Copy pathaction.yml
File metadata and controls
118 lines (109 loc) · 5.1 KB
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
name: PGXN Postgres Action
description: Install, configure, and start a PostgreSQL cluster for testing extensions.
author: David E. Wheeler
branding:
icon: database
color: orange
inputs:
version:
description: Major Postgres version to install
required: true
default: "19"
port:
description: The Postgres server port for Postgres
default: "55432"
required: false
packages:
description: List of additional packages to install
required: false
start:
description: Whether or not to start Postgres after installing
default: "true"
encoding:
description: The encoding to use for databases in the cluster
required: false
locale:
description: The locale to use for databases in the cluster
required: false
config:
description: Server configuration to apply to postgresql.conf
required: false
runs:
using: composite
steps:
- name: Install ${{ inputs.version }}
shell: bash
run: |
set -e
case "$RUNNER_OS" in
Linux)
sudo apt-get update
sudo apt-get -y purge postgresql-client-common
sudo apt-get install -y postgresql-common ca-certificates build-essential pgxnclient ${{ inputs.packages }}
sudo sed -i 's/#create_main_cluster = true/create_main_cluster = false/' /etc/postgresql-common/createcluster.conf
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -i -v ${{ inputs.version }}
PG_BIN=/usr/lib/postgresql/${{ inputs.version }}/bin
export PGDATA=/var/lib/postgresql/test
if [ "${{ inputs.start }}" == 'true' ]; then
# For some reason, the `--user` option causes `pg_createcluster`
# to freeze after `initdb`. So we have to do it manually.
sudo chown -R "$(whoami)" /var/lib/postgresql /var/run/postgresql
"$PG_BIN/initdb" -U postgres ${{ inputs.locale && format('--locale {0}', inputs.locale) }} ${{ inputs.encoding && format('--encoding {0}', inputs.encoding) }}
printf '\n%s\nport = ${{ inputs.port }}\n' "${{ inputs.config }}" >> "$PGDATA/postgresql.conf"
"$PG_BIN/pg_ctl" start
fi
printf '%s\n' "$PG_BIN" >> "$GITHUB_PATH"
printf 'PGPORT=${{ inputs.port }}\nPGUSER=postgres\nPG_CONFIG=%s/pg_config\nPGDATA=%s\n' "$PG_BIN" "$PGDATA" >> "$GITHUB_ENV"
;;
macOS)
export HOMEBREW_GITHUB_ACTIONS=1
export HOMEBREW_NO_ENV_HINTS=1
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_INSTALL_UPGRADE=1
brew install -y --quiet "postgresql@${{ inputs.version }}" pgxnclient ${{ inputs.packages }}
brew unlink --quiet "postgresql@${{ inputs.version }}"
brew link --quiet --overwrite "postgresql@${{ inputs.version }}"
export PGDATA="$RUNNER_TEMP/pgdata${{ inputs.version }}"
if [ "${{ inputs.start }}" == 'true' ]; then
initdb -U postgres ${{ inputs.locale && format('--locale {0}', inputs.locale) }} ${{ inputs.encoding && format('--encoding {0}', inputs.encoding) }}
printf '\n%s\nport = ${{ inputs.port }}\n' "${{ inputs.config }}" >> "$PGDATA/postgresql.conf"
pg_ctl start
fi
printf 'PGPORT=${{ inputs.port }}\nPGUSER=postgres\nPG_CONFIG=%s/bin/pg_config\nPGDATA=%s\n' "$(brew --prefix)" "$PGDATA" >> "$GITHUB_ENV"
;;
Windows)
choco install sudo ${{ inputs.packages }}
# Chocolatey downloads the PostgreSQL installer from
# get.enterprisedb.com, which intermittently responds with HTTP 403
# and aborts the install. Retry a few times to absorb such transient
# download failures.
for attempt in 1 2 3; do
if choco install postgresql${{ inputs.version }} \
--ia "--enable-components server,commandlinetools --extract-only 1" \
--no-progress; then
break
fi
if [ "$attempt" -eq 3 ]; then
echo "::error::Failed to install PostgreSQL after $attempt attempts."
exit 1
fi
echo "::warning::choco install failed (attempt $attempt), retrying in 15s..."
sleep 15
done
pip install pgxnclient
PG_BIN="$PROGRAMFILES/PostgreSQL/${{ inputs.version }}/bin"
export PGDATA="$RUNNER_TEMP/pgdata${{ inputs.version }}"
if [ "${{ inputs.start }}" == 'true' ]; then
"$PG_BIN/initdb.exe" -U postgres ${{ inputs.locale && format('--locale {0}', inputs.locale) }} ${{ inputs.encoding && format('--encoding {0}', inputs.encoding) }}
printf '\n%s\nport = ${{ inputs.port }}\n' "${{ inputs.config }}" >> "$PGDATA/postgresql.conf"
"$PG_BIN/pg_ctl.exe" start
fi
printf '%s\n' "$PG_BIN" >> $GITHUB_PATH
printf 'PGBIN=\nPGPASSWORD=\nPGPORT=${{ inputs.port }}\nPGUSER=postgres\nPG_CONFIG=%s/pg_config.exe\nPGDATA=%s\n' "$PG_BIN" "$PGDATA" >> "$GITHUB_ENV"
;;
*)
printf '%s not supported\n' "$RUNNER_OS"
exit 1
;;
esac