Skip to content

Instantly share code, notes, and snippets.

@prondubuisi
Last active February 20, 2020 06:34
Show Gist options
  • Save prondubuisi/bbb6d0fe7055fb5e50397d1f9c1b3e3b to your computer and use it in GitHub Desktop.
Save prondubuisi/bbb6d0fe7055fb5e50397d1f9c1b3e3b to your computer and use it in GitHub Desktop.

Open Source Static Analysis Integration with Jenkins, Github, DigitalOcean and Psalm

Overview

  • Setup Digital OceanDroplet
  • Install Jenkins and required plugins
  • Configure Github to work with Jenkins
  • Set up PHP project
  • Add Psalm to project
  • Noteworthy Psalm Features

Setup DigitalOcean Droplet

Install Jenkins and Required Plugins

Get Server ready for Psalm

Integrating Jenkins with Github

  • Here is a concise guide on setting up Jenkins to Listen for pull requests on a Github Repo

The steps from the above help you set up a Jenkins Job, And also Configure the Job.

Setting up Psalm

Psalm Setup

Configuring Psalm to Work with Demo locally

  • composer require --dev vimeo/psalm
  • Add a psalm.xml file to Project root folder
    • This can be achieved by running ./vendor/bin/psalm --init
  • See Project errors
  • ./vendor/bin/psalm --show-info=true

Configuring Psalm to Work with Demo on Jenkins

  • Push psalm config files to demo repo

Now you can Add a build Step so Jenkins can install required Dependencies for Psalm, as well as run psalm static analysis on the demo project

  • composer require --dev vimeo/psalm
  • ./vendor/bin/psalm --show-info=true

Working with Legacy Codebases

Psalm baseline feature allows us to grandfather errors already existing in the demo, while checking for new errors arising from subsequent PR's after its installation.

  • This can be achieved by running ./vendor/bin/psalm --set-baseline=psalmbaseline.xml

Handy Flags for PSALM

  • --threads=10

    This increases analysis speed as it utilizes 10 threads instead of one

  • --show-info=false

    Ensures that only error messages are returned by Psalm and not info warnings, this keeps the output clean

  • --debug-by-line

    Very useful to trace line causing Psalm to fail, this makes fixing easy

  • --config=psalm.xml

    Set path to Psalm.xml in case you intend to put the config file outside the root directory

Handy PR comments for GithubPR builder

  • "ok to test" to accept this pull request for testing
  • "test this please" for a one time test run
  • "add to whitelist" to add the author to the whitelist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment