Skip to content

Commit

Permalink
github/workflows: run pylint and pytest in a docker container
Browse files Browse the repository at this point in the history
Create a new service for running unit tests based on the api service so
that it includes the kernelci-core dependency.

Signed-off-by: Ricardo Cañuelo <[email protected]>
  • Loading branch information
Ricardo Cañuelo committed Jan 5, 2024
1 parent 93f1b42 commit a2455d6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
38 changes: 29 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,44 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Export environment variables
run: |
echo "SECRET_KEY=b6451545d2e4635148d768f07877aade3ad8e7e160d52962badd7587a4b9a150" > .env
echo "SMTP_HOST=smtp.gmail.com" >> .env
echo "SMTP_PORT=465" >> .env
echo "[email protected]" >> .env
echo "EMAIL_PASSWORD=random" >> .env
- name: Build docker images
run: docker-compose -f test-docker-compose.yaml build

- name: Run pycodestyle
run: |
pycodestyle api/*.py
- name: Run API containers
run: |
docker-compose -f test-docker-compose.yaml up -d unit_test
- name: Run pylint
run: |
pylint api.auth
pylint api.db
pylint api.main
pylint api.models
pylint api.pubsub
pylint api.user_manager
pylint api.user_models
pylint tests/unit_tests
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pylint api.auth
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pylint api.db
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pylint api.main
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pylint api.models
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pylint api.pubsub
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pylint api.user_manager
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pylint api.user_models
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pylint tests/unit_tests
- name: Run pytest
run: |
SECRET_KEY=b6451545d2e4635148d768f07877aade3ad8e7e160d52962badd7587a4b9a150 SMTP_HOST=smtp.gmail.com SMTP_PORT=465 [email protected] EMAIL_PASSWORD=random pytest -vs tests/unit_tests/
docker-compose -f test-docker-compose.yaml exec --no-tty unit_test pytest -vs tests/unit_tests/
- name: Stop docker containers
if: always()
run: |
docker-compose -f test-docker-compose.yaml down
lint:
runs-on: ubuntu-22.04
Expand Down
16 changes: 16 additions & 0 deletions test-docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,19 @@ services:
- '.env'
environment:
- 'KEEP_ALIVE_PERIOD=0'

unit_test:
container_name: 'kernelci-api-unittests'
build:
context: 'docker/api'
args:
- REQUIREMENTS=${REQUIREMENTS:-requirements-dev.txt}
volumes:
- './api:/home/kernelci/api'
- './tests:/home/kernelci/tests'
depends_on:
- api
env_file:
- '.env'
environment:
- 'KEEP_ALIVE_PERIOD=0'

0 comments on commit a2455d6

Please sign in to comment.