]> git.phdru.name Git - m_librarian.git/blob - .github/workflows/run-tests.yaml
e5e1d5576c57455f9ed1737d096c3269f08901fe
[m_librarian.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, macos-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: macos-latest
19           os-name: OSX
20           pip-cache-path: ~/Library/Caches/pip
21         - os: windows-latest
22           os-name: w32
23           pip-cache-path: ~\AppData\Local\pip\Cache
24
25     name: Python ${{ matrix.python-version }} @ ${{ matrix.os-name }}
26     runs-on: ${{ matrix.os }}
27
28     steps:
29
30       # Setup Python/pip
31       - uses: actions/checkout@v2
32       - uses: s-weigand/setup-conda@v1
33         with:
34           conda-channels: conda-forge
35           python-version: ${{ matrix.python-version }}
36         if: ${{ !contains(fromJSON(env.not_in_conda), matrix.python-version) }}
37       - uses: actions/setup-python@v4
38         with:
39           python-version: ${{ matrix.python-version }}
40         if: ${{ contains(fromJSON(env.not_in_conda), matrix.python-version) }}
41       - name: Cache pip
42         uses: actions/cache@v3
43         with:
44           path: ${{ matrix.pip-cache-path }}
45           key: ${{ runner.os }}-pip
46
47       # Setup tox
48       - name: Install dependencies
49         run: |
50           python --version
51           python -m pip || python -m ensurepip --default-pip --upgrade
52           python -m pip install --upgrade pip setuptools wheel
53           pip --version
54           pip install --upgrade virtualenv "tox >= 3.15, < 4"
55       - name: Set TOXENV
56         run: |
57           import os, sys
58           ld_library_path = None
59           pyver = '%d%d' % tuple(sys.version_info[:2])
60           toxenv = 'py%s-sqlite' % pyver
61           if os.name == 'posix':
62               if pyver == '27':  # Python 2.7 on Linux requires `$LD_LIBRARY_PATH`
63                   ld_library_path = os.path.join(
64                       os.path.dirname(os.path.dirname(sys.executable)), 'lib')
65               toxenv += ',py%s-flake8' % pyver
66           elif os.name == 'nt':
67               toxenv += '-w32'
68           with open(os.environ['GITHUB_ENV'], 'a') as f:
69               if ld_library_path:
70                 f.write('LD_LIBRARY_PATH=' + ld_library_path + '\n')
71               f.write('TOXENV=' + toxenv + '\n')
72         shell: python
73
74       - name: Run tox
75         run: |
76           python -c "import os; print(os.environ['TOXENV'])"
77           tox --version
78           tox