Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: python tests with uv & typing #393

Merged
merged 8 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-binary-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod

- name: Build all platforms
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
42 changes: 26 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
jobs:
build:
name: "Build + tests"
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:

Expand All @@ -24,7 +24,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod

- name: Build
run: |
Expand All @@ -38,19 +38,21 @@ jobs:
env:
RICHGO_FORCE_COLOR: 1

- name: "Setup Python"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: 0.5.24
enable-cache: true
cache-dependency-glob: "test/uv.lock"

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pipenv'
python-version-file: "test/.python-version"

- name: "Install python dependencies"
run: |
python -m pip install --upgrade pipenv wheel
pipenv install --deploy
# some tests need root, so we have to install pytest twice
sudo python3 -m pip install --upgrade pipenv wheel
sudo pipenv install --deploy
- name: Install the project
working-directory: ./test
run: uv sync --all-extras --dev

- name: Install functional test dependencies
run: |
Expand All @@ -65,20 +67,28 @@ jobs:
CROWDSEC_TEST_NETWORK: net-test
CROWDSEC_TEST_TIMEOUT: 60
PYTEST_ADDOPTS: --durations=0 -vv --color=yes -m "not (deb or rpm)"
working-directory: ./test
run: |
# everything except for
# - install (requires root, ignored by default)
# - backends (requires root, ignored by default)
# - deb/rpm (on their own workflows)
pipenv run pytest
uv run pytest
# these need root
sudo -E pipenv run pytest ./test/backends
sudo -E pipenv run pytest ./test/install/no_crowdsec
sudo -E $(which uv) run pytest ./tests/backends
sudo -E $(which uv) run pytest ./tests/install/no_crowdsec
# these need a running crowdsec
docker run -d --name crowdsec -e CI_TESTING=true -e DISABLE_ONLINE_API=true -ti crowdsecurity/crowdsec
install -m 0755 /dev/stdin /usr/local/bin/cscli <<'EOT'
#!/bin/sh
docker exec crowdsec cscli "$@"
EOT
sleep 5
sudo -E pipenv run pytest ./test/install/with_crowdsec
sudo -E $(which uv) run pytest ./tests/install/with_crowdsec

- name: Lint
working-directory: ./test
run: |
uv run ruff check
uv run basedpyright

34 changes: 18 additions & 16 deletions .github/workflows/tests_deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
jobs:
build:
name: "Test .deb packages"
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:

Expand All @@ -24,26 +24,28 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version-file: go.mod

- name: "Setup Python"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: 0.5.24
enable-cache: true
cache-dependency-glob: "test/uv.lock"

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pipenv'
python-version-file: "test/.python-version"

- name: "Install python dependencies"
run: |
python -m pip install --upgrade pipenv wheel
pipenv install --deploy
# some tests need root, so we have to install pytest twice
sudo python3 -m pip install --upgrade pipenv wheel
sudo pipenv install --deploy
- name: Install the project
run: uv sync --all-extras --dev
working-directory: ./test

- name: Install functional test dependencies
run: |
sudo apt update
sudo apt install -y build-essential debhelper devscripts fakeroot lintian
sudo apt install -y nftables iptables ipset build-essential debhelper devscripts fakeroot lintian
docker network create net-test

- name: Run functional tests
Expand All @@ -53,7 +55,7 @@ jobs:
CROWDSEC_TEST_NETWORK: net-test
CROWDSEC_TEST_TIMEOUT: 60
PYTEST_ADDOPTS: --durations=0 -vv --color=yes
working-directory: ./test
run: |
sudo apt install -y nftables iptables ipset
pipenv run pytest test/pkg/test_build_deb.py
sudo -E pipenv run pytest -m deb ./test/install/no_crowdsec
uv run pytest ./tests/pkg/test_build_deb.py
sudo -E $(which uv) run pytest -m deb ./tests/install/no_crowdsec
17 changes: 0 additions & 17 deletions Pipfile

This file was deleted.

Loading