Skip to content

Commit

Permalink
CI: use sudo, assume docker present, use diff-{quality,cover}
Browse files Browse the repository at this point in the history
Huh. I kinda just assumed we'd be root. Guess not!

Docker is already in the GHA base image, no need to install.

Both linter tools report issues on the current master branch,
which means they will always fail on exit. Using diff-quality
gives us a check we can usefully fail on (as configured in this
PR, it will only fail if the quality of the lines changed in
the PR is less than 9.0).

Similarly we can generate a coverage report and use diff-cover
to fail if coverage of the PR is under 90%.

This also uses a standard configuration file name for the pylint
config (so we don't have to specify it with `--rcfile`), removes
all non-default settings from the pylint config so it's clearer
what we really intend to configure, and moves the flake8 config
to a config file like pylint.

We don't use pyproject.toml for configuration here because GHA's
Ubuntu environment is just not new enough, the tools in it don't
consistently read from pyproject.toml.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
  • Loading branch information
AdamWill committed Jan 29, 2024
1 parent 7d53256 commit 927cc89
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 241 deletions.
10 changes: 10 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[run]
branch = true
source_pkgs =
oz

[paths]
# this mapping is for the containers; the source tree is in /oz in the containers
source =
oz/
/oz/oz
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 200
38 changes: 19 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install make and docker
run: apt-get install make docker docker.io
- name: Install required packages
run: sudo apt-get install make flake8 pylint
# it's not in Ubuntu 22.04, was added in 23.04
- name: Install diff-cover from pip
run: pip install diff-cover
- name: Run the tests
run: make container-unittests-fedora
run: sudo make container-unittests-fedora
- name: Run diff-cover
run: diff-cover coverage.xml --compare-branch=origin/$GITHUB_BASE_REF --fail-under=90
- name: Run diff-quality (pylint)
# we want to run this regardless of whether previous lint steps failed
if: success() || failure()
run: diff-quality --compare-branch=origin/$GITHUB_BASE_REF --violations=pylint --fail-under=90
- name: Run diff-quality (flake8)
# we want to run this regardless of whether previous lint steps failed
if: success() || failure()
run: diff-quality --compare-branch=origin/$GITHUB_BASE_REF --violations=flake8 --fail-under=90
unittests-el7:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install make and docker
run: apt-get install make docker
- name: Install make
run: sudo apt-get install make
- name: Run the tests
run: make container-unittests-el7
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install make, pylint and flake8
run: apt-get install make pylint flake8
- name: Run pylint
run: make pylint
- name: Run flake8
run: make flake8
run: sudo make container-unittests-el7
25 changes: 25 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[MESSAGES CONTROL]
disable=C0325,C0103

[REPORTS]
reports=yes

[TYPECHECK]

[FORMAT]
max-line-length=200
max-module-lines=2000

[VARIABLES]
dummy-variables-rgx=.*_unused$

[BASIC]
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9_]+))$

[DESIGN]
max-args=20
max-locals=30
max-branches=30
max-statements=100
max-attributes=30
min-public-methods=0
2 changes: 1 addition & 1 deletion Containerfile.tests.el7
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ COPY ./ /oz
# the XML generation tests are inherently unreliable before Python 3.8,
# as there was no consistent ordering of XML element attributes. See
# https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring
RUN printf "#!/bin/sh\n/usr/sbin/libvirtd -d\ncd /oz\npy.test -vv -k 'not test_xml_generation and not modify_libvirt_xml_for_serial' tests/" > /usr/local/bin/runtests.sh && chmod ugo+x /usr/local/bin/runtests.sh
RUN printf "#!/bin/sh\n/usr/sbin/libvirtd -d\ncd /oz\npython -m pytest -vv -k 'not test_xml_generation and not modify_libvirt_xml_for_serial' tests/" > /usr/local/bin/runtests.sh && chmod ugo+x /usr/local/bin/runtests.sh
CMD /usr/local/bin/runtests.sh
4 changes: 2 additions & 2 deletions Containerfile.tests.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
FROM quay.io/fedora/fedora:latest
RUN set -exo pipefail \
&& dnf install -y --setopt install_weak_deps=false --nodocs \
python3-requests python3-m2crypto python3-setuptools python3-libvirt python3-lxml python3-libguestfs python3-pytest python3-monotonic \
python3-requests python3-m2crypto python3-setuptools python3-libvirt python3-lxml python3-libguestfs python3-pytest python3-coverage python3-monotonic \
libvirt-daemon libvirt-daemon-kvm libvirt-daemon-qemu libvirt-daemon-config-network systemd \
&& dnf clean all \
&& rm -rf /var/cache/* /var/log/dnf*

COPY ./ /oz
RUN printf "#!/bin/sh\n/usr/sbin/libvirtd -d\ncd /oz\npy.test -vv tests/" > /usr/local/bin/runtests.sh && chmod ugo+x /usr/local/bin/runtests.sh
RUN printf "#!/bin/sh\n/usr/sbin/libvirtd -d\ncd /oz\npython3 -m coverage run -m pytest -vv tests/\ncoverage xml\ncoverage report" > /usr/local/bin/runtests.sh && chmod ugo+x /usr/local/bin/runtests.sh
CMD /usr/local/bin/runtests.sh
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ container-unittests-fedora:
docker rm -f oz-tests-fedora
docker build -f Containerfile.tests.fedora -t oz-tests-fedora-image .
docker run --name oz-tests-fedora oz-tests-fedora-image
docker cp oz-tests-fedora:/oz/coverage.xml .

container-unittests-el7:
docker rm -f oz-tests-el7
Expand All @@ -64,10 +65,10 @@ test-coverage:
xdg-open htmlcov/index.html

pylint:
pylint --rcfile=pylint.conf oz oz-install oz-customize oz-cleanup-cache oz-generate-icicle
pylint oz oz-install oz-customize oz-cleanup-cache oz-generate-icicle

flake8:
flake8 --ignore=E501 oz
flake8 oz oz-install oz-customize oz-cleanup-cache oz-generate-icicle

container-clean:
docker rm -f oz-tests-fedora
Expand Down
217 changes: 0 additions & 217 deletions pylint.conf

This file was deleted.

0 comments on commit 927cc89

Please sign in to comment.