forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreusable-coding-standards-php.yml
More file actions
133 lines (118 loc) · 4.73 KB
/
reusable-coding-standards-php.yml
File metadata and controls
133 lines (118 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
##
# 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
<<<<<<< Updated upstream
<<<<<<< Updated upstream
=======
=======
>>>>>>> Stashed changes
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
<<<<<<< Updated upstream
>>>>>>> Stashed changes
=======
>>>>>>> Stashed changes
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
<<<<<<< Updated upstream
<<<<<<< Updated upstream
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
=======
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
>>>>>>> Stashed changes
=======
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
>>>>>>> Stashed changes
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
<<<<<<< Updated upstream
<<<<<<< Updated upstream
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
=======
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
>>>>>>> Stashed changes
=======
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
>>>>>>> Stashed changes
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