]> git.phdru.name Git - sqlconvert.git/blob - .github/workflows/run-tests.yaml
Build(GHActions): Use `checkout@v4` instead of outdated `v2`
[sqlconvert.git] / .github / workflows / run-tests.yaml
1 name: Run tests
2
3 on: [push, pull_request]
4
5 jobs:
6   run-tests:
7     env:
8       not_in_conda: "[]"
9
10     strategy:
11       matrix:
12         os: [ubuntu-latest, windows-latest]
13         python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
14         include:
15         - os: ubuntu-latest
16           os-name: Linux
17           pip-cache-path: ~/.cache/pip
18         - os: windows-latest
19           os-name: w32
20           pip-cache-path: ~\AppData\Local\pip\Cache
21
22     name: Python ${{ matrix.python-version }} @ ${{ matrix.os-name }}
23     runs-on: ${{ matrix.os }}
24
25     steps:
26
27       # Setup PostgreSQL
28       - uses: ankane/setup-postgres@v1
29       - name: Setup Postgres user @ Linux
30         run: |
31           sudo -u postgres psql --command="ALTER USER runner CREATEDB PASSWORD 'test'"
32         if: ${{ runner.os == 'Linux' }}
33       - name: Setup Postgres user @ w32
34         run: |
35           psql --command="CREATE USER runner CREATEDB PASSWORD 'test'"
36         if: ${{ runner.os == 'Windows' }}
37
38       # Setup Python/pip
39       - uses: actions/checkout@v4
40       - uses: s-weigand/setup-conda@v1
41         with:
42           conda-channels: conda-forge
43           python-version: ${{ matrix.python-version }}
44         if: ${{ !contains(fromJSON(env.not_in_conda), matrix.python-version) }}
45       - uses: actions/setup-python@v4
46         with:
47           python-version: ${{ matrix.python-version }}
48         if: ${{ contains(fromJSON(env.not_in_conda), matrix.python-version) }}
49       - name: Cache pip
50         uses: actions/cache@v3
51         with:
52           path: ${{ matrix.pip-cache-path }}
53           key: ${{ runner.os }}-pip
54
55       # Setup tox
56       - name: Install dependencies
57         run: |
58           python --version
59           python -m pip || python -m ensurepip --default-pip --upgrade
60           python -m pip install --upgrade pip setuptools wheel
61           pip --version
62           pip install --upgrade virtualenv "tox >= 3.15, < 4"
63       - name: Set TOXENV
64         run: |
65           import os, sys
66           ld_library_path = None
67           pyver = '%d%d' % tuple(sys.version_info[:2])
68           toxenv = 'py%s' % pyver
69           toxenv += ',py%s-sqlite' % pyver
70           if os.name == 'nt':
71             toxenv += '-w32'
72           toxenv += ',py%s-postgres' % pyver
73           if os.name == 'posix':
74             if pyver == '27':  # Python 2.7 on Linux requires `$LD_LIBRARY_PATH`
75               ld_library_path = os.path.join(
76                 os.path.dirname(os.path.dirname(sys.executable)), 'lib')
77             toxenv += ',py%s-flake8' % pyver
78           elif os.name == 'nt':
79             toxenv += '-w32'
80           with open(os.environ['GITHUB_ENV'], 'a') as f:
81             if ld_library_path:
82               f.write('LD_LIBRARY_PATH=' + ld_library_path + '\n')
83             f.write('TOXENV=' + toxenv + '\n')
84             f.write('PGPASSWORD=test\n')
85         shell: python
86
87       - name: Run tox
88         run: |
89           python -c "import os; print(os.environ['TOXENV'])"
90           tox --version
91           tox