2017 © Pedro PelĂĄez
 

project washingmachine

CI tool that integrates with Gitlab to show variations in the CRAP index

image

thecodingmachine/washingmachine

CI tool that integrates with Gitlab to show variations in the CRAP index

  • Sunday, April 22, 2018
  • by mouf
  • Repository
  • 6 Watchers
  • 12 Stars
  • 29,797 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 3 Open issues
  • 19 Versions
  • 31 % Grown

The README.md

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Build Status Coverage Status, (*1)

Washing machine

The washing machine is a tool that helps you writing cleaner code by integrating PHPUnit with Gitlab CI., (*2)

As a result, when you perform a merge request in Gitlab, the washing machine will add meaningful information about your code quality., (*3)

Usage

Enable Gitlab CI for your project

First, you need a Gitlab project with continuous integration enabled (so a project with a .gitlab-ci.yml file)., (*4)

Create a personal access token

Then, you need a Gitlab API personal access token., (*5)

Got it?, (*6)

Add a secret variable

Now, we need to add this token as a "secret variable" of your project (so the CI script can modify the merge request comments):, (*7)

Go to your project page in Gitlab, (*8)

Settings ➔ CI/CD Pipelines ➔ Secret Variables, (*9)

  • Key: GITLAB_API_TOKEN
  • Value: the token you just received in previous step

Configure PHPUnit to dump a "clover" test file

Let's configure PHPUnit. Go to your phpunit.xml.dist file and add:, (*10)

<phpunit>
    <logging>
        <log type="coverage-clover" target="clover.xml"/>
    </logging>
</phpunit>

Note: the "clover.xml" file must be written at the root of your GIT repository, so if your phpunit.xml.dist sits in a subdirectory, the correct path will be something like "../../clover.xml"., (*11)

Alternatively, washing-machine also knows how to read Crap4J files. Crap4J files contain Crap score, but not code coverage score so you will get slightly less data from Crap4J. The expected file name is "crap4j.xml"., (*12)

Configure Gitlab CI yml file

Now, we need to install the washingmachine, and get it to run., (*13)

.gitlab-ci.yml, (*14)

image: php:7.1

test:
  before_script:
   - cd /root && composer create-project thecodingmachine/washingmachine washingmachine ^2.0

  script:
   - phpdbg -qrr vendor/bin/phpunit

  after_script:
   - /root/washingmachine/washingmachine run -v

Notice that we need to make sure the PHPDbg extension for PHP is installed. Also, make sure that Xdebug is NOT enabled on your Docker instance. Xdebug can also return code coverage data but is less accurate than PHPDbg, leading to wrong CRAP score results., (*15)

Supported Gitlab versions

  • The washingmachine v2.0+ has support for Gitlab 9+.

If you seek support for older Gitlab versions, here is a list of supported Gitlab versions by washingmachine version:, (*16)

  • The washingmachine v1.0 => v1.2 has support for Gitlab 8.
  • The washingmachine v1.2+ has support for Gitlab 8 and up to Gitlab 9.5.

Adding extra data in the comment

When the washingmachine adds a comment in your merge-request, you can ask it to add additional text. This text must be stored in a file., (*17)

You simply do:, (*18)

washingmachine run -f file_to_added_to_comments.txt

Of course, this file might be the output of a CI tool., (*19)

The washingmachine will only display the first 50 lines of the file. If the file is longer, a link to download the file is added at the end of the comment., (*20)

You can also add several files by repeating the "-f" option:, (*21)

washingmachine run -f file1.txt -f file2.txt

Opening an issue

When a merge request is open, the washingmachine will post comments directly in the merge request., (*22)

If no merge request exists, the washingmachine can open an issue in your Gitlab project., (*23)

To open an issue, use the --open-issue option:, (*24)

washingmachine run --open-issue

Tip: you typically want to add the --open-issue tag conditionally if a build fails. Also, the --open-issue is ignored if a merge request matches the build., (*25)

Adding comments in commits

The washingmachine can add comments directly in the commits (in addition to adding comments in the merge request)., (*26)

To add comments in commits, use the --add-comments-in-commits option:, (*27)

washingmachine run --add-comments-in-commits

Note: this option was enabled by default in 1.x and has to be manually enabled in 2.x. For each comment, a mail is sent to the committer. This can generate a big number of mails on big commits. You have been warned :), (*28)

The Versions

21/03 2018
12/06 2017

1.2.x-dev

1.2.9999999.9999999-dev

CI tool that integrates with Gitlab to show variations in the CRAP index

  Sources   Download

MIT

The Requires

 

The Development Requires

12/06 2017
15/05 2017

1.1.x-dev

1.1.9999999.9999999-dev

CI tool that integrates with Gitlab to show variations in the CRAP index

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2017
28/04 2017
28/04 2017
27/04 2017
08/03 2017
28/02 2017
22/02 2017

1.0.x-dev

1.0.9999999.9999999-dev

CI tool that integrates with Gitlab to show variations in the CRAP index

  Sources   Download

MIT

The Requires

 

The Development Requires

22/02 2017
13/02 2017
13/02 2017
10/02 2017
10/02 2017