ci-diff-helper
¶
Diff Helper for Continuous Integration (CI) Services.
For an open source project, running unit tests, system tests, torture tests, fuzz tests, integration tests, code quality checks, etc. can quickly become a large task.
In order to limit the amount of time and resources that these jobs require, this tool provides a way to determine which files have changed and provides a Python API for these changes. In addition, this library provides the corresponding commit SHA (or other artifact) that is used as the diffbase.
The library supports (planned)
- Continuous Integration Services
- Verson Control Systems
- Project Hosting Sites
Note
When configuring your CI environment, it may be useful to set
the GITHUB_OAUTH_TOKEN
environment variable
(GH_TOKEN
). By authenticating in
GitHub API requests, rate limiting can be avoided. Unauthenticated
requests will be subject to rate limiting across the entire
CI system.
To use this in your project, first install:
$ pip install --upgrade ci-diff-helper
Once you’ve done that, you can automatically detect your current environment and get a configuration object with information about your environment:
>>> import ci_diff_helper
>>> config = ci_diff_helper.get_config()
>>> config
<CircleCI (active=True)>
Common Configuration Properties¶
Long-lived configuration objects are provided as an interface for CI system information. These config objects cache the returned values for each property and use them to compute other useful values.
Each such configuration type (e.g. AppVeyor
,
CircleCI
, Travis
) has a
common set of properties.
>>> config
<CircleCI (active=True)>
>>> config.active
True
>>> config.branch
'pull/808'
>>> config.tag is None
True
All configuration types can also be used to detect if a merge commit is currently being built:
>>> config.is_merge
False
git
tools¶
The helpers git_root()
and
get_checked_in_files()
are provided as
tools for a git
-based project. Being able to get the
root of the current git
checkout may be needed to collect
files, execute scripts, etc. Getting all checked in files can
be useful for things like test collection, file linting, etc.
>>> ci_diff_helper.git_root()
'/path/to/your/git_checkout'
>>> ci_diff_helper.get_checked_in_files()
['/path/to/your/git_checkout/setup.py',
'/path/to/your/git_checkout/project/__init__.py',
'/path/to/your/git_checkout/project/feature.py']