Skip to content

CI: Improve unit tests to test the bugtool's main() as well #199

CI: Improve unit tests to test the bugtool's main() as well

CI: Improve unit tests to test the bugtool's main() as well #199

Workflow file for this run

#--------------------------------------------------------------------------------------
# This GitHub Actions workflow can be run locally using https://github.com/nektos/act
#
# act normally uses docker, but it can also be run using podman on Fedora 37:
# dnf install act-cli podman
# podman system service -t 0 &
# act --bind --container-daemon-socket $XDG_RUNTIME_DIR/podman/podman.sock -W .github/workflows/main.yml
#--------------------------------------------------------------------------------------
name: "GitHub CI"
# The GitHub events that trigger this workflow:
# Checks can be skipped by adding "skip-checks: true" to a commit message,
# or requested by adding "request-checks: true" if disabled by default for pushes:
# 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
on: [push, pull_request]
# Docs: https://github.com/marketplace/actions/commit-status-updater#workflow-permissions
# and more info on https://github.com/actions/first-interaction/issues/10
# Allow actions in PRs from other repos to create a comment and update status:
permissions:
pull-requests: write # creating a comment
statuses: write # # updating commit status
# Cancel a currently running workflow from the same PR, branch or tag
# when a new workflow is triggered:
# https://stackoverflow.com/questions/66335225/how-to-cancel-previous-runs-in-the-pr-when-you-push-new-commitsupdate-the-curre
concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
env:
DEBIAN_FRONTEND: noninteractive
# No warnings for pip and pytest themselves; pytest enables warnings in conftest.py
PYTHONWARNINGS: ignore
# Development Mode for stronger checks: https://docs.python.org/3/library/devmode.html
PYTHONDEVMODE: yes
jobs:
container-tests:
name: "Python2: Container tests"
runs-on: ubuntu-22.04
# https://github.com/Docker-Hub-frolvlad/docker-alpine-python2
container: frolvlad/alpine-python2
steps:
- uses: actions/checkout@v3
- name: Install test tools
run: apk add --no-cache libxml2-utils bash
- name: Install python requirements
run: pip install -r requirements.txt
- name: Test sar file collection, extended by XSI-1385 with plain-text SARs
run: bash -x tests/integration/sar-file-collection.test.sh
- name: Test creating a tarball for /etc/systemd
run: bash -x tests/integration/xenserver-config-systemd.sh
python2-tests:
name: "Python2: PyLint and Pytest"
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
#: Install Python 2.7 from Ubuntu 20.04 using apt-get install
sudo apt-get update && sudo apt-get install -y python2
curl -sSL https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python2 get-pip.py
if [ -f requirements.txt ]; then pip2 install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip2 install -r requirements-dev.txt; fi
pip2 install pylint==1.9.4
- name: Run pylint-1.9.4 for pylint --py3k linting (configured in .pylintrc)
run: python2 -m pylint xen-bugtool
- name: Run python2 -m pytest to execute all unit and integration tests
run: >
python2 -m pytest -v -rA
--cov xen-bugtool
--cov tests/
--junitxml=.git/pytest27.xml
--cov-report term-missing
--cov-report html:.git/coverage27.html
--cov-report xml:.git/coverage27.xml
- name: Upload coverage reports to Codecov for the Python 2.7 tests
if: ${{ github.actor != 'nektos/act' }}
uses: codecov/codecov-action@v3
env:
PYTHON: python2.7
with:
directory: .git
files: coverage27.xml
flags: python2.7
env_vars: OS,PYTHON
fail_ci_if_error: true
name: coverage27
verbose: true
- name: Add Pytest 2.7 coverage comment (if write permission is available)
if: ${{ ! github.event.pull_request.head.repo.fork }}
uses: MishaKav/pytest-coverage-comment@main
continue-on-error: true
with:
junitxml-path: .git/pytest27.xml
pytest-xml-coverage-path: .git/coverage27.xml
unique-id-for-comment: pytest-coverage-python27
title: Pytest Code coverage comment for Python 2.7
pre-commit:
name: "Python3: Pre-Commit Suite"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # For diff-cover to get the changed lines: origin/master..HEAD
# https://www.python4data.science/en/latest/productive/git/advanced/hooks/ci.html
- uses: actions/setup-python@v4
id: python
with:
python-version: '3.10'
cache: 'pip'
- run: pip install -r requirements-dev.txt
name: Install the pytest dependencies for running the pytest suite using Python3
- uses: actions/cache@v3
name: Setup cache for running pre-commit fast
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/[email protected]
name: Run pre-commit checks
env:
# Skip the no-commit-to-branch check inside of GitHub CI (for CI on merge to master)
SKIP: no-commit-to-branch
- name: Upload coverage reports to Codecov
if: ${{ github.actor != 'nektos/act' }}
uses: codecov/codecov-action@v3
with:
directory: .git
env_vars: OS,PYTHON
fail_ci_if_error: true
flags: >
unittest,
${{ format('python{0}', steps.python.outputs.python-version ) }}
name: coverage
verbose: true
- name: Add Pytest coverage comment (if write permission is available)
if: ${{ ! github.event.pull_request.head.repo.fork }}
uses: MishaKav/pytest-coverage-comment@main
continue-on-error: true
with:
junitxml-path: .git/pytest.xml
pytest-xml-coverage-path: .git/coverage.xml
unique-id-for-comment: pre-commit-coverage
title: >
Python3 coverage comment from
https://github.com/marketplace/actions/pytest-coverage-comment