DEV Community

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

Posted on • Edited on

3 2

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

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay