Skip to content

ci: migrate to wp-env (#467) #3

ci: migrate to wp-env (#467)

ci: migrate to wp-env (#467) #3

Workflow file for this run

name: PHPCS
on:
workflow_dispatch:
push:
branches:
- develop
- main
pull_request:
types:
- opened
- synchronize
- ready_for_review
paths:
- 'src/**'
- '.github/workflows/code-standard.yml'
- '**.php'
- '.phpcs.xml.dist'
- 'composer.json'
- 'composer.lock'
# 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 the PHP coding standards checks.
#
# Violations are reported inline with annotations.
#
# Performs the following steps:
# - Checks out the repository.
# - Sets up PHP.
# - Configures caching for PHPCS scans.
# - Installs Composer dependencies.
# - Runs PHPCS on the full codebase.
# - Generate a report for displaying issues as pull request annotations.
phpcs:
name: Lint PHP
runs-on: ubuntu-24.04
permissions:
contents: read
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
persist-credentials: false
- name: Set up PHP
uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4
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 PHPCS scan cache
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: tests/_output/phpcs-cache.json
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }}
- name: Install Composer dependencies
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
- name: Run PHPCS
id: phpcs
run: composer lint -- --report-full --report-checkstyle=./tests/_output/phpcs-report.xml
- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./tests/_output/phpcs-report.xml