diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 50b31388..00000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: "Code scanning" - -on: - push: - pull_request: - schedule: - - cron: '0 2 * * 4' - -jobs: - CodeQL-Build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 2 - - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: python - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3c64556a..e49e74c0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 @@ -73,26 +39,13 @@ 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 @@ -100,4 +53,4 @@ jobs: uses: actions/upload-artifact@v2 with: name: coverage.xml - path: ./src/coverage.xml + path: ./coverage.xml diff --git a/Makefile b/Makefile index f5dbaab6..23d7c66b 100644 --- a/Makefile +++ b/Makefile @@ -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 && \ diff --git a/pyproject.toml b/pyproject.toml index c94d478b..b1daba05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/src/.coveragerc b/src/.coveragerc deleted file mode 100644 index f3494f79..00000000 --- a/src/.coveragerc +++ /dev/null @@ -1,23 +0,0 @@ -[run] -source = . -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 - -[report] -fail_under = 80 -show_missing = True -skip_covered = True -exclude_lines = - pragma: no cover - raise NotImplementedError - pass