Skip to content

Commit 5d26dec

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

File tree

2 files changed

+279
-0
lines changed

2 files changed

+279
-0
lines changed

.github/workflows/ci.yml

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
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:
95+
deploy:
96+
replicas: 0
97+
nfs:
98+
deploy:
99+
replicas: 0
100+
kdc:
101+
deploy:
102+
replicas: 0
103+
keycloak:
104+
deploy:
105+
replicas: 0
106+
107+
- name: Patch the SSH configuration
108+
uses: SSSD/sssd-ci-containers/actions/exec@master
109+
with:
110+
user: root
111+
script: |
112+
#!/bin/bash
113+
test -x /usr/bin/sss_ssh_knownhosts && \
114+
sed -e 's/GlobalKnownHostsFile/#GlobalKnownHostsFile/' \
115+
-e 's/ProxyCommand \/usr\/bin\/sss_ssh_knownhostsproxy -p %p %h/KnownHostsCommand \/usr\/bin\/sss_ssh_knownhosts %H/' \
116+
-i /etc/ssh/ssh_config.d/04-ipa.conf
117+
118+
- name: Install system tests dependencies
119+
shell: bash
120+
working-directory: ./sudo-tests/pytest
121+
run: |
122+
set -ex
123+
124+
sudo apt-get update
125+
126+
# Install dependencies for python-ldap
127+
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev libssh-dev
128+
129+
# Virtualenv
130+
pip3 install virtualenv
131+
python3 -m venv .venv
132+
source .venv/bin/activate
133+
134+
# Install system tests requirements
135+
pip3 install -r ./requirements.txt
136+
137+
# Install yq to parse yaml files
138+
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
139+
sudo chmod a+x /usr/local/bin/yq
140+
141+
- name: Install test framework
142+
shell: bash
143+
run: |
144+
set -ex
145+
146+
source ./sudo-tests/pytest/.venv/bin/activate
147+
pip3 install ./sssd-test-framework
148+
149+
- name: Remove ad from mhc.yaml
150+
shell: bash
151+
working-directory: ./sudo-tests/pytest
152+
run: |
153+
yq -i 'del(.domains[0].hosts.[] | select(.role == "ad"))' mhc.yaml
154+
155+
- name: Check polarion metadata
156+
shell: bash
157+
working-directory: ./sudo-tests/pytest
158+
run: |
159+
# Run pytest in collect only mode to quickly catch issues in Polarion metadata.
160+
set -ex -o pipefail
161+
162+
mkdir -p $GITHUB_WORKSPACE/artifacts
163+
source .venv/bin/activate
164+
pytest \
165+
--color=yes \
166+
--mh-config=./mhc.yaml \
167+
--mh-artifacts-dir=$GITHUB_WORKSPACE/artifacts \
168+
--polarion-config=../polarion.yaml \
169+
--output-polarion-testcase=$GITHUB_WORKSPACE/artifacts/testcase.xml \
170+
--collect-only . |& tee $GITHUB_WORKSPACE/pytest-collect.log
171+
172+
- name: Run tests
173+
shell: bash
174+
working-directory: ./sudo-tests/pytest/
175+
run: |
176+
set -ex -o pipefail
177+
178+
mkdir -p $GITHUB_WORKSPACE/artifacts
179+
source .venv/bin/activate
180+
pytest \
181+
--durations=0 \
182+
--color=yes \
183+
--show-capture=no \
184+
--mh-config=./mhc.yaml \
185+
--mh-artifacts-dir=$GITHUB_WORKSPACE/artifacts \
186+
--polarion-config=../polarion.yaml \
187+
--output-polarion-testcase=$GITHUB_WORKSPACE/artifacts/testcase.xml \
188+
--output-polarion-testrun=$GITHUB_WORKSPACE/artifacts/testrun.xml \
189+
-vvv . |& tee $GITHUB_WORKSPACE/pytest.log
190+
191+
- name: Upload artifacts
192+
if: always()
193+
uses: actions/upload-artifact@v4
194+
with:
195+
if-no-files-found: ignore
196+
name: ${{ matrix.tag }}-system
197+
path: |
198+
artifacts
199+
build.log
200+
install.log
201+
pytest.log
202+
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)