Skip to content

Commit fda299c

Browse files
committed
tools: Implement repo scaffolding (squashed
1 parent e7249f2 commit fda299c

21 files changed

+28817
-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: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
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 }}-php-${{ inputs.php-version }}-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+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
77+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
78+
- name: Install Composer dependencies
79+
uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0
80+
with:
81+
custom-cache-suffix: ${{ steps.get-date.outputs.date }}
82+
83+
- name: Make Composer packages available globally
84+
run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH"
85+
86+
- name: Run PHPCS
87+
id: phpcs
88+
run: composer lint -- --report-full --report-checkstyle=./tests/_output/phpcs-report.xml
89+
90+
- name: Show PHPCS results in PR
91+
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
92+
run: cs2pr ./tests/_output/phpcs-report.xml
93+
94+
# Runs PHP static analysis tests.
95+
#
96+
# Violations are reported inline with annotations.
97+
#
98+
# Performs the following steps:
99+
# - Checks out the repository.
100+
# - Sets up PHP.
101+
# - Installs Composer dependencies.
102+
# - Configures caching for PHP static analysis scans.
103+
# - Make Composer packages available globally.
104+
# - Runs PHPStan static analysis (with Pull Request annotations).
105+
# - Saves the PHPStan result cache.
106+
# - Ensures version-controlled files are not modified or deleted.
107+
phpstan:
108+
name: Run PHP static analysis
109+
runs-on: ubuntu-24.04
110+
permissions:
111+
contents: read
112+
timeout-minutes: 20
113+
114+
steps:
115+
- name: Checkout repository
116+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
117+
with:
118+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
119+
persist-credentials: false
120+
121+
- name: Set up PHP
122+
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
123+
with:
124+
php-version: 8.3
125+
coverage: none
126+
tools: cs2pr
127+
128+
# This date is used to ensure that the Composer cache is cleared at least once every week.
129+
# http://man7.org/linux/man-pages/man1/date.1.html
130+
- name: "Get last Monday's date"
131+
id: get-date
132+
run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT"
133+
134+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
135+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
136+
- name: Install Composer dependencies
137+
uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0
138+
with:
139+
custom-cache-suffix: ${{ steps.get-date.outputs.date }}
140+
141+
- name: Make Composer packages available globally
142+
run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH"
143+
144+
- name: Cache PHP Static Analysis scan cache
145+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
146+
with:
147+
path: tests/_output # This is defined in the base.neon file.
148+
key: 'phpstan-result-cache-${{ github.run_id }}'
149+
restore-keys: |
150+
phpstan-result-cache-
151+
152+
- name: Run PHP static analysis tests
153+
id: phpstan
154+
run: phpstan analyse -vvv --error-format=checkstyle | cs2pr
155+
156+
- name: 'Save result cache'
157+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
158+
if: ${{ !cancelled() }}
159+
with:
160+
path: tests/_output
161+
key: 'phpstan-result-cache-${{ github.run_id }}'
162+
163+
# Runs the PHPUnit tests for WordPress.
164+
#
165+
# Performs the following steps:
166+
# - Sets environment variables.
167+
# - Checks out the repository.
168+
# - Sets up Node.js.
169+
# - Sets up PHP.
170+
# - Installs Composer dependencies.
171+
# - Installs npm dependencies
172+
# - Logs general debug information about the runner.
173+
# - Logs Docker debug information (about the Docker installation within the runner).
174+
# - Starts the WordPress Docker container.
175+
# - Logs the running Docker containers.
176+
# - Logs debug information about what's installed within the WordPress Docker containers.
177+
# - Install WordPress within the Docker container.
178+
# - Run the PHPUnit tests.
179+
# - Upload the code coverage report to Codecov.io.
180+
# - Upload the HTML code coverage report as an artifact.
181+
# - Ensures version-controlled files are not modified or deleted.
182+
# - Checks out the WordPress Test reporter repository.
183+
# - Submit the test results to the WordPress.org host test results.
184+
phpunit:
185+
name: Test PHP ${{ matrix.php }} WP ${{ matrix.wp }}${{ matrix.coverage && ' with coverage' || '' }}
186+
runs-on: ubuntu-24.04
187+
strategy:
188+
matrix:
189+
php: ['8.4', '8.3', '8.2', '8.1', '8.0', '7.4']
190+
wp: [latest, trunk, '6.7']
191+
coverage: [false]
192+
include:
193+
- php: '8.4'
194+
wp: latest
195+
coverage: true
196+
env:
197+
WP_ENV_PHP_VERSION: ${{ matrix.php }}
198+
WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }}
199+
200+
steps:
201+
- name: Configure environment variables
202+
run: |
203+
echo "PHP_FPM_UID=$(id -u)" >> "$GITHUB_ENV"
204+
echo "PHP_FPM_GID=$(id -g)" >> "$GITHUB_ENV"
205+
206+
- name: Checkout repository
207+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
208+
with:
209+
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
210+
persist-credentials: false
211+
212+
##
213+
# This allows Composer dependencies to be installed using a single step.
214+
#
215+
# Since the tests are currently run within the Docker containers where the PHP version varies,
216+
# the same PHP version needs to be configured for the action runner machine so that the correct
217+
# dependency versions are installed and cached.
218+
##
219+
- name: Set up PHP
220+
uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0
221+
with:
222+
php-version: '${{ matrix.php }}'
223+
coverage: none
224+
225+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
226+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
227+
- name: Install Composer dependencies
228+
uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0
229+
with:
230+
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
231+
232+
- name: Setup Node
233+
uses: actions/setup-node@v4
234+
with:
235+
cache: 'npm'
236+
node-version-file: '.nvmrc'
237+
238+
- name: Install NPM dependencies
239+
run: npm ci
240+
241+
- name: Start the Docker testing environment
242+
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
243+
with:
244+
timeout_minutes: 10
245+
max_attempts: 3
246+
command: |
247+
if [ "${{ matrix.coverage }}" == "true" ]; then
248+
npm run wp-env start -- --xdebug=coverage
249+
else
250+
npm run wp-env start
251+
fi
252+
253+
- name: Log versions
254+
run: |
255+
npm run wp-env -- run cli php -- -v
256+
npm run wp-env -- run cli wp core version
257+
258+
- name: Run PHPUnit tests${{ matrix.coverage && ' with coverage report' || '' }}
259+
continue-on-error: true
260+
id: phpunit
261+
run: |
262+
if [ "${{ matrix.coverage }}" == "true" ]; then
263+
npm run test:php:coverage
264+
else
265+
npm run test:php
266+
fi
267+
268+
- name: Upload code coverage report
269+
continue-on-error: true
270+
if: ${{ matrix.coverage }}
271+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
272+
with:
273+
token: ${{ secrets.CODECOV_TOKEN }}
274+
files: tests/_output/php-coverage.xml
275+
flags: unit
276+
fail_ci_if_error: true
277+
278+
- name: Upload HTML coverage report as artifact
279+
if: ${{ matrix.coverage }}
280+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
281+
with:
282+
name: wp-code-coverage-${{ matrix.php }}-${{ matrix.wp }}
283+
path: tests/_output/html
284+
overwrite: true

0 commit comments

Comments
 (0)