|
| 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