# Setting up Continuous Quality with GitHub and Circle for Python
The following steps walk through how to add
test-coverage analyzers to DeepSource, how to setup test coverage with Circle CI and optionally how to enable branch protection rules with GitHub.
test-coverage analyzers in
To enable analysis on the repository, an analysis configuration should be defined in
.deepsource.toml file in the repository's root. Let's configure for Python with test coverage.
# Version of the DeepSource TOML. Should be 1. version = 1 # Glob pattern of the test files test_patterns = [ "tests/**" ] # List of analyzers # Python analyzer [[analyzers]] name = "python" enabled = true runtime_version = "3.x.x" [analyzers.meta] max_line_length = 90 # Test coverage analyzer [[analyzers]] name = "test-coverage" enabled = true
Now that the configuration is written, create a file
.deepsource.toml with the above contents in the repository's root.
GitHub / Repository root
Refer to specific analyzer's configuration to see other available options.
# Activate DeepSource analysis on the repository
To activate continuous analysis, go to DeepSource dashboard and click
Activate new repo.
Since we've already added the configuration to the repository, select the repository and click
I've already added the config, skip this stepon right bottom and click
Activate analysison the repository overview page.
# Configure Circle CI to run tests and report test coverage
Let's configure Travis CI to run the tests:
version: 2 jobs: build: docker: - image: circleci/python:3.7 steps: - checkout - run: name: Install dependencies command: | sudo pip install -r requirements.txt - run: name: Run tests command: | coverage run test_hello.py - run: name: Report results to DeepSource command: | # Generate coverage report in xml format coverage xml # Install deepsource CLI curl https://deepsource.io/cli | sh # Report coverage artifact to 'test-coverage' analyzer ./bin/deepsource report --analyzer test-coverage --key python --value-file ./coverage.xml
Refer to Circle CI documentation to customize the build.
- Create a file
.circleci/config.ymlwith the above contents in the repository's root.
# Activate Circle builds
- Go to
Settingspage of the repository dashboard in DeepSource and copy the
DeepSource / Repository Settings
- On Circle CI, go to
Environment Variablesand add
DEEPSOURCE_DSNenvironment variable with value as the
Circle CI / Dashboard
Do not add the
DEEPSOURCE_DSN variable as part of
.circleci/config.yml as the value contains sensitive information.
Triggerthe build on Circle CI.
# Setup GitHub status checks (Optional)
Required status checks ensure that all required checks are passing before collaborators can make changes to a branch.
- Go to repository
Settingspage on GitHub and click
Branch protection rulessection, add a new branch by clicking
Add rule(or) updating existing branch protection configuration by clicking
Editagainst the listed branch.
GitHub / Repository Settings
DeepSource: Test Coverage,
ci/circleci: Build Errorand
GitHub / Repository Settings / Branch protection
If you enable required status checks, Circle CI and DeepSource checks will be strictly enforced -- pull requests can be merged only after all the tests pass and all issues of major or critical severity are fixed.
🎉 Circle CI and DeepSource now runs tests and quality analysis continuously on every code change.
DeepSource / Repository Dashboard