Skip to content

Commit

Permalink
Build/Test Tools: Cache the results of PHP_CodeSniffer across workf…
Browse files Browse the repository at this point in the history
…low 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
  • Loading branch information
desrosj committed Nov 16, 2021
1 parent c322210 commit ba62022
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
Empty file added .cache/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions .github/workflows/coding-standards.yml
Expand Up @@ -48,6 +48,7 @@ jobs:
# - Checks out the repository.
# - Sets up PHP.
# - Logs debug information.
# - Configures caching for PHPCS scans.
# - Installs Composer dependencies (use cache if possible).
# - Make Composer packages available globally.
# - Logs PHP_CodeSniffer debug information.
Expand Down Expand Up @@ -75,6 +76,18 @@ jobs:
php --version
composer --version
# 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 "::set-output name=date::$(/bin/date -u --date='last Mon' "+%F")"

- name: Cache PHPCS scan cache
uses: actions/cache@26968a09c0ea4f3e233fdddbafd1166051a095f6 # v2.1.4
with:
path: .cache/phpcs.json
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json') }}

- name: Install Composer dependencies
uses: ramsey/composer-install@92a7904348d4ad30236f3611e33b7f0c6f9edd70 # v1.1.0
with:
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/php-compatibility.yml
Expand Up @@ -20,7 +20,7 @@ on:
- '**.php'
# These files configure Composer. Changes could affect the outcome.
- 'composer.*'
# This file configures PHP Compatibility scanning. Changes could affect the outcome.
# This file configures PHP compatibility scanning. Changes could affect the outcome.
- 'phpcompat.xml.dist'
# Changes to workflow files should always verify all workflows are successful.
- '.github/workflows/*.yml'
Expand All @@ -42,7 +42,8 @@ jobs:
# Performs the following steps:
# - Checks out the repository.
# - Sets up PHP.
# - Logs debug information about the runner container.
# - Logs debug information.
# - Configures caching for PHP compatibility scans.
# - Installs Composer dependencies (use cache if possible).
# - Make Composer packages available globally.
# - Logs PHP_CodeSniffer debug information.
Expand All @@ -69,6 +70,18 @@ jobs:
php --version
composer --version
This comment was marked as a violation of GitHub Acceptable Use Policies
Copy link
@MrsSuraj

MrsSuraj Dec 16, 2023

Hii Suraj Prajapati's
WT_19042019_0922

# This date is used to ensure that the PHP compatibility 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 "::set-output name=date::$(/bin/date -u --date='last Mon' "+%F")"

- name: Cache PHP compatibility scan cache
uses: actions/cache@26968a09c0ea4f3e233fdddbafd1166051a095f6 # v2.1.4
with:
path: .cache/phpcompat.json
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcompat-cache-${{ hashFiles('**/composer.json') }}

- name: Install Composer dependencies
uses: ramsey/composer-install@92a7904348d4ad30236f3611e33b7f0c6f9edd70 # v1.1.0
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,6 +10,7 @@ wp-tests-config.php
/phpunit.xml
/.phpcs.xml
/phpcs.xml
.cache/*
/tests/phpunit/data/plugins/wordpress-importer
/tests/phpunit/data/.trac-ticket-cache*
/tests/qunit/compiled.html
Expand Down
2 changes: 1 addition & 1 deletion phpcompat.xml.dist
Expand Up @@ -11,7 +11,7 @@
<arg name="extensions" value="php"/>

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

<!-- Set the memory limit to 256M.
For most standard PHP configurations, this means the memory limit will temporarily be raised.
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Expand Up @@ -6,7 +6,7 @@
<arg name="extensions" value="php"/>

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

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

0 comments on commit ba62022

Please sign in to comment.