Skip to content

Commit 4a6ce7b

Browse files
committed
Only run pytest in the Container, run ruff separately
Pulling devel dependencies like ruff (and eventually pyright) into the prod container isn't the best setup - instead make test.sh able to run only some tests and: * Run the full tools/test.sh in a separate "Run Tests" CI action * Only run ./tools/test.sh --pytest when building the Container
1 parent 9d6a4dd commit 4a6ce7b

File tree

5 files changed

+98
-51
lines changed

5 files changed

+98
-51
lines changed

.github/workflows/build-container.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/run-tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
run-tests-in-container:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
submodules: true
20+
21+
- name: Build container image with podman
22+
run: |
23+
podman build \
24+
-f Containerfile \
25+
-t flatpak-indexer:latest \
26+
--build-arg=FLATPAK_INDEXER_UPDATE_TEST_DATA=1 \
27+
.
28+
29+
source-code-checks:
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
36+
- name: Set up Python 3.12
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: '3.12'
40+
41+
- name: Install dependencies
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install python3.12-dev gcc libkrb5-dev
45+
pip install uv
46+
uv sync
47+
48+
- name: Check source code
49+
run: |
50+
uv run tools/test.sh --ruff-format --ruff-check

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ COPY --from=tar-diff-builder /opt/app-root/bin/tar-diff /opt/app-root/bin/
3737
COPY --from=builder /opt/app-root /opt/app-root
3838

3939
# Run tests
40-
RUN $APP_ROOT/src/tools/test.sh
40+
RUN $APP_ROOT/src/tools/test.sh --pytest
4141

4242
# Set the default command for the resulting image
4343
CMD /usr/libexec/s2i/run

pyproject.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies = [
1919
"requests",
2020
"PyYAML",
2121
"version_utils>=0.3.2",
22-
# Dev requirements - listed in main dependencies to make the image
22+
# Test requirements - listed in main dependencies to make the image
2323
# self-contained for testing.
2424
# 2.22.0 contains an accidental incompatibility with python < 3.11,
2525
# fixed in git.
@@ -29,25 +29,16 @@ dependencies = [
2929
"pytest",
3030
"pytest-cov",
3131
"pytest-socket",
32-
"ruff",
3332
"responses",
3433
"www-authenticate",
3534
]
3635

3736
[project.scripts]
3837
flatpak-indexer = "flatpak_indexer.cli:cli"
3938

40-
[project.optional-dependencies]
41-
# Alternative: install only dev dependencies separately
39+
[dependency-groups]
4240
dev = [
43-
"fakeredis!=2.22.0",
44-
"graphql-core",
45-
"iso8601",
46-
"pytest",
47-
"pytest-cov",
48-
"pytest-socket",
49-
"responses",
50-
"www-authenticate",
41+
"ruff",
5142
]
5243

5344
[tool.setuptools.packages.find]

tools/test.sh

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
11
#!/bin/bash
22

3-
set +e -x
4-
53
# These are set to build-time specific location when building the Red Hat-internal
64
# image; unset them to avoid breaking things at runtime.
75
unset REQUESTS_CA_BUNDLE
86
unset GIT_SSL_CAINFO
97

10-
pytest --cov-fail-under=100 "$@"
8+
modules=()
9+
pytest_args=()
10+
all=true
11+
failed=""
12+
13+
for arg in "$@" ; do
14+
case $arg in
15+
--pytest|--ruff-check|--ruff-format|--pyright)
16+
modules+=("${arg#--}")
17+
all=false
18+
;;
19+
*)
20+
modules+=(pytest)
21+
pytest_args+=("$arg")
22+
all=false
23+
;;
24+
esac
25+
done
26+
27+
if $all ; then
28+
modules=(pytest pyright ruff-check ruff-format)
29+
fi
1130

12-
[ $? == 0 ] || failed="$failed pytest"
13-
ruff format --check flatpak_indexer tests tools
14-
[ $? == 0 ] || failed="$failed ruff-format"
15-
ruff check flatpak_indexer tests tools
16-
[ $? == 0 ] || failed="$failed ruff-check"
31+
if [[ "${#pytest_args[@]}" = 0 ]] ; then
32+
pytest_args=(--cov-fail-under=100)
33+
fi
34+
35+
run() {
36+
module=$1
37+
shift
38+
if [[ " ${modules[*]} " =~ " $module " ]] ; then
39+
if [[ -t 1 ]] ; then
40+
echo -e "\e[33m\e[1mRUNNING\e[0m: $*"
41+
else
42+
echo "RUNNING: $*"
43+
fi
44+
"$@"
45+
[[ $? -eq 0 ]] || failed="$failed $module"
46+
fi
47+
}
1748

18-
set -e +x
49+
run pytest pytest "${pytest_args[@]}"
50+
run ruff-format ruff format --check flatpak_indexer tests tools
51+
run ruff-check ruff check flatpak_indexer tests tools
1952

20-
if [ "$failed" != "" ] ; then
53+
if [[ "$failed" != "" ]] ; then
2154
if [[ -t 1 ]] ; then
22-
echo -e "\e[31m\e[1mFAILED:\e[0m$failed"
55+
echo -e "\e[31m\e[1mFAILED\e[0m:$failed"
2356
else
2457
echo -e "FAILED:$failed"
2558
fi

0 commit comments

Comments
 (0)