The Odoo Community Association (OCA) manages a large number of Odoo projects using the GitHub infrastructure. The association projects use Travis CI for continuous integration. This recipe shows how you can use the maintainer QA tools developed by the community in your own GitHub repositories.
To use this recipe, you need to have a public GitHub repository with your modules. At the time of writing, the OCA tools expect that this repository contains several addons in subdirectories.
To integrate the OCA maintainer-quality-tools with your repository, you need to perform the following steps:
.travis.yml
with the following content:language: python sudo: false cache: apt: true directories: - $HOME/.cache/pip python: - "2.7" addons: apt: packages: - expect-dev # provides unbuffer utility - python-lxml # because pip installation is slow - python-simplejson - python-serial - python-yaml virtualenv: system_site_packages: true env: global: - VERSION="9.0" TESTS="0" LINT_CHECK="0" matrix: - LINT_CHECK="1" - TESTS="1" ODOO_REPO="odoo/odoo" - TESTS="1" ODOO_REPO="OCA/OCB" install: - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - travis_install_nightly script: - travis_run_tests after_success: - travis_after_tests_success
$ git add .travis.yml $ git commit -m "add travis configuration" $ git push origin
travis-ci.org
page and click on your project's name. You should see a first build in progress. If your code follows the OCA coding standard, it may even be green on the first run:When you enable Travis CI on a repository, Travis registers a hook on GitHub. By default, the hook will trigger a Travis CI build for each push to a branch of the repository and for each pull request. Pull requests are built on a temporary merge of the PR, to ensure that the merged branches pass the tests.
The Travis CI configuration file proposed here is fairly advanced and very close to the one found in the sample_files
subdirectory of the maintainer-quality-tools project you can see at https://github.com/OCA/maintainer-quality-tools (we removed the transifex configuration used to manage module translations). Here's an explanation of the customized sections in the file:
addons
: This has nothing to do with Odoo addon modules. It's used to ask Travis to install some Ubuntu packages using distribution packages in the testing environment. This saves us from installing Python packages such as python-lxml
from source, which takes a lot of time.env
: This section defines environment variables and the build matrix. The maintainer quality tools use these environment variables to know what to test, and will run each env
line in a separate test run:VERSION
: This is the Odoo version to test against.LINT_CHECK
: Use 0
for a build with no flake8
or Pylint
tests, and 1
otherwise. In the matrix, we set the first build to perform the lint check, as this is fast and we want rapid feedback if the coding standards are not met or if the linter finds errors.TESTS
: Use 0
for a build in which the module tests are not run; otherwise use 1
.ODOO_REPO
: This is the GitHub repository for Odoo to test against when TESTS
is 1
. In the recipe, we set up a build against both the official https://github.com/odoo/odoo repository and the community backports repository https://github.com/OCA/OCB. If unset, only the official repository is used.install
: This sections downloads maintainer-quality-tools
in the build environment and calls the travis_install_nightly
utility, which will set up Odoo in Travis for you.script
: This section calls travis_run_tests
from maintainer-quality-tools
. This is the script in charge of checking the environment variables from the build matrix and performing the appropriate actions.after_success
: After the tests in the script section have run successfully, the travis_after_test_success
script is run. In the context of the recipe, this script will check the test coverage of the modules using https://coveralls.io and produce a report in the build.