Skip to content

tests: vitest base config + git workflow (#187) #102

tests: vitest base config + git workflow (#187)

tests: vitest base config + git workflow (#187) #102

Workflow file for this run

name: PHPStan
on:
workflow_dispatch:
push:
branches:
- develop
- main
pull_request:
types:
- opened
- synchronize
- ready_for_review
paths:
- 'bin/**'
- 'phpstan/**'
- 'src/**'
- '**.php'
- '.github/workflows/phpstan.yml'
- '.env.dist'
- '.nvmrc'
- '.wp-env.json'
- 'composer.json'
- 'composer.lock'
- 'package-lock.json'
- 'package.json'
- 'phpstan.neon.dist'
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
jobs:
# Runs PHP static analysis tests.
#
# Violations are reported inline with annotations.
#
# Performs the following steps:
# - Checks out the repository.
# - Sets up PHP.
# - Gets last Monday's date (for cache invalidation).
# - Configures caching for PHP static analysis scans.
# - Installs Composer dependencies.
# - Makes Composer packages available globally.
# - Sets up Node.js.
# - Installs npm dependencies.
# - Configures caching for wp-env.
# - Sets up WordPress environment.
# - Starts the WordPress testing environment with wp-env.
# - Runs PHPStan static analysis (with Pull Request annotations).
# - Saves the PHPStan result cache.
phpstan:
name: Run PHP static analysis
runs-on: ubuntu-24.04
permissions:
contents: read
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
persist-credentials: false
- name: Set up PHP
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2.36.0
with:
php-version: 8.4
coverage: none
tools: cs2pr
# This date is used to ensure that the PHPCS cache is cleared at least once every week.
# http://man7.org/linux/man-pages/man1/date.1.html
- name: "Get last Monday's date"
id: get-date
run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT"
- name: Cache PHP Static Analysis scan cache
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: tests/_output # This is defined in the base.neon file.
key: 'phpstan-result-cache-${{ runner.os }}-date-${{ steps.get-date.outputs.date }}'
restore-keys: |
phpstan-result-cache-
- name: Install Composer dependencies
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
- name: Setup Node
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: Install NPM dependencies
run: npm ci
- name: Create cache directories
run: mkdir -p ~/.wp-env/downloads
- name: Cache WordPress downloads
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: ~/.wp-env/downloads
key: ${{ runner.os }}-wp-env-downloads-${{ hashFiles('.wp-env.json') }}
restore-keys: |
${{ runner.os }}-wp-env-downloads-
- name: Start the Docker testing environment
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
with:
timeout_minutes: 10
max_attempts: 3
command: |
npm run wp-env start -- ${{ secrets.ACTIONS_STEP_DEBUG && '--debug' || '' }}
- name: Run PHP static analysis tests
id: phpstan
run: |
npm run wp-env run tests-cli -- --env-cwd=wp-content/plugins/wp-graphql-headless-login sh -lc "vendor/bin/phpstan analyse --memory-limit=2G --error-format=checkstyle > phpstan-checkstyle.xml 2>&1"
- name: Show PHPStan results in PR
if: ${{ always() && steps.phpstan.outcome == 'failure' }}
run: cs2pr phpstan-checkstyle.xml
- name: Save result cache
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
if: ${{ !cancelled() }}
with:
path: tests/_output
key: 'phpstan-result-cache-${{ runner.os }}-date-${{ steps.get-date.outputs.date }}'