Skip to content

Commit 8a6b983

Browse files
committed
CI: use sudo, assume docker present, use diff-{quality,cover}
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 <[email protected]>
1 parent 9206d28 commit 8a6b983

File tree

8 files changed

+62
-241
lines changed

8 files changed

+62
-241
lines changed

.coveragerc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[run]
2+
branch = true
3+
source_pkgs =
4+
oz
5+
6+
[paths]
7+
# this mapping is for the containers; the source tree is in /oz in the containers
8+
source =
9+
oz/
10+
/oz/oz

.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 200

.github/workflows/ci.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ jobs:
1111
uses: actions/checkout@v4
1212
with:
1313
fetch-depth: 0
14-
- name: Install make and docker
15-
run: apt-get install make docker docker.io
14+
- name: Install required packages
15+
run: sudo apt-get install make flake8 pylint
16+
# it's not in Ubuntu 22.04, was added in 23.04
17+
- name: Install diff-cover from pip
18+
run: pip install diff-cover
1619
- name: Run the tests
17-
run: make container-unittests-fedora
20+
run: sudo make container-unittests-fedora
21+
- name: Run diff-cover
22+
run: diff-cover coverage.xml --compare-branch=origin/$GITHUB_BASE_REF --fail-under=90
23+
- name: Run diff-quality (pylint)
24+
# we want to run this regardless of whether previous lint steps failed
25+
if: success() || failure()
26+
run: diff-quality --compare-branch=origin/$GITHUB_BASE_REF --violations=pylint --fail-under=90
27+
- name: Run diff-quality (flake8)
28+
# we want to run this regardless of whether previous lint steps failed
29+
if: success() || failure()
30+
run: diff-quality --compare-branch=origin/$GITHUB_BASE_REF --violations=flake8 --fail-under=90
1831
unittests-el7:
1932
runs-on: ubuntu-latest
2033
steps:
2134
- name: Checkout the repo
2235
uses: actions/checkout@v4
2336
with:
2437
fetch-depth: 0
25-
- name: Install make and docker
26-
run: apt-get install make docker
38+
- name: Install make
39+
run: sudo apt-get install make
2740
- name: Run the tests
28-
run: make container-unittests-el7
29-
lint:
30-
runs-on: ubuntu-latest
31-
steps:
32-
- name: Checkout the repo
33-
uses: actions/checkout@v4
34-
with:
35-
fetch-depth: 0
36-
- name: Install make, pylint and flake8
37-
run: apt-get install make pylint flake8
38-
- name: Run pylint
39-
run: make pylint
40-
- name: Run flake8
41-
run: make flake8
41+
run: sudo make container-unittests-el7

.pylintrc

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[MESSAGES CONTROL]
2+
disable=C0325,C0103
3+
4+
[REPORTS]
5+
reports=yes
6+
7+
[TYPECHECK]
8+
9+
[FORMAT]
10+
max-line-length=200
11+
max-module-lines=2000
12+
13+
[VARIABLES]
14+
dummy-variables-rgx=.*_unused$
15+
16+
[BASIC]
17+
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9_]+))$
18+
19+
[DESIGN]
20+
max-args=20
21+
max-locals=30
22+
max-branches=30
23+
max-statements=100
24+
max-attributes=30
25+
min-public-methods=0

Containerfile.tests.el7

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ COPY ./ /oz
1212
# the XML generation tests are inherently unreliable before Python 3.8,
1313
# as there was no consistent ordering of XML element attributes. See
1414
# https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring
15-
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
15+
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
1616
CMD /usr/local/bin/runtests.sh

Containerfile.tests.fedora

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
FROM quay.io/fedora/fedora:latest
55
RUN set -exo pipefail \
66
&& dnf install -y --setopt install_weak_deps=false --nodocs \
7-
python3-requests python3-cryptography python3-setuptools python3-libvirt python3-lxml python3-libguestfs python3-pytest python3-monotonic \
7+
python3-requests python3-cryptography python3-setuptools python3-libvirt python3-lxml python3-libguestfs python3-pytest python3-coverage python3-monotonic \
88
libvirt-daemon libvirt-daemon-kvm libvirt-daemon-qemu libvirt-daemon-config-network systemd \
99
&& dnf clean all \
1010
&& rm -rf /var/cache/* /var/log/dnf*
1111

1212
COPY ./ /oz
13-
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
13+
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
1414
CMD /usr/local/bin/runtests.sh

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ container-unittests-fedora:
5050
docker rm -f oz-tests-fedora
5151
docker build -f Containerfile.tests.fedora -t oz-tests-fedora-image .
5252
docker run --name oz-tests-fedora oz-tests-fedora-image
53+
docker cp oz-tests-fedora:/oz/coverage.xml .
5354

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

6667
pylint:
67-
pylint --rcfile=pylint.conf oz oz-install oz-customize oz-cleanup-cache oz-generate-icicle
68+
pylint oz oz-install oz-customize oz-cleanup-cache oz-generate-icicle
6869

6970
flake8:
70-
flake8 --ignore=E501 oz
71+
flake8 oz oz-install oz-customize oz-cleanup-cache oz-generate-icicle
7172

7273
container-clean:
7374
docker rm -f oz-tests-fedora

pylint.conf

-217
This file was deleted.

0 commit comments

Comments
 (0)