Skip to content

Commit c40f122

Browse files
authored
chore: scaffold plugin entrypoint and tooling (#4)
* tools: Implement repo scaffolding (squashed * ci: clean up workflow smells * ci: `test:php` is same for coverage/non-coverage * docs: lint issue with split comment * tests(phpunit): fix `TESTS_REPO_ROOT_DIR` when bootstrapping
1 parent e7249f2 commit c40f122

21 files changed

+28805
-44
lines changed

.editorconfig

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# editorconfig.org
33

44
# WordPress Coding Standards
5-
# https://make.wordpress.org/core/handbook/coding-standards/
5+
# https://developer.wordpress.org/coding-standards/wordpress-coding-standards/
66

77
root = true
88

@@ -13,12 +13,19 @@ insert_final_newline = true
1313
trim_trailing_whitespace = true
1414
indent_style = tab
1515

16-
[*.yml]
17-
indent_style = space
16+
[*.json]
1817
indent_size = 2
1918

2019
[*.md]
2120
trim_trailing_whitespace = false
21+
indent_style = space
22+
indent_size = 2
2223

23-
[{*.txt,wp-config-sample.php}]
24-
end_of_line = crlf
24+
[*.txt]
25+
trim_trailing_whitespace = false
26+
27+
[*.yml]
28+
insert_final_newline = false
29+
quote_type = single
30+
indent_style = space
31+
indent_size = 2
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: 'Copilot Setup Steps'
2+
3+
# Automatically run the setup steps when they are changed to allow for easy validation, and
4+
# allow manual testing through the repository's "Actions" tab
5+
on:
6+
workflow_dispatch:
7+
push:
8+
paths:
9+
- .github/workflows/copilot-setup-steps.yml
10+
pull_request:
11+
paths:
12+
- .github/workflows/copilot-setup-steps.yml
13+
14+
jobs:
15+
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
16+
copilot-setup-steps:
17+
runs-on: ubuntu-latest
18+
19+
permissions:
20+
contents: read
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
with:
26+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
27+
persist-credentials: false
28+
29+
##
30+
# This allows Composer dependencies to be installed using a single step.
31+
#
32+
# Since the tests are currently run within the Docker containers where the PHP version varies,
33+
# the same PHP version needs to be configured for the action runner machine so that the correct
34+
# dependency versions are installed and cached.
35+
##
36+
- name: Set up PHP
37+
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
38+
with:
39+
php-version: '8.3'
40+
coverage: none
41+
42+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
43+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
44+
- name: Install Composer dependencies
45+
uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0
46+
with:
47+
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
48+
49+
- name: Setup Node
50+
uses: actions/setup-node@v4
51+
with:
52+
cache: 'npm'
53+
node-version-file: '.nvmrc'
54+
55+
- name: Install NPM dependencies
56+
run: npm ci

.github/workflows/test.yml

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
name: Test
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- trunk
8+
paths:
9+
- .github/workflows/test.yml
10+
pull_request:
11+
types:
12+
- opened
13+
- synchronize
14+
- ready_for_review
15+
16+
# Cancels all previous workflow runs for pull requests that have not completed.
17+
concurrency:
18+
# The concurrency group contains the workflow name and the branch name for pull requests
19+
# or the commit hash for any other events.
20+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
# Runs the PHP coding standards checks.
25+
#
26+
# Violations are reported inline with annotations.
27+
#
28+
# Performs the following steps:
29+
# - Checks out the repository.
30+
# - Sets up PHP.
31+
# - Configures caching for PHPCS scans.
32+
# - Installs Composer dependencies.
33+
# - Make Composer packages available globally.
34+
# - Runs PHPCS on the full codebase.
35+
# - Generate a report for displaying issues as pull request annotations.
36+
phpcs:
37+
name: Run PHPCS coding standards checks
38+
runs-on: ubuntu-24.04
39+
permissions:
40+
contents: read
41+
timeout-minutes: 20
42+
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
46+
with:
47+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
48+
persist-credentials: false
49+
50+
- name: Set up PHP
51+
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
52+
with:
53+
php-version: '8.3'
54+
coverage: none
55+
tools: cs2pr
56+
57+
# This date is used to ensure that the PHPCS cache is cleared at least once every week.
58+
# http://man7.org/linux/man-pages/man1/date.1.html
59+
- name: "Get last Monday's date"
60+
id: get-date
61+
run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT"
62+
63+
- name: Cache PHPCS scan cache
64+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
65+
with:
66+
path: tests/_output/phpcs-cache.json
67+
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }}
68+
69+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
70+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
71+
- name: Install Composer dependencies
72+
uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0
73+
with:
74+
custom-cache-suffix: ${{ steps.get-date.outputs.date }}
75+
76+
- name: Make Composer packages available globally
77+
run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH"
78+
79+
- name: Run PHPCS
80+
id: phpcs
81+
run: composer lint -- --report-full --report-checkstyle=./tests/_output/phpcs-report.xml
82+
83+
- name: Show PHPCS results in PR
84+
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
85+
run: cs2pr ./tests/_output/phpcs-report.xml
86+
87+
# Runs PHP static analysis tests.
88+
#
89+
# Violations are reported inline with annotations.
90+
#
91+
# Performs the following steps:
92+
# - Checks out the repository.
93+
# - Sets up PHP.
94+
# - Installs Composer dependencies.
95+
# - Configures caching for PHP static analysis scans.
96+
# - Make Composer packages available globally.
97+
# - Runs PHPStan static analysis (with Pull Request annotations).
98+
# - Saves the PHPStan result cache.
99+
# - Ensures version-controlled files are not modified or deleted.
100+
phpstan:
101+
name: Run PHP static analysis
102+
runs-on: ubuntu-24.04
103+
permissions:
104+
contents: read
105+
timeout-minutes: 20
106+
107+
steps:
108+
- name: Checkout repository
109+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
110+
with:
111+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
112+
persist-credentials: false
113+
114+
- name: Set up PHP
115+
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
116+
with:
117+
php-version: 8.3
118+
coverage: none
119+
tools: cs2pr
120+
121+
# This date is used to ensure that the Composer cache is cleared at least once every week.
122+
# http://man7.org/linux/man-pages/man1/date.1.html
123+
- name: "Get last Monday's date"
124+
id: get-date
125+
run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT"
126+
127+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
128+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
129+
- name: Install Composer dependencies
130+
uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0
131+
with:
132+
custom-cache-suffix: ${{ steps.get-date.outputs.date }}
133+
134+
- name: Make Composer packages available globally
135+
run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH"
136+
137+
- name: Cache PHP Static Analysis scan cache
138+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
139+
with:
140+
path: tests/_output # This is defined in the base.neon file.
141+
key: 'phpstan-result-cache-${{ github.run_id }}'
142+
restore-keys: |
143+
phpstan-result-cache-
144+
145+
- name: Run PHP static analysis tests
146+
id: phpstan
147+
run: phpstan analyse -vvv --error-format=checkstyle | cs2pr
148+
149+
- name: 'Save result cache'
150+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
151+
if: ${{ !cancelled() }}
152+
with:
153+
path: tests/_output
154+
key: 'phpstan-result-cache-${{ github.run_id }}'
155+
156+
# Runs the PHPUnit tests for WordPress.
157+
#
158+
# Performs the following steps:
159+
# - Sets environment variables.
160+
# - Checks out the repository.
161+
# - Sets up Node.js.
162+
# - Sets up PHP.
163+
# - Installs Composer dependencies.
164+
# - Installs npm dependencies
165+
# - Logs general debug information about the runner.
166+
# - Logs Docker debug information (about the Docker installation within the runner).
167+
# - Starts the WordPress Docker container.
168+
# - Logs the running Docker containers.
169+
# - Logs debug information about what's installed within the WordPress Docker containers.
170+
# - Install WordPress within the Docker container.
171+
# - Run the PHPUnit tests.
172+
# - Upload the code coverage report to Codecov.io.
173+
# - Upload the HTML code coverage report as an artifact.
174+
# - Ensures version-controlled files are not modified or deleted.
175+
# - Checks out the WordPress Test reporter repository.
176+
# - Submit the test results to the WordPress.org host test results.
177+
phpunit:
178+
name: Test PHP ${{ matrix.php }} WP ${{ matrix.wp }}${{ matrix.coverage && ' with coverage' || '' }}
179+
runs-on: ubuntu-24.04
180+
strategy:
181+
matrix:
182+
php: ['8.4', '8.3', '8.2', '8.1', '8.0', '7.4']
183+
wp: [latest, trunk, '6.7']
184+
coverage: [false]
185+
include:
186+
- php: '8.4'
187+
wp: latest
188+
coverage: true
189+
env:
190+
WP_ENV_PHP_VERSION: ${{ matrix.php }}
191+
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
192+
193+
steps:
194+
- name: Configure environment variables
195+
run: |
196+
echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV"
197+
echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV"
198+
199+
- name: Checkout repository
200+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
201+
with:
202+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
203+
persist-credentials: false
204+
205+
##
206+
# This allows Composer dependencies to be installed using a single step.
207+
#
208+
# Since the tests are currently run within the Docker containers where the PHP version varies,
209+
# the same PHP version needs to be configured for the action runner machine so that the correct
210+
# dependency versions are installed and cached.
211+
##
212+
- name: Set up PHP
213+
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
214+
with:
215+
php-version: '${{ matrix.php }}'
216+
coverage: none
217+
218+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
219+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
220+
- name: Install Composer dependencies
221+
uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0
222+
with:
223+
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
224+
225+
- name: Setup Node
226+
uses: actions/setup-node@v4
227+
with:
228+
cache: 'npm'
229+
node-version-file: '.nvmrc'
230+
231+
- name: Install NPM dependencies
232+
run: npm ci
233+
234+
- name: Start the Docker testing environment
235+
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
236+
with:
237+
timeout_minutes: 10
238+
max_attempts: 3
239+
command: |
240+
if [ "${{ matrix.coverage }}" == "true" ]; then
241+
npm run wp-env start -- --xdebug=coverage
242+
else
243+
npm run wp-env start
244+
fi
245+
246+
- name: Log versions
247+
run: |
248+
npm run wp-env -- run cli php -- -v
249+
npm run wp-env -- run cli wp core version
250+
251+
- name: Run PHPUnit tests${{ matrix.coverage && ' with coverage report' || '' }}
252+
continue-on-error: true
253+
id: phpunit
254+
run: |
255+
npm run test:php
256+
257+
- name: Upload code coverage report
258+
continue-on-error: true
259+
if: ${{ matrix.coverage }}
260+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
261+
with:
262+
token: ${{ secrets.CODECOV_TOKEN }}
263+
files: tests/_output/php-coverage.xml
264+
flags: unit
265+
fail_ci_if_error: true
266+
267+
- name: Upload HTML coverage report as artifact
268+
if: ${{ matrix.coverage }}
269+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
270+
with:
271+
name: wp-code-coverage-${{ matrix.php }}-${{ matrix.wp }}
272+
path: tests/_output/html
273+
overwrite: true

0 commit comments

Comments
 (0)