DEV Community

Cover image for Running Psalm With Github Actions
Faruk Nasir
Faruk Nasir

Posted on • Updated on

Running Psalm With Github Actions

I have written about Psalm here. Here, I share my workflow for running Psalm in Github Actions:

name: Psalm

on:
  push:
    paths:
      - '**.php'
      - 'psalm.xml.dist'

jobs:
  psalm:
    name: psalm
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
          coverage: none

      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: vendor
          key: composer-${{ hashFiles('composer.lock') }}

      - name: Run composer install
        run: composer install -n --prefer-dist

      - name: Run psalm
        run: ./vendor/bin/psalm --output-format=github
Enter fullscreen mode Exit fullscreen mode

Let's Discuss What's Happening Above

I start by specifying a name for the job. In this case, "Psalm".

name: Psalm
Enter fullscreen mode Exit fullscreen mode

I, then, go on to describe when I want the job to run. I only want it to run when there is a new version of a php file or the psalm config file.

on:
  push:
    paths:
      - '**.php'
      - 'psalm.xml'
Enter fullscreen mode Exit fullscreen mode

Then, I go on to describe fully the actual job that needs to run. First, I specify the environment the job is going to run on. Then, I check out the code in the virtual machine.

jobs:
  psalm:
    name: psalm
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
Enter fullscreen mode Exit fullscreen mode

That is followed by setting up PHP(using a third party action) and Composer:

- name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
          coverage: none

      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: vendor
          key: composer-${{ hashFiles('composer.lock') }}

      - name: Run composer install
        run: composer install -n --prefer-dist
Enter fullscreen mode Exit fullscreen mode

Then, the job is finally executed:

      - name: Run psalm
        run: ./vendor/bin/psalm --output-format=github
Enter fullscreen mode Exit fullscreen mode

And, that's that!

This post first appeared here

Top comments (0)