|
| 1 | +# actions can be run locally using act and docker, on Fedora 37 also with podman, using: |
| 2 | +# https://github.com/nektos/act |
| 3 | +# sudo dnf install -y act-cli podman-docker |
| 4 | +# act --bind --container-daemon-socket $XDG_RUNTIME_DIR/podman/podman.sock -W .github/workflows/main.yml |
| 5 | + |
1 | 6 | name: Unit tests |
2 | 7 |
|
| 8 | +# Checks can be skipped by adding "skip-checks: true" to a commit message, |
| 9 | +# or requested by adding "request-checks: true" if disabled by default for pushes: |
| 10 | +# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks#skipping-and-requesting-checks-for-individual-commits |
3 | 11 | on: [push, pull_request] |
| 12 | +env: |
| 13 | + PYTHONWARNINGS: "ignore:DEPRECATION" |
| 14 | + PIP_ROOT_USER_ACTION: "ignore" # For local testing using act-cli |
| 15 | + PIP_NO_WARN_SCRIPT_LOCATION: "0" # For local testing using act-cli |
| 16 | + PIP_DISABLE_PIP_VERSION_CHECK: "1" # Reduce noise in logs |
4 | 17 |
|
5 | 18 | jobs: |
6 | | - test_py2: |
7 | | - runs-on: ubuntu-20.04 |
8 | | - |
| 19 | + test: |
| 20 | + strategy: |
| 21 | + # See: https://github.com/xenserver/python-libs/pull/26#discussion_r1179482169 |
| 22 | + # max-parallel: 1 |
| 23 | + # Want to get the results of all the tests, don't terminate all on a fail: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - python-version: '3.11' |
| 28 | + os: ubuntu-latest |
| 29 | + # This tests with Python 2.7 and with Ubuntu-20.04's Python 3.8 for combined py2+3 coverage: |
| 30 | + - python-version: '2.7' |
| 31 | + os: ubuntu-20.04 |
| 32 | + - python-version: '3.10' |
| 33 | + os: ubuntu-latest |
| 34 | + - python-version: '3.9' |
| 35 | + os: ubuntu-latest |
| 36 | + - python-version: '3.7' |
| 37 | + os: ubuntu-latest |
| 38 | + - python-version: '3.6' |
| 39 | + os: ubuntu-20.04 |
| 40 | + runs-on: ${{ matrix.os }} |
9 | 41 | steps: |
10 | | - - uses: actions/checkout@v2 |
| 42 | + - uses: actions/checkout@v3 |
11 | 43 | with: |
12 | | - fetch-depth: 0 |
13 | | - - name: Set up Python 2.7 |
14 | | - uses: actions/setup-python@v2 |
| 44 | + fetch-depth: 0 # Needed by diff-cover to get the changed lines: origin/master..HEAD |
| 45 | + - name: Set up Python ${{ matrix.python-version }} |
| 46 | + uses: actions/setup-python@v4 |
15 | 47 | with: |
16 | | - python-version: '2.7' |
| 48 | + python-version: ${{ matrix.python-version }} |
17 | 49 |
|
18 | | - - name: Install dependencies |
19 | | - run: | |
20 | | - python -m pip install --upgrade pip |
21 | | - pip install -r requirements-dev.txt |
22 | | - # FIXME: branding.py still has no permanent home |
23 | | - curl https://gist.github.com/ydirson/3c36a7e19d762cc529a6c82340894ccc/raw/5ca39f621b1feab813e171f535c1aad1bd483f1d/branding.py -O -L |
24 | | - pip install pyliblzma |
25 | | - pip install -e . |
26 | | - command -v xz |
27 | | -
|
28 | | - - name: Test |
| 50 | + - name: Run of tox on ubuntu-latest |
| 51 | + if: ${{ startsWith(matrix.python-version, '3.') && matrix.python-version != 3.6 }} |
29 | 52 | run: | |
30 | | - pytest --cov -rP |
31 | | - coverage xml |
32 | | - coverage html |
33 | | - coverage html -d htmlcov-tests --include="tests/*" |
34 | | - diff-cover --html-report coverage-diff.html coverage.xml |
| 53 | + pip install 'virtualenv<20.22' 'tox>=4.5.1' tox-gh-actions |
| 54 | + tox --workdir .github/workflows/.tox --recreate |
35 | 55 |
|
36 | | - - name: Pylint |
| 56 | + # tox >= 4.0.0 is needed for using optional-dependencies from pyproject.toml, which is |
| 57 | + # is not available for python <= 3.6, so use the python3.8 of Ubuntu-20.04 to install it: |
| 58 | + - name: Install of tox on ubuntu-20.04 (to support optional-dependencies from pyproject.toml) |
| 59 | + if: ${{ matrix.python-version == 2.7 || matrix.python-version == 3.6 }} |
37 | 60 | run: | |
38 | | - pylint --version |
39 | | - pylint --exit-zero xcp/ tests/ setup.py |
40 | | - pylint --exit-zero --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" xcp/ tests/ setup.py > pylint.txt |
41 | | - diff-quality --violations=pylint --html-report pylint-diff.html pylint.txt |
| 61 | + set -xv;curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py |
| 62 | + python3.8 get-pip.py |
| 63 | + python3.8 -m pip install 'virtualenv<20.22' 'tox>=4.5.1' tox-gh-actions |
| 64 | +
|
| 65 | + - name: Run tox4 with Python 3.8(to support optional-dependencies from pyproject.toml) for Python3.6 |
| 66 | + if: ${{ matrix.python-version == 3.6 }} |
| 67 | + run: tox --workdir .github/workflows/.tox --recreate -e py36-lint |
| 68 | + |
| 69 | + - name: Generate combined test-coverage with Python 2.7 and 3.8 for Upload |
| 70 | + if: ${{ matrix.python-version == 2.7 }} |
| 71 | + run: tox --workdir .github/workflows/.tox --recreate -e py38-covcombine |
42 | 72 |
|
43 | | - - uses: actions/upload-artifact@v3 |
| 73 | + - name: Upload coverage reports to Codecov |
| 74 | + if: ${{ matrix.python-version == 2.7 }} |
| 75 | + uses: codecov/codecov-action@v3 |
44 | 76 | with: |
45 | | - name: Coverage and pylint reports |
46 | | - path: | |
47 | | - coverage-diff.html |
48 | | - pylint-diff.html |
49 | | - htmlcov |
50 | | - htmlcov-tests |
| 77 | + directory: .github/workflows/.tox/py38-covcombine/log |
| 78 | + env_vars: OS,PYTHON |
| 79 | + fail_ci_if_error: true |
| 80 | + flags: unittest |
| 81 | + name: py27-py38-combined |
| 82 | + verbose: true |
0 commit comments