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

Update CI workflows to use pytest #120

Merged
merged 15 commits into from
Jun 9, 2021
30 changes: 0 additions & 30 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

57 changes: 5 additions & 52 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,7 @@ jobs:
test:
runs-on: ubuntu-latest
env:
DJANGO_SETTINGS_MODULE: 'backend.settings.test'
REDIS_PORT: 6379
REDIS_CONFIG_DB: 1
REDIS_CACHE_DB: 2
REDIS_HOST: localhost
SQL_PORT: 5432
SQL_USER: ractf
SQL_HOST: localhost
SQL_DATABASE: ractf
SQL_PASSWORD: postgres
services:
postgres:
image: postgres:12-alpine
env:
POSTGRES_PASSWORD: postgres
POSTGRES_EXTENSIONS: citext
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: ractf
POSTGRES_USER: ractf
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:5
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
DJANGO_SETTINGS_MODULE: 'backend.settings.lint'

steps:
- name: Checkout repository
Expand All @@ -64,7 +30,7 @@ jobs:

- name: Install Poetry
run: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

- name: Disable Virtualenvs
run: $HOME/.poetry/bin/poetry config virtualenvs.create false

Expand All @@ -73,31 +39,18 @@ jobs:
env:
PIP_CACHE_DIR: ~/.pip

- name: Run Migrations
run: ./manage.py migrate
working-directory: ./src

- name: Run Tests
run: coverage run --source='.' ./manage.py test
working-directory: ./src

- name: Output Coverage Report
run: coverage report || true
working-directory: ./src

- name: Save Coverage XML
run: coverage xml || true
working-directory: ./src
run: make coverage

- name: Upload to CodeCov
uses: codecov/codecov-action@v1
with:
files: ./src/coverage.xml
files: ./coverage.xml
fail_ci_if_error: true
verbose: true

- name: Publish Coverage XML
uses: actions/upload-artifact@v2
with:
name: coverage.xml
path: ./src/coverage.xml
path: ./coverage.xml
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
test:
export DJANGO_SETTINGS_MODULE='backend.settings.lint' && \
cd src && \
BETTER_EXCEPTIONS=1 \
python manage.py migrate && \
pytest --testmon || \
.EXPORT_ALL_VARIABLES:
BETTER_EXCEPTIONS=1
DJANGO_SETTINGS_MODULE=backend.settings.lint

migrate:
python src/manage.py migrate

test: migrate
pytest --testmon src || \
if [ $$? = 5 ]; \
then exit 0; \
else exit $$?; \
fi

coverage:
export DJANGO_SETTINGS_MODULE='backend.settings.lint' && \
cd src && \
BETTER_EXCEPTIONS=1 \
python manage.py migrate && \
pytest --cov=. --cov-report=xml && \
coverage: migrate
pytest --cov=. --cov-report=xml src && \
coverage html && \
xdg-open htmlcov/index.html
which xdg-open && \
xdg-open htmlcov/index.html || true

format:
isort src && \
Expand Down
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ ignore::django.utils.deprecation.RemovedInDjango40Warning
ignore::django.utils.deprecation.RemovedInDjango41Warning
"""

[tool.coverage.run]
source = ["src"]
branch = true
omit = [
"*/venv/*",
"backend/asgi.py",
"backend/wsgi.py",
"backend/exception_handler.py",
"manage.py",
"sockets/routing.py",
"backend/settings/*",
"ractf/management/*",
"gunicorn_config.py",
"*/migrations/*.py"
]

[tool.coverage.report]
fail_under = 80
show_missing = true
skip_covered = true
exclude_lines = [
"pragma: no cover",
"raise NotImplementedError",
"pass"
]

[tool.black]
exclude = 'migrations'
line_length = 200
Expand Down
23 changes: 0 additions & 23 deletions src/.coveragerc

This file was deleted.