From 33af39335e56c4586771a556adb34c2991bc3389 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 25 Feb 2021 20:47:28 +0000 Subject: [PATCH] Build/Test Tools: Prevent the NPM/Composer caches in GitHub Actions from snowballing. The `actions/cache` GitHub action uses a `key` input to find the desired cache in storage. Currently, this is defined as a combination of the operating system being used, the software being cached (NPM or Composer), PHP version (Composer only), and a hash of the relevant lock file. The `cache` action also supports a `restore-keys` input, which is an ordered list of keys to use for restoring a cache if no cache hit occurred for the specified key. However, this means that every time a lock file is updated, the cache is being recreated by first restoring a previous one (when available), and then installing new versions of dependencies on top of that. This results in old, unused versions of dependencies never being removed from the cache. In this change, the `restore-keys` are removed. This will force a new, fresh cache to be generated when the desired `key` is not matched. In testing, this results in a ~40% reduction in cache size when compared to the latest successful workflow runs. Since there is no way to manually flush the cache in GHA, the benefits of this change will not be seen until the `package-lock.json` and `composer.lock` files are updated, or the cache at the desired key is evicted. Props johbillion. See #52660. git-svn-id: https://develop.svn.wordpress.org/trunk@50436 602fd350-edb4-49c9-b593-d223f7449a82 --- .github/workflows/coding-standards.yml | 2 -- .github/workflows/end-to-end-tests.yml | 2 -- .github/workflows/javascript-tests.yml | 2 -- .github/workflows/phpunit-tests.yml | 6 ------ .github/workflows/test-coverage.yml | 2 -- .github/workflows/verify-npm-on-windows.yml | 2 -- 6 files changed, 16 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index e5117f737d..4c88c9e53c 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -114,8 +114,6 @@ jobs: # npm cache files are stored in `~/.npm` on Linux/macOS path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-npm- - name: Log debug information run: | diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml index f99d5ead10..40f3fc46d0 100644 --- a/.github/workflows/end-to-end-tests.yml +++ b/.github/workflows/end-to-end-tests.yml @@ -82,8 +82,6 @@ jobs: # npm cache files are stored in `~/.npm` on Linux/macOS path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-npm- - name: Install Dependencies run: npx install-changed --install-command="npm ci" diff --git a/.github/workflows/javascript-tests.yml b/.github/workflows/javascript-tests.yml index b873c5ac33..8e44a4455f 100644 --- a/.github/workflows/javascript-tests.yml +++ b/.github/workflows/javascript-tests.yml @@ -64,8 +64,6 @@ jobs: # npm cache files are stored in `~/.npm` on Linux/macOS path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-npm- - name: Log debug information run: | diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 3fabb20e2d..d41c4f9412 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -80,8 +80,6 @@ jobs: # npm cache files are stored in `~/.npm` on Linux/macOS path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-npm- - name: Install Dependencies run: npx install-changed --install-command="npm ci" @@ -186,8 +184,6 @@ jobs: # npm cache files are stored in `~/.npm` on Linux/macOS path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-npm- - name: Install Dependencies run: npx install-changed --install-command="npm ci" @@ -205,8 +201,6 @@ jobs: with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php-${{ matrix.php }}-composer- - name: Install Composer dependencies if: ${{ env.COMPOSER_INSTALL == true || env.LOCAL_PHP == '8.0-fpm' }} diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index 96c1a2761f..8fe9054a49 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -81,8 +81,6 @@ jobs: # npm cache files are stored in `~/.npm` on Linux/macOS path: ~/.npm key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-npm- - name: Install Dependencies run: npx install-changed --install-command="npm ci" diff --git a/.github/workflows/verify-npm-on-windows.yml b/.github/workflows/verify-npm-on-windows.yml index fb4218c681..c22e3596c0 100644 --- a/.github/workflows/verify-npm-on-windows.yml +++ b/.github/workflows/verify-npm-on-windows.yml @@ -65,8 +65,6 @@ jobs: with: path: ${{ steps.npm-cache.outputs.dir }} key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-npm- - name: Install Dependencies run: npx install-changed --install-command="npm ci"