From 563a4c3e08ee2791a32a91c92d6270eee3f9ae3b Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Tue, 5 Jan 2021 19:21:50 +0000 Subject: [PATCH] Build/Test Tools: Simplify Composer package caching. This simplifies the caching of Composer dependencies in the coding standards and PHP compatibility workflows by using a published action. This combines 3 steps into 1 within these workflows. Because the Composer implementation within the PHPUnit test workflow is a bit specialized (`composer install` is run within the Docker container), caching has been left as is in that workflow. However, the cache key has been changed to include the version of PHP being tested. This will prevent incorrect versions of dependencies being present when they are required on jobs other than PHP 8. Props jrf. See #50401. git-svn-id: https://develop.svn.wordpress.org/trunk@49938 602fd350-edb4-49c9-b593-d223f7449a82 --- .github/workflows/coding-standards.yml | 27 ++++++++----------------- .github/workflows/php-compatibility.yml | 27 ++++++++----------------- .github/workflows/phpunit-tests.yml | 4 ++-- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index e14eecc141..83097a158d 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -16,10 +16,10 @@ jobs: # # Performs the following steps: # - Checks out the repository. - # - Configures caching for Composer. # - Sets up PHP. # - Logs debug information. - # - Installs Composer dependencies (from cache if possible). + # - Installs Composer dependencies (use cache if possible). + # - Make Composer packages available globally. # - Logs PHP_CodeSniffer debug information. # - Runs PHPCS on the full codebase with warnings suppressed. # - Runs PHPCS on the `tests` directory without warnings suppressed. @@ -33,20 +33,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Get Composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Set up Composer caching - uses: actions/cache@v2 - env: - cache-name: cache-composer-dependencies - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - name: Set up PHP uses: shivammathur/setup-php@v2 with: @@ -60,9 +46,12 @@ jobs: composer --version - name: Install Composer dependencies - run: | - composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction - echo "${PWD}/vendor/bin" >> $GITHUB_PATH + uses: ramsey/composer-install@v1 + with: + composer-options: "--no-progress --no-ansi --no-interaction" + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH - name: Log PHPCS debug information run: phpcs -i diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index a3915189ab..6c3fb82ceb 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -17,10 +17,10 @@ jobs: # # Performs the following steps: # - Checks out the repository. - # - Configures caching for Composer. # - Sets up PHP. # - Logs debug information about the runner container. - # - Installs Composer dependencies (from cache if possible). + # - Installs Composer dependencies (use cache if possible). + # - Make Composer packages available globally. # - Logs PHP_CodeSniffer debug information. # - Runs the PHP compatibility tests. # - todo: Configure Slack notifications for failing scans. @@ -33,20 +33,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Get Composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Set up Composer caching - uses: actions/cache@v2 - env: - cache-name: cache-composer-dependencies - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - name: Set up PHP uses: shivammathur/setup-php@v2 with: @@ -60,9 +46,12 @@ jobs: composer --version - name: Install Composer dependencies - run: | - composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction - echo "${PWD}/vendor/bin" >> $GITHUB_PATH + uses: ramsey/composer-install@v1 + with: + composer-options: "--no-progress --no-ansi --no-interaction" + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH - name: Log PHPCS debug information run: phpcs -i diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 89941a6ff9..0d14901f5e 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -191,9 +191,9 @@ jobs: cache-name: cache-composer-dependencies with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: | - ${{ runner.os }}-composer- + ${{ runner.os }}-php-${{ matrix.php }}-composer- - name: Install Composer dependencies if: ${{ env.COMPOSER_INSTALL == true || env.LOCAL_PHP == '8.0-fpm' }}