-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
192 lines (177 loc) · 6.86 KB
/
action.yml
File metadata and controls
192 lines (177 loc) · 6.86 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: 'Install Postgres'
description: 'From zero to running Postgres faster than you can say "Postgres".'
branding:
icon: 'fast-forward'
color: 'orange'
inputs:
version:
description: 'The full, exact, version of postgres to install (e.g. 17.2.0).'
required: true
default: '17.2.0'
outputs:
dsn:
description: 'The DSN for connecting to the embedded postgres.'
data:
description: 'The path to the data directory of the embedded postgres.'
runs:
using: composite
steps:
- name: Install Postgres
shell: bash
env:
version: ${{ inputs.version }}
os: ${{ runner.os }}
arch: ${{ runner.arch }}
run: |
#!/bin/bash
# Install Postgres
#
# version is the version of the embedded postgres to install.
# The format must be in <major>.<minor>.<patch> format.
set -ueo pipefail
main() {
# Step 1: Validate and coearse the following version, or, and arch into
# their equivalent in the embedded postgres binaries file names.
#
# The os is taken from the runner.os context.
# From the docs:
#
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs
#
# runner.os
# The operating system of the runner executing the job.
# Possible values are Linux, Windows, or macOS.
#
# runner.arch
# The architecture of the runner executing the job. Possible
# values are X86, X64, ARM, or ARM64.
#
#
# The matrix is:
#
# # Darwin (macOS) binaries:
# embedded-postgres-binaries-darwin-amd64/ macOS X64
# embedded-postgres-binaries-darwin-arm64v8/ macOS ARM64
#
# # Linux binaries:
# embedded-postgres-binaries-linux-amd64/ Linux X64
# embedded-postgres-binaries-linux-amd64-alpine/ Linux X64
# embedded-postgres-binaries-linux-arm32v6/ Linux ARM
# embedded-postgres-binaries-linux-arm32v7/ Linux ARM
# embedded-postgres-binaries-linux-arm64v8/ Linux ARM64
# embedded-postgres-binaries-linux-i386/ Linux X86
# embedded-postgres-binaries-linux-ppc64le/ Linux - (PPC64LE not supported in Actions)
#
# # Windows binaries:
# embedded-postgres-binaries-windows-amd64/ Windows X64
# embedded-postgres-binaries-windows-i386/ Windows X86
#
case $os in
macOS)
os=darwin
case $arch in
X64)
arch=amd64
;;
ARM64)
arch=arm64v8
;;
*)
echo "Unsupported $os arch: $arch"
echo "Only X64 and ARM64 are supported on macOS."
;;
esac
;;
Linux)
os=linux
case $arch in
X64)
arch=amd64
;;
ARM)
arch=arm32v6
;;
ARM64)
arch=arm64v8
;;
X86)
arch=i386
;;
*)
echo "Unsupported $os arch: $arch"
echo "Only X64, ARM, ARM64, and X86 are supported on Linux."
exit 1
;;
esac
;;
Windows)
os=windows
case $arch in
X64)
arch=amd64
;;
X86)
arch=i386
;;
*)
echo "Unsupported arch: $arch"
echo "Only X64 and X86 are supported on Windows."
exit 1
;;
esac
;;
*)
echo "Unsupported OS: $os"
echo "Only Linux, Windows, and macOS are supported."
exit 1
;;
esac
mkdir -p "$HOME"/.local
cd "$HOME"/.local
url="https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-$os-$arch/$version/embedded-postgres-binaries-$os-$arch-$version.jar"
echo "Downloading Postgres:"
echo
echo " Version: $version"
echo " OS: $os"
echo " Arch: $arch"
echo " URL: $url"
# Download the embedded postgres binaries
curl -s -o /tmp/pg.jar -L "$url"
if [ ! -f /tmp/pg.jar ]; then
echo "Failed to find embedded postgres binaries for version $version on $os-$arch."
echo "Please find the right os, arch, and version here https://repo1.maven.org/maven2/io/zonky/test/postgres/"
echo "and update your step's version, os, and arch inputs accordingly."
exit 1
fi
# Extract the embedded postgres binaries
unzip -p /tmp/pg.jar "postgres-$os-*.txz" | xz -d | tar xvf - 1>/dev/null
export PATH=$PWD/bin:$PATH
echo "PATH=$PATH" >> $GITHUB_ENV
echo "Postgres $version added to PATH ($PWD/bin/postgres)"
# Custom Envs
#
# NOTE: DATABASE_URL is set using the DSN form so that, which allows
# for modification via appending, which the URL form does not. This enables
# the user to add additional parameters to the DSN as needed.
export PGDATA=${PGDATA:-$HOME/.local/share/postgres/data}
export PGHOST=${PGHOST:-/tmp}
export PGPORT=${PGPORT:-5432}
export PGUSER=${PGUSER:-postgres}
export PGPASSWORD=${PGPASSWORD:-postgres}
export PGDATABASE=${PGDATABASE:-postgres}
export PGSSLMODE=${PGSSLMODE:-disable}
env | grep '^PG' >> "$GITHUB_ENV"
DATABASE_URL="dbname=$PGDATABASE user=$PGUSER password=$PGPASSWORD host=$PGHOST port=$PGPORT sslmode=$PGSSLMODE"
echo "DATABASE_URL=$DATABASE_URL" >> "$GITHUB_ENV"
echo "Initializing database at $PGDATA"
initdb -D "$PGDATA" -U "$PGUSER"
echo "Starting Postgres at $PGHOST:$PGPORT"
pg_ctl -D "$PGDATA" \
-l "$PGDATA"/postgres.log \
-o "-d 2 -c shared_buffers=12MB -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c log_line_prefix=\"%d ::LOG::\"" \
start
# Outputs
echo "url=$DATABASE_URL" >> "$GITHUB_OUTPUT"
echo "data=$PGDATA" >> "$GITHUB_OUTPUT"
}
time main