From e5ee57edd8cdef38f741f4b8493c12ca8b35636d Mon Sep 17 00:00:00 2001 From: Erik Sommer Date: Sun, 26 Jan 2025 22:39:40 +0100 Subject: [PATCH] Add phpstan action Signed-off-by: Erik Sommer --- .github/workflows/php-code-scanning.yml | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/php-code-scanning.yml diff --git a/.github/workflows/php-code-scanning.yml b/.github/workflows/php-code-scanning.yml new file mode 100644 index 00000000..05620e58 --- /dev/null +++ b/.github/workflows/php-code-scanning.yml @@ -0,0 +1,50 @@ +name: PHP Code Scanning + +on: + push: + branches: + - '*' # Trigger on commits to any branch + pull_request: + branches: + - 'master' # Trigger for PRs targeting the 'master' branch + +jobs: + phpstan: + runs-on: ubuntu-latest + + steps: + # Check out the code from the repository + - name: Checkout code + uses: actions/checkout@v3 + + # Set up PHP 7.4 environment + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + + # Install dependencies (including PHPStan if it's a dev dependency) + - name: Install dependencies + run: | + composer install --no-interaction --prefer-dist + + # Run PHPStan to analyze for errors and surface them in the logs + - name: Run PHPStan (Errors Only) + run: | + vendor/bin/phpstan analyse --level 5 --error-format=console --no-progress + continue-on-error: true # Continue even if PHPStan finds warnings + + # Check if PHPStan found errors and fail if so + - name: Fail on Errors (if any) + run: | + if grep -q 'ERROR' phpstan.log; then + echo "PHPStan found errors, failing the job!"; + exit 1; + fi + continue-on-error: false # This step will fail the job if errors are found + + # Optional: Run PHPStan again for warnings (if you want to surface warnings) + - name: Run PHPStan (Warnings) + run: | + vendor/bin/phpstan analyse --level 5 --error-format=console --no-progress + continue-on-error: true # Continue even if PHPStan finds warnings