Skip to content

Commit c8cc4b5

Browse files
committed
ci: Add python unit tests
Signed-off-by: Sergei Petrosian <[email protected]>
1 parent 4ab46ad commit c8cc4b5

File tree

5 files changed

+173
-2
lines changed

5 files changed

+173
-2
lines changed

.github/workflows/codeql.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: CodeQL
3+
on: # yamllint disable-line rule:truthy
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
merge_group:
9+
branches:
10+
- main
11+
types:
12+
- checks_requested
13+
schedule:
14+
- cron: 4 3 * * 2
15+
jobs:
16+
analyze:
17+
name: Analyze
18+
runs-on: ubuntu-latest
19+
permissions:
20+
actions: read
21+
contents: read
22+
security-events: write
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
language: [python]
27+
steps:
28+
- name: Update pip, git
29+
run: |
30+
set -euxo pipefail
31+
sudo apt update
32+
sudo apt install -y git
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
36+
- name: Initialize CodeQL
37+
uses: github/codeql-action/init@v3
38+
with:
39+
languages: ${{ matrix.language }}
40+
queries: +security-and-quality
41+
42+
- name: Autobuild
43+
uses: github/codeql-action/autobuild@v3
44+
45+
- name: Perform CodeQL Analysis
46+
uses: github/codeql-action/analyze@v3
47+
with:
48+
category: "/language:${{ matrix.language }}"
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
# yamllint disable rule:line-length
3+
name: Python Unit Tests
4+
on: # yamllint disable-line rule:truthy
5+
pull_request:
6+
merge_group:
7+
branches:
8+
- main
9+
types:
10+
- checks_requested
11+
push:
12+
branches:
13+
- main
14+
workflow_dispatch:
15+
permissions:
16+
contents: read
17+
jobs:
18+
python:
19+
strategy:
20+
matrix:
21+
pyver_os:
22+
- ver: "2.7"
23+
os: ubuntu-20.04
24+
- ver: "3.6"
25+
os: ubuntu-20.04
26+
- ver: "3.8"
27+
os: ubuntu-latest
28+
- ver: "3.9"
29+
os: ubuntu-latest
30+
- ver: "3.10"
31+
os: ubuntu-latest
32+
- ver: "3.11"
33+
os: ubuntu-latest
34+
runs-on: ${{ matrix.pyver_os.os }}
35+
steps:
36+
- name: Update git
37+
run: |
38+
set -euxo pipefail
39+
sudo apt update
40+
sudo apt install -y git
41+
42+
- name: checkout PR
43+
uses: actions/checkout@v4
44+
45+
- name: Set up Python 2.7
46+
if: ${{ matrix.pyver_os.ver == '2.7' }}
47+
run: |
48+
set -euxo pipefail
49+
sudo apt install -y python2.7
50+
51+
- name: Set up Python 3
52+
if: ${{ matrix.pyver_os.ver != '2.7' }}
53+
uses: actions/setup-python@v5
54+
with:
55+
python-version: ${{ matrix.pyver_os.ver }}
56+
57+
- name: Install platform dependencies, python, tox, tox-lsr
58+
run: |
59+
set -euxo pipefail
60+
python -m pip install --upgrade pip
61+
if [ "${{ matrix.pyver_os.ver }}" = 2.7 ]; then
62+
# newer virtualenv cannot create python2 venvs
63+
# newer tox requires newer virtualenv
64+
tox='tox<4.15'
65+
virtualenv='virtualenv<20.22.0'
66+
else
67+
tox=tox
68+
virtualenv=virtualenv
69+
fi
70+
pip install "$tox" "$virtualenv" "git+https://github.com/linux-system-roles/[email protected]"
71+
# If you have additional OS dependency packages e.g. libcairo2-dev
72+
# then put them in .github/config/ubuntu-requirements.txt, one
73+
# package per line.
74+
if [ -f .github/config/ubuntu-requirements.txt ]; then
75+
sudo apt-get install -y $(cat .github/config/ubuntu-requirements.txt)
76+
fi
77+
78+
- name: Run unit tests
79+
run: |
80+
set -euxo pipefail
81+
toxpyver=$(echo "${{ matrix.pyver_os.ver }}" | tr -d .)
82+
toxenvs="py${toxpyver}"
83+
# NOTE: The use of flake8, pylint, black with specific
84+
# python envs is arbitrary and must be changed in tox-lsr
85+
case "$toxpyver" in
86+
310) toxenvs="${toxenvs},coveralls,flake8,pylint,black" ;;
87+
*) toxenvs="${toxenvs},coveralls" ;;
88+
esac
89+
TOXENV="$toxenvs" lsr_ci_runtox
90+
91+
- name: Upload coverage reports to Codecov
92+
uses: codecov/codecov-action@v4

.github/workflows/tft.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
${{ matrix.platform }}-${{ matrix.ansible_version }}_$DATETIME/artifacts"
124124
ARTIFACTS_TARGET_DIR=/srv/pub/alt/linuxsystemroles/logs
125125
ARTIFACTS_DIR=$ARTIFACTS_TARGET_DIR/$ARTIFACTS_DIR_NAME
126-
ARTIFACTS_URL=https://dl.fedoraproject.org/pub/alt/linuxsystemroles/logs/$ARTIFACTS_DIR_NAME
126+
ARTIFACTS_URL=https://dl.fedoraproject.org/pub/alt/linuxsystemroles/logs$ARTIFACTS_DIR_NAME
127127
echo "DATETIME=$DATETIME" >> $GITHUB_OUTPUT
128128
echo "ARTIFACTS_DIR=$ARTIFACTS_DIR" >> $GITHUB_OUTPUT
129129
echo "ARTIFACTS_URL=$ARTIFACTS_URL" >> $GITHUB_OUTPUT

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,4 @@ See README-ostree.md
455455
MIT
456456

457457
Based on [Ansible-sudoers](https://github.com/ahuffman/ansible-sudoers).
458-
[![ansible-lint.yml](https://github.com/linux-system-roles/sudo/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/ansible-lint.yml) [![ansible-test.yml](https://github.com/linux-system-roles/sudo/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/ansible-test.yml) [![markdownlint.yml](https://github.com/linux-system-roles/sudo/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/markdownlint.yml) [![shellcheck.yml](https://github.com/linux-system-roles/sudo/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/shellcheck.yml) [![tft.yml](https://github.com/linux-system-roles/sudo/actions/workflows/tft.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/tft.yml) [![tft_citest_bad.yml](https://github.com/linux-system-roles/sudo/actions/workflows/tft_citest_bad.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/tft_citest_bad.yml) [![woke.yml](https://github.com/linux-system-roles/sudo/actions/workflows/woke.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/woke.yml)
458+
[![ansible-lint.yml](https://github.com/linux-system-roles/sudo/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/ansible-lint.yml) [![ansible-test.yml](https://github.com/linux-system-roles/sudo/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/ansible-test.yml) [![codeql.yml](https://github.com/linux-system-roles/sudo/actions/workflows/codeql.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/codeql.yml) [![markdownlint.yml](https://github.com/linux-system-roles/sudo/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/markdownlint.yml) [![python-unit-test.yml](https://github.com/linux-system-roles/sudo/actions/workflows/python-unit-test.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/python-unit-test.yml) [![shellcheck.yml](https://github.com/linux-system-roles/sudo/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/shellcheck.yml) [![tft.yml](https://github.com/linux-system-roles/sudo/actions/workflows/tft.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/tft.yml) [![tft_citest_bad.yml](https://github.com/linux-system-roles/sudo/actions/workflows/tft_citest_bad.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/tft_citest_bad.yml) [![woke.yml](https://github.com/linux-system-roles/sudo/actions/workflows/woke.yml/badge.svg)](https://github.com/linux-system-roles/sudo/actions/workflows/woke.yml)

contributing.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,34 @@ are likely to be suitable for new contributors!
1919

2020
**Code** is managed on [Github](https://github.com/linux-system-roles/sudo), using
2121
[Pull Requests](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests).
22+
23+
## Python Code
24+
25+
The Python code needs to be **compatible with the Python versions supported by
26+
the role platform**.
27+
28+
For example, see [meta](https://github.com/linux-system-roles/sudo/blob/main/meta/main.yml)
29+
for the platforms supported by the role.
30+
31+
If the role provides Ansible modules (code in `library/` or `module_utils/`) -
32+
these run on the *managed* node, and typically[1] use the default system python:
33+
34+
* EL6 - python 2.6
35+
* EL7 - python 2.7 or python 3.6 in some cases
36+
* EL8 - python 3.6
37+
* EL9 - python 3.9
38+
39+
If the role provides some other sort of Ansible plugin such as a filter, test,
40+
etc. - these run on the *control* node and typically use whatever version of
41+
python that Ansible uses, which in many cases is *not* the system python, and
42+
may be a modularity release such as python311.
43+
44+
In general, it is a good idea to ensure the role python code works on all
45+
versions of python supported by `tox-lsr` from py36 on, and on py27 if the role
46+
supports EL7, and on py26 if the role supports EL6.[1]
47+
48+
[1] Advanced users may set
49+
[ansible_python_interpreter](https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#term-ansible_python_interpreter)
50+
to use a non-system python on the managed node, so it is a good idea to ensure
51+
your code has broad python version compatibility, and do not assume your code
52+
will only ever be run with the default system python.

0 commit comments

Comments
 (0)