Skip to content

Commit d32b323

Browse files
committed
meson: ci: test extensions
1 parent 3203147 commit d32b323

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

.cirrus.yml

+17-1
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,32 @@ task:
358358
task:
359359
<<: *linux_opensuse_template
360360

361-
name: Linux - OpenSuse Tumbleweed (LLVM) - Meson
361+
name: Linux - OpenSuse Tumbleweed (LLVM) - Meson - Test Extensions
362362

363363
configure_script:
364364
- su postgres -c 'meson setup --buildtype debug -Dcassert=true -Dssl=openssl -Duuid=e2fs -Dllvm=enabled build'
365365

366+
###
367+
# build & run tests
366368
build_script: su postgres -c 'ninja -C build'
369+
367370
upload_caches: ccache
368371

369372
tests_world_script:
370373
- su postgres -c 'meson test --no-rebuild -C build --num-processes ${TEST_JOBS}'
374+
###
375+
376+
###
377+
# test extensions
378+
install_script: ninja -C build install
379+
380+
# some of the make commands of test_execution script needs to run with sudo,
381+
# that command makes postgres user can execute sudo commands without password
382+
dont_ask_sudo_pw_script:
383+
- echo "postgres ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/postgres
384+
385+
install_extensions_script: su postgres -c 'python3 src/tools/ci/test_extensions'
386+
###
371387

372388
on_failure:
373389
<<: *on_failure

src/tools/ci/docker/linux_opensuse_tumbleweed

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ RUN \
4949
lz4 \
5050
zstd \
5151
\
52+
### packages needed by extensions ###
53+
sudo \
54+
\
55+
# pgbouncer
56+
libevent-devel \
57+
pandoc \
58+
\
5259
&& \
5360
zypper -n clean -a
5461

src/tools/ci/test_extensions

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import shutil
5+
import subprocess
6+
import sys
7+
8+
tmp_dir = '/tmp'
9+
extension_dir = '/tmp/extension'
10+
extensions = []
11+
failed_extensions = []
12+
git_clone_command = ['git', 'clone', '--depth', '1']
13+
14+
# add pg_cron
15+
extensions.append(
16+
{
17+
'extension_name': 'pg_cron',
18+
'download': [
19+
git_clone_command + ['https://github.com/citusdata/pg_cron.git', extension_dir],
20+
],
21+
'build': [
22+
['make'],
23+
['sudo', 'make', 'install']
24+
],
25+
'test': [
26+
['make', 'installcheck'],
27+
]
28+
}
29+
)
30+
31+
# add pgbouncer
32+
extensions.append(
33+
{
34+
'extension_name': 'pgbouncer',
35+
'download': [
36+
git_clone_command + ['https://github.com/pgbouncer/pgbouncer.git', extension_dir],
37+
],
38+
'build': [
39+
['git', 'submodule', 'init'],
40+
['git', 'submodule', 'update'],
41+
['./autogen.sh'],
42+
['./configure', '--prefix=/usr/local'],
43+
['make'],
44+
['sudo', 'make', 'install']
45+
],
46+
'test': [
47+
['make', '-C', './test', 'all'],
48+
['make', '-C', './test', 'check']
49+
]
50+
}
51+
)
52+
53+
# if that function returns True, that means there is
54+
# error while running command
55+
def run_commands(extension, current_process, cwd=extension_dir) -> bool:
56+
if current_process in extension and extension[current_process]:
57+
print('\n\n### {} {} ###\n'.format(current_process, extension['extension_name']), flush=True)
58+
for command in extension[current_process]:
59+
result = subprocess.run(command, cwd=cwd,)
60+
if result.returncode:
61+
failed_extensions.append('`{}` is failed at step `{}`'
62+
.format(extension['extension_name'], current_process))
63+
return True
64+
else:
65+
print('\n\n### No {} found for {} ###\n'.format(current_process, extension['extension_name']), flush=True)
66+
return False
67+
68+
def clear_extension_dir():
69+
if os.path.exists(extension_dir) and os.path.isdir(extension_dir):
70+
print('### Clearing {} ###'.format(extension_dir), flush=True)
71+
shutil.rmtree(extension_dir)
72+
73+
has_error = False
74+
for extension in extensions:
75+
print('\n\n##### {} #####\n'.format(extension['extension_name']), flush=True)
76+
77+
clear_extension_dir()
78+
79+
process_order = [['download', tmp_dir], ['build', extension_dir], ['test', extension_dir]]
80+
for process, cwd in process_order:
81+
if run_commands(extension, process, cwd):
82+
print('\n##### There are errors while testing {} #####\n\n'.format(extension['extension_name']), flush=True)
83+
has_error = True
84+
break
85+
86+
if not has_error:
87+
print('\n##### {} is completed #####\n\n'.format(extension['extension_name']), flush=True)
88+
89+
if failed_extensions:
90+
for failed_extension in failed_extensions:
91+
print(failed_extension)
92+
sys.exit('There are failed extensions, exiting')

0 commit comments

Comments
 (0)