From baaf187c81db932f830bf9a7c76129b819af7239 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Thu, 5 Jan 2023 12:32:39 +0100 Subject: [PATCH] Fix behave tests on GH actions MacOS (#2515) - the new MacOS doesn't play well with old go binaries (bump etcd) - use brew to install Postgres and expect (unbuffer, to make behave output colorful) and use the latest version - upload failed logs instead of grepping them to stdout --- .github/workflows/install_deps.py | 9 +++++---- .github/workflows/run_tests.py | 17 +++++++---------- .github/workflows/tests.yaml | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/install_deps.py b/.github/workflows/install_deps.py index 18c47e4b..130454d0 100644 --- a/.github/workflows/install_deps.py +++ b/.github/workflows/install_deps.py @@ -96,7 +96,7 @@ def unpack(archive, name): def install_etcd(): - version = os.environ.get('ETCDVERSION', '3.3.13') + version = os.environ.get('ETCDVERSION', '3.4.23') platform = {'linux2': 'linux', 'win32': 'windows', 'cygwin': 'windows'}.get(sys.platform, sys.platform) dirname = 'etcd-v{0}-{1}-amd64'.format(version, platform) ext = 'tar.gz' if platform == 'linux' else 'zip' @@ -108,16 +108,17 @@ def install_etcd(): def install_postgres(): - version = os.environ.get('PGVERSION', '14.1-1') + version = os.environ.get('PGVERSION', '15.1-1') platform = {'darwin': 'osx', 'win32': 'windows-x64', 'cygwin': 'windows-x64'}[sys.platform] + if platform == 'osx': + return subprocess.call(['brew', 'install', 'expect', 'postgresql@{0}'.format(version.split('.')[0])]) name = 'postgresql-{0}-{1}-binaries.zip'.format(version, platform) get_file('http://get.enterprisedb.com/postgresql/' + name, name) unzip_all(name) bin_dir = os.path.join('pgsql', 'bin') for f in os.listdir(bin_dir): chmod_755(os.path.join(bin_dir, f)) - subprocess.call(['pgsql/bin/postgres', '-V']) - return 0 + return subprocess.call(['pgsql/bin/postgres', '-V']) def main(): diff --git a/.github/workflows/run_tests.py b/.github/workflows/run_tests.py index 7395c393..9a078e4f 100644 --- a/.github/workflows/run_tests.py +++ b/.github/workflows/run_tests.py @@ -29,22 +29,19 @@ def main(): path = '/usr/lib/postgresql/{0}/bin:.'.format(version) unbuffer = ['timeout', '900', 'unbuffer'] else: - path = os.path.abspath(os.path.join('pgsql', 'bin')) if sys.platform == 'darwin': - path += ':.' - unbuffer = [] + version = os.environ.get('PGVERSION', '15.1-1') + path = '/usr/local/opt/postgresql@{0}/bin:.'.format(version.split('.')[0]) + unbuffer = ['unbuffer'] + else: + path = os.path.abspath(os.path.join('pgsql', 'bin')) + unbuffer = [] env['PATH'] = path + os.pathsep + env['PATH'] env['DCS'] = what if what == 'kubernetes': env['PATRONI_KUBERNETES_CONTEXT'] = 'k3d-k3s-default' - ret = subprocess.call(unbuffer + [sys.executable, '-m', 'behave'], env=env) - - if ret != 0: - if subprocess.call('grep . features/output/*_failed/*postgres?.*', shell=True) != 0: - subprocess.call('grep . features/output/*/*postgres?.*', shell=True) - return 1 - return 0 + return subprocess.call(unbuffer + [sys.executable, '-m', 'behave'], env=env) if __name__ == '__main__': diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0ff62f03..c8cbc10c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -92,8 +92,8 @@ jobs: runs-on: ${{ fromJson('{"ubuntu":"ubuntu-20.04","windows":"windows-latest","macos":"macos-latest"}')[matrix.os] }} env: DCS: ${{ matrix.dcs }} - ETCDVERSION: 3.3.13 - PGVERSION: 12.1-1 # for windows and macos + ETCDVERSION: 3.4.23 + PGVERSION: 15.1-1 # for windows and macos strategy: fail-fast: false matrix: @@ -133,6 +133,16 @@ jobs: run: python .github/workflows/install_deps.py - name: Run behave tests run: python .github/workflows/run_tests.py + - name: Upload logs if behave failed + uses: actions/upload-artifact@v3 + if: failure() + with: + name: behave-${{ matrix.os }}-${{ matrix.dcs }}-${{ matrix.python-version }}-logs + path: | + features/output/*_failed/*postgres?.* + features/output/* + if-no-files-found: error + retention-days: 5 - uses: actions/setup-python@v4 with: python-version: '3.10'