From ba620225c5b0fb87d1c3d119c29fb383121803e4 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Tue, 16 Nov 2021 14:17:26 +0000 Subject: [PATCH] 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 --- .cache/.gitkeep | 0 .github/workflows/coding-standards.yml | 13 +++++++++++++ .github/workflows/php-compatibility.yml | 17 +++++++++++++++-- .gitignore | 1 + phpcompat.xml.dist | 2 +- phpcs.xml.dist | 2 +- 6 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 .cache/.gitkeep diff --git a/.cache/.gitkeep b/.cache/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 95e2af01721d..a5b1e53f212d 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -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. @@ -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: diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index 82202829ef53..6848465b5028 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -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' @@ -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. @@ -69,6 +70,18 @@ jobs: php --version composer --version + # 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: diff --git a/.gitignore b/.gitignore index ca946e1930c6..4fe178c594c7 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/phpcompat.xml.dist b/phpcompat.xml.dist index db47b0ea2654..fbc436cf0d29 100644 --- a/phpcompat.xml.dist +++ b/phpcompat.xml.dist @@ -11,7 +11,7 @@ - + - +