mirror of
git://develop.git.wordpress.org/
synced 2025-03-29 16:22:47 +01:00
This updates the following 3rd party actions: - `actions/setup-node` from `4.2.0` to `4.3.0` - `actions/upload-artifact` from `4.6.0` to `4.6.1` - `ramsey/composer-install` from `3.0.0` to `3.1.0` - `actions/cache` from `4.2.0` to `4.2.2` - `actions/download-artifact` from `4.1.8` to `4.1.9` - `codecov/codecov-action` from `5.3.1` to `5.4.0` See #62221. git-svn-id: https://develop.svn.wordpress.org/trunk@60051 602fd350-edb4-49c9-b593-d223f7449a82
109 lines
4.0 KiB
YAML
109 lines
4.0 KiB
YAML
##
|
|
# A reusable workflow that checks the PHP coding standards.
|
|
##
|
|
name: PHP coding standards
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
php-version:
|
|
description: 'The PHP version to use.'
|
|
required: false
|
|
type: 'string'
|
|
default: 'latest'
|
|
old-branch:
|
|
description: 'Whether this is an old branch that runs phpcbf instead of phpcs'
|
|
required: false
|
|
type: 'boolean'
|
|
default: false
|
|
|
|
# Disable permissions for all available scopes by default.
|
|
# Any needed permissions should be configured at the job level.
|
|
permissions: {}
|
|
|
|
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.
|
|
# - Make Composer packages available globally.
|
|
# - Runs PHPCS on the full codebase (warnings excluded).
|
|
# - Generate a report for displaying issues as pull request annotations.
|
|
# - Runs PHPCS on the `tests` directory without (warnings included).
|
|
# - Generate a report for displaying `test` directory issues as pull request annotations.
|
|
# - Ensures version-controlled files are not modified or deleted.
|
|
phpcs:
|
|
name: Run coding standards checks
|
|
runs-on: ubuntu-24.04
|
|
permissions:
|
|
contents: read
|
|
timeout-minutes: 20
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
with:
|
|
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
|
|
persist-credentials: false
|
|
|
|
- name: Set up PHP
|
|
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
|
|
with:
|
|
php-version: ${{ inputs.php-version }}
|
|
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@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
|
|
with:
|
|
path: |
|
|
.cache/phpcs-src.json
|
|
.cache/phpcs-tests.json
|
|
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-php-${{ inputs.php-version }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }}
|
|
|
|
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
|
|
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
|
|
- name: Install Composer dependencies
|
|
uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0
|
|
with:
|
|
custom-cache-suffix: ${{ steps.get-date.outputs.date }}
|
|
|
|
- name: Make Composer packages available globally
|
|
run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH"
|
|
|
|
- name: Run PHPCS on all Core files
|
|
id: phpcs-core
|
|
if: ${{ ! inputs.old-branch }}
|
|
run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml
|
|
|
|
- name: Show PHPCS results in PR
|
|
if: ${{ always() && steps.phpcs-core.outcome == 'failure' }}
|
|
run: cs2pr ./.cache/phpcs-report.xml
|
|
|
|
- name: Check test suite files for warnings
|
|
id: phpcs-tests
|
|
if: ${{ ! inputs.old-branch }}
|
|
run: phpcs tests --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml
|
|
|
|
- name: Show test suite scan results in PR
|
|
if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }}
|
|
run: cs2pr ./.cache/phpcs-tests-report.xml
|
|
|
|
- name: Run PHPCBF on all Core files (old branches)
|
|
if: ${{ inputs.old-branch }}
|
|
run: phpcbf
|
|
|
|
- name: Ensure version-controlled files are not modified during the tests
|
|
run: git diff --exit-code
|