WordPress.org

Make WordPress Core

Changeset 50436


Ignore:
Timestamp:
02/25/2021 08:47:28 PM (7 months ago)
Author:
desrosj
Message:

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.

Location:
trunk/.github/workflows
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/coding-standards.yml

    r50432 r50436  
    115115          path: ~/.npm
    116116          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    117           restore-keys: |
    118             ${{ runner.os }}-npm-
    119117
    120118      - name: Log debug information
  • trunk/.github/workflows/end-to-end-tests.yml

    r50432 r50436  
    8383          path: ~/.npm
    8484          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    85           restore-keys: |
    86             ${{ runner.os }}-npm-
    8785
    8886      - name: Install Dependencies
  • trunk/.github/workflows/javascript-tests.yml

    r50432 r50436  
    6565          path: ~/.npm
    6666          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    67           restore-keys: |
    68             ${{ runner.os }}-npm-
    6967
    7068      - name: Log debug information
  • trunk/.github/workflows/phpunit-tests.yml

    r50435 r50436  
    8181          path: ~/.npm
    8282          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    83           restore-keys: |
    84             ${{ runner.os }}-npm-
    8583
    8684      - name: Install Dependencies
     
    187185          path: ~/.npm
    188186          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    189           restore-keys: |
    190             ${{ runner.os }}-npm-
    191187
    192188      - name: Install Dependencies
     
    206202          path: ${{ steps.composer-cache.outputs.dir }}
    207203          key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
    208           restore-keys: |
    209             ${{ runner.os }}-php-${{ matrix.php }}-composer-
    210204
    211205      - name: Install Composer dependencies
  • trunk/.github/workflows/test-coverage.yml

    r50387 r50436  
    8282          path: ~/.npm
    8383          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    84           restore-keys: |
    85             ${{ runner.os }}-npm-
    8684
    8785      - name: Install Dependencies
  • trunk/.github/workflows/verify-npm-on-windows.yml

    r50432 r50436  
    6666          path: ${{ steps.npm-cache.outputs.dir }}
    6767          key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    68           restore-keys: |
    69             ${{ runner.os }}-npm-
    7068
    7169      - name: Install Dependencies
Note: See TracChangeset for help on using the changeset viewer.