Skip to content

Commit

Permalink
feat: add composer-phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Apr 15, 2024
1 parent ada6996 commit e1b94b3
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,26 @@ Run [Pest](https://pestphp.com/) through composer.
| No | `php-version` | PHP version to use. If image is set, this will be ignored. | `php:8.1` | `''` |
| No | `flags` | Additional flags to pass to Pest | `--retry` | `''` |

#### composer-phpstan

[Source](composer-phpstan/action.yml)

Run [PHPStan](https://phpstan.org/) through composer.

1. Runs [composer-install].
2. Runs `vendor/bin/phpstan` in container.

##### Inputs

| Required | Name | Description | Example | Default |
| -------- | ------------- | ---------------------------------------------------------- | ------------------------------ | ------------------------------ |
| No | `command` | The PHPStan command to run. | `analyse` | `analyse` |
| No | `config-file` | PHPStan configuration file | `phpstan.neon` | `''` |
| No | `cache-dir` | PHPStan cache directory | `./tmp/phpstan` | `/tmp/phpstan` |
| No | `cache-hash` | Hash to use for caching | `${{ hashFiles('src/**/*') }}` | `${{ hashFiles('**/*.php') }}` |
| No | `image` | PHP Docker image to use | `php:8.1` | `''` |
| No | `php-version` | PHP version to use. If image is set, this will be ignored. | `8.1` | `7.4` |

### Testing

#### update-coverage
Expand Down
83 changes: 83 additions & 0 deletions composer-phpstan/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: 'Run PHPStan'
description: 'Set up PHP and run PHPStan'

inputs:
command:
description: 'The PHPStan command to run.'
required: false
default: 'analyse'

config-file:
description: 'PHPStan configuration file'
required: false
default: ''

cache-dir:
description: 'PHPStan cache directory'
required: false
default: '/tmp/phpstan'

cache-hash:
description: 'Hash to use for caching'
required: false
default: ${{ hashFiles('**/*.php') }}

image:
description: 'PHP Docker image to use'
required: false
default: ''

php-version:
description: 'PHP version to use. If image is set, this will be ignored.'
default: '7.4'
required: false

runs:
using: composite
steps:
- name: 'Prepare variables'
id: prepare
shell: bash
env:
CONFIG_FILE: ${{ inputs.config-file }}
#language=bash
run: |
ARGS=""
if [ -n "$CONFIG_FILE" ]; then
ARGS="$ARGS --configuration $CONFIG_FILE"
fi
echo "args=$ARGS" >> $GITHUB_OUTPUT
- name: 'Handle PHPStan cache'
uses: actions/cache@v4
id: phpstan-cache
with:
path: ${{ inputs.cache-dir }}
key: phpstan-cache-${{ hashFiles('phpstan.neon.dist', 'composer.json') }}-${{ inputs.cache-hash }}
restore-keys: |
phpstan-cache-${{ hashFiles('phpstan.neon.dist', 'composer.json') }}-
phpstan-cache-
- uses: myparcelnl/actions/pdk-setup-backend@v4
id: setup
if: steps.phpstan-cache.outputs.cache-hit != 'true'
with:
php-version: ${{ vars.PHP_VERSION }}

- name: 'Run PHPStan analysis'
if: steps.phpstan-cache.outputs.cache-hit != 'true'
env:
ARGS: ${{ inputs.args }}
IMAGE: ${{ steps.setup.outputs.image }}
shell: bash
#language=bash
run: |
docker run -t \
--volume $PWD:/app \
$IMAGE \
php -dmemory_limit=-1 vendor/bin/phpstan \
analyse \
--no-progress \
--no-interaction

0 comments on commit e1b94b3

Please sign in to comment.