# Setting up Continuous Quality with GitHub and Travis for Python
The following steps walk you through how to add
test-coverage analyzers to DeepSource, how to setup test coverage with Travis 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 the
.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 Travis CI to run tests and report test coverage
Let's configure Travis CI to run the tests:
# Set build language to Python language: python # Set python version to 3.6 python: 3.6 # Install dependencies install: - pip install -r requirements.txt # Run tests script: - coverage run test_hello.py # Report results to DeepSource after_success: # 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 Travis CI documentation to customize the build.
- Create a file
.travis.ymlwith the above contents on the repository root.
# Activate Travis builds
- Go to
Settingspage of the repository dashboard in DeepSource and copy the
DeepSource / Repository Settings
- On Travis CI, go to
Environment Variablesand add
DEEPSOURCE_DSNenvironment variable with value as the
Travis CI / Dashboard
Travis CI / Repository Settings
Do not add the
DEEPSOURCE_DSN variable as part of
.travis.yml as the value contains sensitive information.
Triggerthe build on Travis.
# 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
GitHub / Repository Settings/ Branch protection
If you enable required status checks, Travis 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.
🎉 Travis and DeepSource now runs tests and quality analysis continuously on every code change.
DeepSource / Repository Dashboard