Skip to content

Commit bcd0a7f

Browse files
Setup github ci for pytest tests including static analysis
1 parent 15a1e48 commit bcd0a7f

File tree

2 files changed

+271
-0
lines changed

2 files changed

+271
-0
lines changed

.github/workflows/ci.yml

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
name: CI
2+
on:
3+
push:
4+
#branches: [master]
5+
pull_request:
6+
#branches: [master]
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
jobs:
11+
tox:
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.11", "3.x"]
16+
upstream: ["pypi"]
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
steps:
21+
- name: Detect skipped environments
22+
id: skipenv
23+
env:
24+
UPSTREAM: ${{ matrix.upstream }}
25+
run: |
26+
set -ex
27+
case $UPSTREAM in
28+
upstream)
29+
echo 'skipenv=.*(?<!upstream)$' >> $GITHUB_OUTPUT
30+
;;
31+
*)
32+
echo 'skipenv=.*-upstream$' >> $GITHUB_OUTPUT
33+
;;
34+
esac
35+
- uses: actions/checkout@v3
36+
- uses: actions/setup-python@v4
37+
with:
38+
python-version: ${{ matrix.python-version }}
39+
- name: Install dependencies
40+
run: |
41+
sudo apt-get update
42+
43+
# Install dependencies for python-ldap
44+
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev libssh-dev
45+
46+
python -m pip install --upgrade pip
47+
pip install tox tox-gh
48+
- name: Prepare tox environment and install packages
49+
run: |
50+
tox --skip-env '${{ steps.skipenv.outputs.skipenv }}' --colored=yes --notest
51+
- name: Run tests
52+
run: |
53+
tox --skip-env '${{ steps.skipenv.outputs.skipenv }}' --colored=yes --skip-pkg-install
54+
55+
system:
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
tag:
60+
- fedora-latest
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: read
64+
steps:
65+
- uses: actions/setup-python@v5
66+
with:
67+
python-version: 3.x
68+
69+
- name: Checkout sssd-test-framework repository
70+
uses: actions/checkout@v5
71+
with:
72+
# Fetch the entire history of the repository and tags to determine
73+
# correct framework version, as it is constructed from git describe
74+
repository: sssd/sssd-test-framework
75+
fetch-depth: 0
76+
fetch-tags: true
77+
path: sssd-test-framework
78+
79+
- name: Checkout sudo-tests repository
80+
uses: actions/checkout@v5
81+
with:
82+
repository: RedHat-SP-Security/sudo-tests
83+
path: sudo-tests
84+
85+
- name: Setup containers
86+
uses: SSSD/sssd-ci-containers/actions/setup@master
87+
with:
88+
path: sssd-ci-containers
89+
registry: quay.io/sssd
90+
tag: ${{ matrix.tag }}
91+
override: |
92+
version: "3"
93+
services:
94+
ipa2: !reset null
95+
nfs: !reset null
96+
kdc: !reset null
97+
keycloak: !reset null
98+
99+
- name: Patch the SSH configuration
100+
uses: SSSD/sssd-ci-containers/actions/exec@master
101+
with:
102+
user: root
103+
script: |
104+
#!/bin/bash
105+
test -x /usr/bin/sss_ssh_knownhosts && \
106+
sed -e 's/GlobalKnownHostsFile/#GlobalKnownHostsFile/' \
107+
-e 's/ProxyCommand \/usr\/bin\/sss_ssh_knownhostsproxy -p %p %h/KnownHostsCommand \/usr\/bin\/sss_ssh_knownhosts %H/' \
108+
-i /etc/ssh/ssh_config.d/04-ipa.conf
109+
110+
- name: Install system tests dependencies
111+
shell: bash
112+
working-directory: ./sudo-tests/pytest
113+
run: |
114+
set -ex
115+
116+
sudo apt-get update
117+
118+
# Install dependencies for python-ldap
119+
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev libssh-dev
120+
121+
# Virtualenv
122+
pip3 install virtualenv
123+
python3 -m venv .venv
124+
source .venv/bin/activate
125+
126+
# Install system tests requirements
127+
pip3 install -r ./requirements.txt
128+
129+
# Install yq to parse yaml files
130+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
131+
sudo chmod a+x /usr/local/bin/yq
132+
133+
- name: Install test framework
134+
shell: bash
135+
run: |
136+
set -ex
137+
138+
source ./sudo-tests/pytest/.venv/bin/activate
139+
pip3 install ./sssd-test-framework
140+
141+
- name: Remove ad from mhc.yaml
142+
shell: bash
143+
working-directory: ./sudo-tests/pytest
144+
run: |
145+
yq -i 'del(.domains[0].hosts.[] | select(.role == "ad"))' mhc.yaml
146+
147+
- name: Check polarion metadata
148+
shell: bash
149+
working-directory: ./sudo-tests/pytest
150+
run: |
151+
# Run pytest in collect only mode to quickly catch issues in Polarion metadata.
152+
set -ex -o pipefail
153+
154+
mkdir -p $GITHUB_WORKSPACE/artifacts
155+
source .venv/bin/activate
156+
pytest \
157+
--color=yes \
158+
--mh-config=./mhc.yaml \
159+
--mh-artifacts-dir=$GITHUB_WORKSPACE/artifacts \
160+
--polarion-config=../polarion.yaml \
161+
--output-polarion-testcase=$GITHUB_WORKSPACE/artifacts/testcase.xml \
162+
--collect-only . |& tee $GITHUB_WORKSPACE/pytest-collect.log
163+
164+
- name: Run tests
165+
shell: bash
166+
working-directory: ./sudo-tests/pytest/
167+
run: |
168+
set -ex -o pipefail
169+
170+
mkdir -p $GITHUB_WORKSPACE/artifacts
171+
source .venv/bin/activate
172+
pytest \
173+
--durations=0 \
174+
--color=yes \
175+
--show-capture=no \
176+
--mh-config=./mhc.yaml \
177+
--mh-artifacts-dir=$GITHUB_WORKSPACE/artifacts \
178+
--polarion-config=../polarion.yaml \
179+
--output-polarion-testcase=$GITHUB_WORKSPACE/artifacts/testcase.xml \
180+
--output-polarion-testrun=$GITHUB_WORKSPACE/artifacts/testrun.xml \
181+
-vvv . |& tee $GITHUB_WORKSPACE/pytest.log
182+
183+
- name: Upload artifacts
184+
if: always()
185+
uses: actions/upload-artifact@v4
186+
with:
187+
if-no-files-found: ignore
188+
name: ${{ matrix.tag }}-system
189+
path: |
190+
artifacts
191+
build.log
192+
install.log
193+
pytest.log
194+
pytest-collect.log
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: "Static code analysis"
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
schedule:
8+
# Everyday at midnight
9+
- cron: '0 0 * * *'
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
jobs:
14+
static-code-analysis-tests:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
steps:
19+
- uses: actions/setup-python@v6
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Checkout repository
24+
uses: actions/checkout@v5
25+
with:
26+
repository: RedHat-SP-Security/sudo-tests
27+
path: sudo-tests
28+
29+
- name: Setup virtual environment
30+
working-directory: ./sudo-tests/pytest
31+
run: |
32+
sudo apt-get update
33+
34+
# Install dependencies for python-ldap
35+
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev libssh-dev
36+
37+
pip3 install virtualenv
38+
python3 -m venv .venv
39+
source .venv/bin/activate
40+
pip3 install -r ./requirements.txt
41+
pip3 install flake8 pycodestyle isort mypy black
42+
43+
- name: flake8
44+
if: always()
45+
working-directory: ./sudo-tests/pytest
46+
run: source .venv/bin/activate && flake8 .
47+
48+
- name: pycodestyle
49+
if: always()
50+
working-directory: ./sudo-tests/pytest
51+
run: source .venv/bin/activate && pycodestyle .
52+
53+
- name: isort
54+
if: always()
55+
working-directory: ./sudo-tests/pytest
56+
run: source .venv/bin/activate && isort --check-only .
57+
58+
- name: black
59+
if: always()
60+
working-directory: ./sudo-tests/pytest
61+
run: source .venv/bin/activate && black --check --diff .
62+
63+
- name: mypy
64+
if: always()
65+
working-directory: ./sudo-tests/pytest
66+
run: source .venv/bin/activate && mypy --install-types --non-interactive tests
67+
68+
result:
69+
name: All tests are successful
70+
if: ${{ always() }}
71+
runs-on: ubuntu-latest
72+
needs: [static-code-analysis-tests]
73+
steps:
74+
- name: Fail on failure
75+
if: |
76+
needs.static-code-analysis-tests.result != 'success'
77+
run: exit 1

0 commit comments

Comments
 (0)