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

Set up test configs to run tests in a container #46

Merged
merged 1 commit into from
Mar 25, 2024
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
14 changes: 4 additions & 10 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ jobs:
**/*.py
- name: Prepare python env
if: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
python -m venv env
source env/bin/activate
pip install -U pip
pip install -r test-requirements.txt
run: pip3 install -r requirements.devel.txt
- name: Run unit tests (pytest)
if: ${{ steps.changed-files.outputs.all_changed_files }}
run: bash -o pipefail -c 'source
env/bin/activate && pip3 install -r requirements.txt &&
pytest -vv --cov-report term-missing:skip-covered
--cov-report xml:/tmp/coverage.xml --junitxml=/tmp/pytest.xml --cov=alma_tests_cacher
tests/ | tee /tmp/pytest-coverage.txt'
run: pytest -v --cov
--cov-report xml:/tmp/coverage.xml --junitxml=/tmp/pytest.xml
--cov-report term-missing:skip-covered | tee /tmp/pytest-coverage.txt
- name: Pytest coverage comment
if: ${{ steps.changed-files.outputs.all_changed_files }}
uses: MishaKav/pytest-coverage-comment@main
Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/syntax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,15 @@ jobs:
**/*.py
- name: Prepare python env
if: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
python -m venv env
source env/bin/activate
pip install -U pip
pip install -r test-requirements.txt
pip install isort[colors] colorama black pylint
run: pip3 install -r requirements.devel.txt
- name: Run pylint
id: pylint
if: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
delimiter='$(openssl rand -hex 8)'
echo 'report<<$(delimiter)' >> $GITHUB_OUTPUT
source env/bin/activate
delimiter=$(openssl rand -hex 8)
echo "report<<$delimiter" >> $GITHUB_OUTPUT
pylint ${{ steps.changed-files.outputs.all_changed_files }} --exit-zero >> $GITHUB_OUTPUT
echo '$(delimiter)' >> $GITHUB_OUTPUT
echo $delimiter >> $GITHUB_OUTPUT
- name: Post pylint output
uses: mshick/add-pr-comment@v2
if: ${{ steps.changed-files.outputs.all_changed_files }}
Expand All @@ -50,7 +44,7 @@ jobs:
message-id: pylint-report
- name: Run black
if: ${{ steps.changed-files.outputs.all_changed_files }}
run: env/bin/black ${{ steps.changed-files.outputs.all_changed_files }} --check --diff --color
run: black ${{ steps.changed-files.outputs.all_changed_files }} --check --diff --color
- name: Run isort
if: ${{ steps.changed-files.outputs.all_changed_files }}
run: env/bin/isort ${{ steps.changed-files.outputs.all_changed_files }} --diff --color --check-only
run: isort ${{ steps.changed-files.outputs.all_changed_files }} --diff --color --check-only
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
32 changes: 23 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
FROM almalinux:9

RUN mkdir -p /code && \
dnf update -y && \
dnf install git -y && \
dnf clean all
RUN curl https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -o wait_for_it.sh && chmod +x wait_for_it.sh
COPY ./requirements.txt /code/requirements.txt
RUN cd /code && python3 -m venv env && source env/bin/activate && \
pip3 install --upgrade pip && pip3 install -r /code/requirements.txt --no-cache-dir
RUN <<EOT
set -ex
umask 0077
mkdir -p ~/.ssh
printf 'Host github.com\n StrictHostKeyChecking accept-new\n' >> ~/.ssh/config
EOT

RUN <<EOT
set -ex
dnf upgrade -y
dnf install -y git
dnf clean all
EOT

WORKDIR /code
CMD ["/bin/bash", "-c", "source env/bin/activate && pip3 install --upgrade pip && pip3 install -r requirements.txt --no-cache-dir && python alma_tests_cacher.py"]
COPY requirements.* .
RUN <<EOT
set -ex
python3 -m ensurepip
pip3 install -r requirements.devel.txt
rm requirements.*
EOT

ADD --chmod=755 https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /
1 change: 1 addition & 0 deletions alma_tests_cacher/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PackageTestRepository(BaseModel):


class TestRepository(BaseModel):
__test__ = False
id: Union[int, str]
name: str
url: str
Expand Down
14 changes: 2 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
version: "3.9"
services:
cacher:
image: alma-tests-cacher:latest
build:
context: .
dockerfile: Dockerfile
restart: on-failure
command: "python3 alma_tests_cacher.py"
volumes:
- "./alma_tests_cacher:/code/alma_tests_cacher"
- "./alma_tests_cacher.py:/code/alma_tests_cacher.py"
- "./requirements.txt:/code/requirements.txt"
- "./vars.yaml:/code/vars.yaml"
command: "bash -c '/wait_for_it.sh web_server:8000 &&
source env/bin/activate &&
pip3 install --upgrade pip &&
pip3 install -r /code/requirements.txt --no-cache-dir &&
python alma_tests_cacher.py'"
- ".:/code"
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ split_on_trailing_comma = true
[tool.black]
line-length = 79
skip-string-normalization = true
# see https://black.readthedocs.io/en/stable/the_black_code_style/future_style.html#preview-style
preview = true
enable-unstable-feature = ["hug_parens_with_braces_and_square_brackets"]

[tool.pylint]
max-line-length = 80

[tool.coverage.run]
source = ['.']

[tool.coverage.report]
skip_empty = true
include = ['alma_tests_cacher/*']

[tool.pytest.ini_options]
pythonpath = '.'
testpaths = ['tests']
9 changes: 9 additions & 0 deletions requirements.devel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-r requirements.txt

pytest==8.1.1
pytest-cov==4.1.0
anyio==4.3.0

isort[colors]==5.13.2
black==24.3.0
pylint==3.1.0
5 changes: 0 additions & 5 deletions test-requirements.txt

This file was deleted.

Loading