forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
310 lines (280 loc) · 11.2 KB
/
ci-lazypg.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# This workflow will build and test PL/Java against a version of PostgreSQL
# lazily obtained (either preinstalled in the GitHub Actions runner environment,
# or obtained from a package repository if the runner does not provide one).
# Arrange for the matrix to include a pg version, for cases where one must be
# installed.
name: CI lazy getting PostgreSQL
permissions:
contents: read
on:
push:
branches: [ master, REL1_6_STABLE, chore/REL1_6_STABLE/gha ]
pull_request:
branches: [ master, REL1_6_STABLE ]
jobs:
build:
if: true
runs-on: ${{ matrix.oscc.os }}
continue-on-error: true
strategy:
matrix:
oscc:
# - os: ubuntu-latest
# cc: gcc
# - os: macos-13
# cc: clang
# pg: 17
# - os: macos-14
# cc: clang
# pg: 17
- os: windows-latest
cc: msvc
# - os: windows-latest
# cc: mingw
java: [21]
steps:
- name: Check for JDK preinstalled
id: jdkcheck
shell: bash
env:
JAVAVER: ${{ matrix.java }}
run: |
if
candidate="JAVA_HOME_${JAVAVER}_${RUNNER_ARCH}"
echo -n "Environment contains $candidate? "
[[ -n ${!candidate+set} ]]
then
echo yes
echo >>"$GITHUB_ENV" "JAVA_HOME=${!candidate}"
echo >>"$GITHUB_OUTPUT" java_found=true
elif
candidate="JAVA_HOME_${JAVAVER}_$(tr A-Z a-z <<<${RUNNER_ARCH})"
echo -ne 'no\n'"Environment contains $candidate? "
[[ -n ${!candidate+set} ]]
then
echo yes
echo >>"$GITHUB_ENV" "JAVA_HOME=${!candidate}"
echo >>"$GITHUB_OUTPUT" java_found=true
else
echo -e 'no\n'"only: ${!JAVA_HOME_*}"
echo >>"$GITHUB_OUTPUT" java_found=false
fi
- name: Fetch a JDK
if: ${{ 'false' == steps.jdkcheck.outputs.java_found }}
uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b
with:
distribution: temurin
java-version: ${{ matrix.java }}
- name: Compute absolute paths for java and jshell
shell: bash
run: |
if [[ $RUNNER_OS == Windows ]]
then
echo >>"$GITHUB_ENV" "ABS_JAVA=$JAVA_HOME"'\bin\java'
echo >>"$GITHUB_ENV" "ABS_JSHELL=$JAVA_HOME"'\bin\jshell'
else
echo >>"$GITHUB_ENV" "ABS_JAVA=$JAVA_HOME/bin/java"
echo >>"$GITHUB_ENV" "ABS_JSHELL=$JAVA_HOME/bin/jshell"
fi
- name: Set PGCONFIG in environment, installing PostgreSQL if needed
shell: bash
env:
PGVER: ${{ matrix.oscc.pg }}
run: |
if [[ $RUNNER_OS == Linux ]]
then
echo >>"$GITHUB_ENV" PGCONFIG=pg_config
elif [[ $RUNNER_OS == Windows ]]
then
echo >>"$GITHUB_ENV" PGCONFIG="$PGBIN"'\pg_config'
elif [[ $RUNNER_OS == macOS ]]
then
echo '::group::brew update'
brew update
echo '::endgroup::'
echo "::group::brew install postgresql@$PGVER"
# HOMEBREW_GITHUB_ACTIONS will suppress the formula's initdb
HOMEBREW_GITHUB_ACTIONS=1 HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 \
brew install postgresql@"$PGVER"
echo '::endgroup::'
pfx=$(brew --prefix postgresql@"$PGVER")
echo >>"$GITHUB_ENV" PGCONFIG="$pfx/bin/pg_config"
fi
- name: Report Java, Maven, and PostgreSQL versions
shell: bash
run: |
"$ABS_JAVA" -version
mvn --version
"$PGCONFIG"
- name: Obtain PG development files (Ubuntu, PGDG)
if: ${{ 'Linux' == runner.os }}
run: |
pgver=$("$PGCONFIG" --version)
pgver=${pgver##PostgreSQL }
pgver=${pgver%% *}
pgver=${pgver%.*}
echo '::group::Install PGDG key and repo'
curl -s -S https://www.postgresql.org/media/keys/ACCC4CF8.asc |
gpg --dearmor |
sudo dd of=/etc/apt/trusted.gpg.d/apt.postgresql.org.gpg
echo \
deb \
http://apt.postgresql.org/pub/repos/apt \
"$(lsb_release -cs)-pgdg" \
main |
sudo tee /etc/apt/sources.list.d/pgdg.list
echo '::endgroup::'
echo '::group::apt-get update'
sudo apt-get update
echo '::endgroup::'
echo "::group::apt-get install postgresql-server-dev-$pgver"
sudo apt-get install postgresql-server-dev-"$pgver" libkrb5-dev
echo '::endgroup::'
- name: Confirm PostgreSQL development files are present
shell: python
run: |
from os import getenv
from os.path import join
from re import sub
from subprocess import check_output
pgconfig = getenv('PGCONFIG')
def ask_pg_config(what):
return check_output([pgconfig, '--'+what]).splitlines()[0]
pgch = join(ask_pg_config('includedir-server'), b'pg_config.h')
with open(pgch, 'r') as f:
line = [ln for ln in f if ln.startswith('#define PG_VERSION_STR ')][0]
vers = sub(r'#define PG_VERSION_STR "(.*)"\n', r'\1', line)
print('PostgreSQL development files are present:', vers, sep='\n')
- name: Check out PL/Java
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
path: pljava
- name: Set plethora of MSVC environment variables (Windows MSVC)
if: ${{ 'Windows' == runner.os && 'msvc' == matrix.oscc.cc }}
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756
- name: Build PL/Java (Windows MSVC)
if: ${{ 'Windows' == runner.os && 'msvc' == matrix.oscc.cc }}
working-directory: pljava
# shell: cmd because of the issue described for ilammy/msvc-dev-cmd
# with Actions bash prepending stuff to the just-carefully-created PATH
shell: cmd
run: |
%M2%\mvn clean install --batch-mode ^
-Dpgsql.pgconfig="%PGCONFIG%" ^
-Psaxon-examples -Ppgjdbc ^
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: Build PL/Java (Linux, macOS)
if: ${{ 'Windows' != runner.os }}
working-directory: pljava
run: |
mvn clean install --batch-mode \
-Dpgsql.pgconfig="$PGCONFIG" \
-Psaxon-examples -Ppgjdbc \
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: Build PL/Java (Windows MinGW-w64)
if: ${{ 'Windows' == runner.os && 'mingw' == matrix.oscc.cc }}
working-directory: pljava
#
# GitHub Actions will allow 'bash' as a shell choice, even on a Windows
# runner, in which case it's the bash from Git for Windows. That isn't the
# same as the msys64\usr\bin\bash that we want; what's more, while both
# rely on a cygwin DLL, they don't rely on the same one, and an attempt
# to exec one from the other leads to a "fatal error - cygheap base
# mismatch". So, the bash we want has to be started by something other
# than the bash we've got. In this case, set shell: to a command that
# will use cmd to start the right bash.
#
# Some of the MinGW magic is set up by the bash profile run at "login", so
# bash must be started with -l. That profile ends with a cd $HOME, so to
# avoid changing the current directory, set HOME=. first (credit for that:
# https://superuser.com/a/806371). As set above, . is really the pljava
# working-directory, so the bash script should start by resetting HOME to
# the path of its parent.
#
# The runner is provisioned with a very long PATH that includes separate
# bin directories for pre-provisioned packages. The MinGW profile replaces
# that with a much shorter path, so mvn and pg_config below must be given
# as absolute paths (using M2 and PGBIN supplied in the environment) or
# they won't be found. As long as mvn itself can be found, it is able
# to find java without difficulty, using the JAVA_HOME that is also in
# the environment.
#
# Those existing variables in the environment are all spelled in Windows
# style with drive letters, colons, and backslashes, rather than the MinGW
# unixy style, but the mingw bash doesn't seem to object.
#
# If you use the runner-supplied bash to examine the environment, you will
# see MSYSTEM=MINGW64 already in it, but that apparently is something the
# runner-supplied bash does. It must be set here before invoking the MinGW
# bash directly.
#
env:
HOME: .
MSYSTEM: MINGW64
shell: 'cmd /C "c:\msys64\usr\bin\bash -l "{0}""'
run: |
HOME=$( (cd .. && pwd) )
"$M2"/mvn clean install --batch-mode \
-Dpgsql.pgconfig="$PGCONFIG" \
-Psaxon-examples -Ppgjdbc \
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: Install and test PL/Java
working-directory: pljava
shell: bash
run: |
packageJar=$(find pljava-packaging -name pljava-pg*.jar -print)
mavenRepo="$HOME/.m2/repository"
saxonVer=$(
find "$mavenRepo/net/sf/saxon/Saxon-HE" \
-name 'Saxon-HE-*.jar' -print |
sort |
tail -n 1
)
saxonVer=${saxonVer%/*}
saxonVer=${saxonVer##*/}
jdbcJar=$(
find "$mavenRepo/org/postgresql/postgresql" \
-name 'postgresql-*.jar' -print |
sort |
tail -n 1
)
#
# The runner on a Unix-like OS is running as a non-privileged user, but
# has passwordless sudo available (needed to install the PL/Java files
# into the system directories where the supplied PostgreSQL lives). By
# contrast, on Windows the runner has admin privilege, and can install
# the files without any fuss (but later below, pg_ctl will have to be
# used when starting PostgreSQL; pg_ctl has a Windows-specific ability
# to drop admin privs so postgres will not refuse to start).
#
# The Git for Windows bash environment includes a find command, and the
# things found have unixy paths returned. Make them Windowsy here, with
# a hardcoded assumption they start with /c which should become c: (as
# appears to be the case in the Windows runner currently).
#
echo '::group::Install files from the package jar'
if [[ $RUNNER_OS == Windows ]]
then
pathSep=';'
"$ABS_JAVA" -Dpgconfig="$PGCONFIG" -jar "$packageJar"
function toWindowsPath() {
local p
p="c:${1#/c}"
printf "%s" "${p//\//\\}"
}
jdbcJar="$(toWindowsPath "$jdbcJar")"
mavenRepo="$(toWindowsPath "$mavenRepo")"
else
pathSep=':'
sudo "$ABS_JAVA" -Dpgconfig="$PGCONFIG" -jar "$packageJar"
fi
echo '::endgroup::'
"$ABS_JSHELL" \
-execution local \
"-J--class-path=$packageJar$pathSep$jdbcJar" \
"--class-path=$packageJar" \
"-J--add-modules=java.sql.rowset,jdk.httpserver" \
"-J-Dpgconfig=$PGCONFIG" \
"-J-DmavenRepo=$mavenRepo" \
"-J-DsaxonVer=$saxonVer" \
CI/integration