Using the Odoo Community Association maintainer quality tools

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.

Getting ready

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.

How to do it…

To integrate the OCA maintainer-quality-tools with your repository, you need to perform the following steps:

  1. Connect to https://travis-ci.org/.
    How to do it…
  2. To sign in, choose Sign in with Github.
  3. Click on your name in the top right corner to access to your profile's settings, as shown in the following screenshot:
    How to do it…
  4. Click on the Sync button to load the information about all your public repositories in Travis. This can take a couple of minutes depending on how many repositories you have.
  5. For all the repositories you want to use Travis on, enable them by toggling the grey cross to a green check mark.
  6. You can click on the cogwheel to access each repository's settings, but the defaults are OK too.
  7. Inside a local clone of your repository, create a file called .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
  8. Commit the file and push it to GitHub:
    $ git add .travis.yml
    $ git commit -m "add travis configuration"
    $ git push origin
    
  9. Go to your 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:
    How to do it…

How it works…

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.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset