Skip to content

Increase php-parser use #346

Increase php-parser use

Increase php-parser use #346

Workflow file for this run

name: PHPStan Analysis
on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
# branches: [ master ] # all PRs?
push:
branches:
- master
workflow_dispatch:
jobs:
phpstan:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout PR branch
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0 # needed for baseline comparison
- name: Set up PHP
uses: shivammathur/setup-php@ccf2c627fe61b1b4d924adfcbd19d661a18133a0 # v2.35.2
with:
php-version: 7.4
tools: composer:v2, cs2pr
extensions: fileinfo, gd
coverage: none
- name: Install Project Dependencies
run: composer install
- name: Run PHPStan (annotate all errors to max level)
id: run-phpstan
run: |
vendor/bin/phpstan analyse --memory-limit=-1 --level max -vvv --error-format=checkstyle | cs2pr
continue-on-error: true
- name: Run PHPStan (fail if phpstan.neon level is not met) on PRs
run: vendor/bin/phpstan analyse --memory-limit=-1 -vvv
# TODO: fail _after_ the badge is updated
continue-on-error: true
- name: Get PhpStan level
id: phpstan-level
run: |
# After adding the example commands at the top of the phpstan.neon file, which contain the word "level", we
# now have to use `tail`+`head` to skip the first few lines. (I'm sure there's a suitable regex, but this is
# easy to implement and follow)
LEVEL=$(tail -n +3 phpstan.neon | head -n 10 | grep level | sed "s/[^0-9]*//")
echo "level=$LEVEL" >> "$GITHUB_OUTPUT"
- name: Check success
if: steps.run-phpstan.outcome == 'success'
run: curl -o .github/phpstan.svg https://img.shields.io/badge/PHPStan-Level%20${{ steps.phpstan-level.outputs.level}}-2a5ea7.svg
- name: Check failures
if: steps.run-phpstan.outcome != 'success'
run: curl -o .github/phpstan.svg https://img.shields.io/badge/PHPStan-Level%20${{ steps.phpstan-level.outputs.level}}❌-lightgrey.svg
# This probably needs DEPLOY_KEY set for PRs and private repos
- name: Commit README badge changes
uses: stefanzweifel/git-auto-commit-action@v7
if: ${{ matrix.php == '7.4' && github.event_name != 'pull_request' }}
with:
file_pattern: ".github/phpstan.svg"
commit_message: "🤖 PhpStan"