Integrating Psalm Static Analysis Tool in Jenkins CI
Hello, as part of my GSOC 2019 Project, I have worked with @eileen @JoeMurray To See ways of Integrating Psalm Static Analysis Tool with civicore, I am happy to report that we have made progress with the integration, and here are the steps that can be taken to replicate the Integration. I know that Jenkins and Composer has already been setup on civicore infrastructure, but for the sake of anyone looking to replicate this from scratch I will be assuming that nothing is in place
Installing Jenkins on a server
- Install PHP on server, check out this link
- Install composer on server, check out this link
- Install Jenkins on Server, check out this link
Integrating Jenkins with Github
- Here is a concise guide on setting up Jenkins to Listen for pull requests on a Github Repo
Final Step
The steps from the above steps help you set up a Jenkins Job, And also Configure the Job, Now you can Add A build Step so Jenkins can install required Dependencies for Psalm, as well as run psalm static analysis on civicore
Add the following to build Step
composer update
composer require --dev vimeo/psalm:3.4.9
./vendor/bin/psalm --show-info=false
Configuring Psalm to Work with civicore
- Add a psalm.xml file to civicore root folder
- This can be achieved by running
./vendor/bin/psalm --init
- This can be achieved by running
- Add psalmbase.xml file to civicore root folder, this is a baseline file
- This can be achieved by running
./vendor/bin/psalm --set-baseline=psalmbaseline.xml
- This can be achieved by running
Psalm baseline features allows us to grandfather errors already existing in civicore, while checking for new errors arising from subsequent PR's after its installation.
** Demo **
- Jenkins Server with Job and required configuration setup
- Github repo Mirrowing civicore, notice the psalm.xml file and the psalmbaseline.xml file
- A passing PR with baseline feature set
- A falling PR with baseline feature set and new errors introduced through commits
** Potential Gotchas **
-
For consistent results, It is advisable to create psalm configuration files i.e psalm.xml && psalmbaseline.xml on the actual server where Jenkins is installed, as Psalm might have different error count when run on the same repository, with same configurations but on different servers. Am working to find out why this is the case.
-
running
./vendor/bin/psalm --init
creates a psalm.xml file which lists the different folders in the current repository, for civicore folders ext,packages are always included but non existent, do well to remove the folders from psalm.xml before running./vendor/bin/psalm
on the folder, to avoid errors
cc @totten