Build/Test Tools: Improve how Composer dependencies are installed.

To improve how Composer dependencies are installed and managed within GitHub Actions, the `ramsey/composer-install` third-party action is now used consistently throughout all workflows.

Previously, some workflows manually ran `composer` commands while others already used `ramsey/composer-install`.

The `ramsey/composer-install` action manages caching dependencies across workflow runs internally, which is something that was manually handled before this change.

Props jrf, desrosj.
Fixes #53841.

git-svn-id: https://develop.svn.wordpress.org/trunk@54856 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2022-11-18 14:50:52 +00:00
parent acbbee8a11
commit 4b5931521b
4 changed files with 63 additions and 71 deletions

View File

@ -56,7 +56,6 @@ jobs:
# - Runs PHPCS on the `tests` directory without warnings suppressed. # - Runs PHPCS on the `tests` directory without warnings suppressed.
# - Generate a report for displaying `test` directory issues as pull request annotations. # - Generate a report for displaying `test` directory issues as pull request annotations.
# - Ensures version-controlled files are not modified or deleted. # - Ensures version-controlled files are not modified or deleted.
phpcs: phpcs:
name: PHP coding standards name: PHP coding standards
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -72,7 +71,7 @@ jobs:
with: with:
php-version: '7.4' php-version: '7.4'
coverage: none coverage: none
tools: composer, cs2pr tools: cs2pr
# This date is used to ensure that the PHPCS cache is cleared at least once every week. # 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 # http://man7.org/linux/man-pages/man1/date.1.html
@ -86,10 +85,12 @@ jobs:
path: .cache/phpcs.json path: .cache/phpcs.json
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }}
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
- name: Install Composer dependencies - name: Install Composer dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
with: with:
composer-options: "--no-progress --no-ansi" custom-cache-suffix: ${{ steps.get-date.outputs.date }}
- name: Make Composer packages available globally - name: Make Composer packages available globally
run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH

View File

@ -66,7 +66,7 @@ jobs:
with: with:
php-version: '7.4' php-version: '7.4'
coverage: none coverage: none
tools: composer, cs2pr tools: cs2pr
- name: Log debug information - name: Log debug information
run: | run: |
@ -84,10 +84,12 @@ jobs:
path: .cache/phpcompat.json path: .cache/phpcompat.json
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcompat-cache-${{ hashFiles('**/composer.json', 'phpcompat.xml.dist') }} key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcompat-cache-${{ hashFiles('**/composer.json', 'phpcompat.xml.dist') }}
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
- name: Install Composer dependencies - name: Install Composer dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0 uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
with: with:
composer-options: "--no-progress --no-ansi" custom-cache-suffix: ${{ steps.get-date.outputs.date }}
- name: Make Composer packages available globally - name: Make Composer packages available globally
run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH

View File

@ -38,10 +38,10 @@ jobs:
# - Sets environment variables. # - Sets environment variables.
# - Checks out the repository. # - Checks out the repository.
# - Sets up Node.js. # - Sets up Node.js.
# - Logs general debug information about the runner. # - Sets up PHP.
# - Installs npm dependencies
# - Configures caching for Composer.
# - Installs Composer dependencies. # - Installs Composer dependencies.
# - Installs npm dependencies
# - Logs general debug information about the runner.
# - Logs Docker debug information (about the Docker installation within the runner). # - Logs Docker debug information (about the Docker installation within the runner).
# - Starts the WordPress Docker container. # - Starts the WordPress Docker container.
# - Logs the running Docker containers. # - Logs the running Docker containers.
@ -112,6 +112,29 @@ jobs:
node-version-file: '.nvmrc' node-version-file: '.nvmrc'
cache: npm cache: npm
##
# This allows Composer dependencies to be installed using a single step.
#
# Since the tests are currently run within the Docker containers where the PHP version varies,
# the same PHP version needs to be configured for the action runner machine so that the correct
# dependency versions are installed and cached.
##
- name: Set up PHP
uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0
with:
php-version: '${{ matrix.php }}'
coverage: none
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
- name: Install Composer dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
with:
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
- name: Install npm dependencies
run: npm ci
- name: General debug information - name: General debug information
run: | run: |
npm --version npm --version
@ -119,38 +142,8 @@ jobs:
curl --version curl --version
git --version git --version
svn --version svn --version
composer --version
- name: Install npm dependencies locale -a
run: npm ci
# This date is used to ensure that the Composer cache is refreshed 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 "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT
- name: Get Composer cache directory
id: composer-cache
run: echo "composer_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.composer_dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-date-${{ steps.get-date.outputs.date }}-composer-${{ hashFiles('**/composer.json') }}
- name: Install Composer dependencies
run: |
docker-compose run --rm php composer --version
# Install using `composer update` as there is no `composer.lock` file.
if [ ${{ env.LOCAL_PHP }} == '8.2-fpm' ]; then
docker-compose run --rm php composer update --ignore-platform-req=php+
else
docker-compose run --rm php composer update
fi
- name: Docker debug information - name: Docker debug information
run: | run: |

View File

@ -38,10 +38,10 @@ jobs:
# - Sets environment variables. # - Sets environment variables.
# - Checks out the repository. # - Checks out the repository.
# - Sets up Node.js. # - Sets up Node.js.
# - Logs general debug information about the runner. # - Sets up PHP.
# - Installs npm dependencies
# - Configures caching for Composer.
# - Installs Composer dependencies. # - Installs Composer dependencies.
# - Installs npm dependencies
# - Logs general debug information about the runner.
# - Logs Docker debug information (about the Docker installation within the runner). # - Logs Docker debug information (about the Docker installation within the runner).
# - Starts the WordPress Docker container. # - Starts the WordPress Docker container.
# - Logs the running Docker containers. # - Logs the running Docker containers.
@ -78,6 +78,29 @@ jobs:
node-version-file: '.nvmrc' node-version-file: '.nvmrc'
cache: npm cache: npm
##
# This allows Composer dependencies to be installed using a single step.
#
# Since the tests are currently run within the Docker containers where the PHP version varies,
# the same PHP version needs to be configured for the action runner machine so that the correct
# dependency versions are installed and cached.
##
- name: Set up PHP
uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0
with:
php-version: '7.4'
coverage: none
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
- name: Install Composer dependencies
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
with:
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
- name: Install npm Dependencies
run: npm ci
- name: Log debug information - name: Log debug information
run: | run: |
echo "$GITHUB_REF" echo "$GITHUB_REF"
@ -87,36 +110,9 @@ jobs:
curl --version curl --version
git --version git --version
svn --version svn --version
composer --version
locale -a locale -a
- name: Install npm Dependencies
run: npm ci
# This date is used to ensure that the Composer cache is refreshed 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 "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT
- name: Get Composer cache directory
id: composer-cache
run: echo "composer_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.composer_dir }}
key: ${{ runner.os }}-php-${{ matrix.php }}-date-${{ steps.get-date.outputs.date }}-composer-${{ hashFiles('**/composer.json') }}
- name: Install Composer dependencies
run: |
docker-compose run --rm php composer --version
# Install using `composer update` as there is no `composer.lock` file.
docker-compose run --rm php composer update
- name: Docker debug information - name: Docker debug information
run: | run: |
docker -v docker -v