Skip to content

Commit ba62022

Browse files
committed
Build/Test Tools: Cache the results of PHP_CodeSniffer across workflow runs.
When the `PHP_CodeSniffer` runs, it produces a cache file. When a cache file is present, only changed files are rescanned, making subsequent scans significantly faster. This adds the needed steps to the corresponding GitHub Actions workflows to cache these files across runs. The cache keys include the date of the previous Monday to ensure that the cache is flushed at least weekly. Since GitHub Action caches cannot be updated once created, the scans will take slightly longer as the week progresses and more PHP files are updated. The date within the cache key can be updated to purge twice weekly if the scan time starts to approach the current scan times. This change also introduces a `.cache` directory for all caching files related to build/test tools. Props johnbillion, jrf. Fixes #49783. git-svn-id: https://develop.svn.wordpress.org/trunk@52179 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c322210 commit ba62022

6 files changed

Lines changed: 31 additions & 4 deletions

File tree

.cache/.gitkeep

Whitespace-only changes.

.github/workflows/coding-standards.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
# - Checks out the repository.
4949
# - Sets up PHP.
5050
# - Logs debug information.
51+
# - Configures caching for PHPCS scans.
5152
# - Installs Composer dependencies (use cache if possible).
5253
# - Make Composer packages available globally.
5354
# - Logs PHP_CodeSniffer debug information.
@@ -75,6 +76,18 @@ jobs:
7576
php --version
7677
composer --version
7778
79+
# This date is used to ensure that the PHPCS cache is cleared at least once every week.
80+
# http://man7.org/linux/man-pages/man1/date.1.html
81+
- name: "Get last Monday's date"
82+
id: get-date
83+
run: echo "::set-output name=date::$(/bin/date -u --date='last Mon' "+%F")"
84+
85+
- name: Cache PHPCS scan cache
86+
uses: actions/cache@26968a09c0ea4f3e233fdddbafd1166051a095f6 # v2.1.4
87+
with:
88+
path: .cache/phpcs.json
89+
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json') }}
90+
7891
- name: Install Composer dependencies
7992
uses: ramsey/composer-install@92a7904348d4ad30236f3611e33b7f0c6f9edd70 # v1.1.0
8093
with:

.github/workflows/php-compatibility.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ on:
2020
- '**.php'
2121
# These files configure Composer. Changes could affect the outcome.
2222
- 'composer.*'
23-
# This file configures PHP Compatibility scanning. Changes could affect the outcome.
23+
# This file configures PHP compatibility scanning. Changes could affect the outcome.
2424
- 'phpcompat.xml.dist'
2525
# Changes to workflow files should always verify all workflows are successful.
2626
- '.github/workflows/*.yml'
@@ -42,7 +42,8 @@ jobs:
4242
# Performs the following steps:
4343
# - Checks out the repository.
4444
# - Sets up PHP.
45-
# - Logs debug information about the runner container.
45+
# - Logs debug information.
46+
# - Configures caching for PHP compatibility scans.
4647
# - Installs Composer dependencies (use cache if possible).
4748
# - Make Composer packages available globally.
4849
# - Logs PHP_CodeSniffer debug information.
@@ -69,6 +70,18 @@ jobs:
6970
php --version
7071
composer --version
7172
73+
# This date is used to ensure that the PHP compatibility cache is cleared at least once every week.
74+
# http://man7.org/linux/man-pages/man1/date.1.html
75+
- name: "Get last Monday's date"
76+
id: get-date
77+
run: echo "::set-output name=date::$(/bin/date -u --date='last Mon' "+%F")"
78+
79+
- name: Cache PHP compatibility scan cache
80+
uses: actions/cache@26968a09c0ea4f3e233fdddbafd1166051a095f6 # v2.1.4
81+
with:
82+
path: .cache/phpcompat.json
83+
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcompat-cache-${{ hashFiles('**/composer.json') }}
84+
7285
- name: Install Composer dependencies
7386
uses: ramsey/composer-install@92a7904348d4ad30236f3611e33b7f0c6f9edd70 # v1.1.0
7487
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ wp-tests-config.php
1010
/phpunit.xml
1111
/.phpcs.xml
1212
/phpcs.xml
13+
.cache/*
1314
/tests/phpunit/data/plugins/wordpress-importer
1415
/tests/phpunit/data/.trac-ticket-cache*
1516
/tests/qunit/compiled.html

phpcompat.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<arg name="extensions" value="php"/>
1212

1313
<!-- Whenever possible, cache the scan results and re-use those for unchanged files on the next scan. -->
14-
<arg name="cache"/>
14+
<arg name="cache" value=".cache/phpcompat.json"/>
1515

1616
<!-- Set the memory limit to 256M.
1717
For most standard PHP configurations, this means the memory limit will temporarily be raised.

phpcs.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<arg name="extensions" value="php"/>
77

88
<!-- Whenever possible, cache the scan results and re-use those for unchanged files on the next scan. -->
9-
<arg name="cache"/>
9+
<arg name="cache" value=".cache/phpcs.json"/>
1010

1111
<!-- Set the memory limit to 256M.
1212
For most standard PHP configurations, this means the memory limit will temporarily be raised.

0 commit comments

Comments
 (0)