Skip to content

Improve Unit Tests GH Action #30

Improve Unit Tests GH Action

Improve Unit Tests GH Action #30

# Runs against the entire project, not just the changed files.
name: Static Analysis
on:
# run on pushes to all branches or all PR requests
push:
pull_request:
workflow_dispatch:
# used when called manually. 'secrets' are passed in automagically
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
inputs:
COMPOSER_ROOT_VERSION:
description: 'branch alias to use instead of dev-SHA, must have branch-alias in composer.json for root project'
default: 'dev-main'
required: false
type: string
workflow_call:
# used when called by _another_ workflow (not when called on this repo!)
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_call
inputs:
COMPOSER_ROOT_VERSION:
description: 'branch alias to use instead of dev-SHA, must have branch-alias in composer.json for root project'
default: 'dev-main'
required: false
type: string
env:
COMPOSER_ROOT_VERSION: 'dev-main'
jobs:
static-analysis:
runs-on: ubuntu-latest
steps:
# get the source code
- uses: actions/checkout@v3
- name: Print directory info after checkout
run: ls -lah
- name: Setup PHP
uses: shivammathur/setup-php@verbose
with:
php-version: '8.3.12'
# note that psalm isn't installed here, since we use a custom fork of psalm, and is instead installed via
# composer, then called directly
tools: cs2pr:1.8.5, composer:2.8.4, phpstan/phpstan:2.0.4
extensions: mailparse
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Composer dependencies
if: ${{ steps.composer-cache.outputs.cache-hit != 'true' }}
env:
# use the inputs if supplied (from being called via another workflow), supplied vars, or env as a final fallback
COMPOSER_ROOT_VERSION: ${{ inputs.COMPOSER_ROOT_VERSION || vars.COMPOSER_ROOT_VERSION || env.COMPOSER_ROOT_VERSION }}
run: composer install --no-interaction --no-scripts --ignore-platform-req=php+
- name: Run PHPStan
id: run-phpstan
run: phpstan analyse -c phpstan.neon --error-format=checkstyle --no-progress --memory-limit=2G ${{ steps.files.outputs.added_modified }} | cs2pr
- name: Run Psalm
id: run-psalm
# note that we're running the composer-installed psalm in vendor so that it picks up our custom fork
run: vendor/bin/psalm --ignore-baseline --output-format=checkstyle ${{ steps.files.outputs.added_modified }} | cs2pr