Skip to content

Commit 4b59315

Browse files
committed
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
1 parent acbbee8 commit 4b59315

File tree

4 files changed

+63
-71
lines changed

4 files changed

+63
-71
lines changed

.github/workflows/coding-standards.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ jobs:
5656
# - Runs PHPCS on the `tests` directory without warnings suppressed.
5757
# - Generate a report for displaying `test` directory issues as pull request annotations.
5858
# - Ensures version-controlled files are not modified or deleted.
59-
6059
phpcs:
6160
name: PHP coding standards
6261
runs-on: ubuntu-latest
@@ -72,7 +71,7 @@ jobs:
7271
with:
7372
php-version: '7.4'
7473
coverage: none
75-
tools: composer, cs2pr
74+
tools: cs2pr
7675

7776
# This date is used to ensure that the PHPCS cache is cleared at least once every week.
7877
# http://man7.org/linux/man-pages/man1/date.1.html
@@ -86,10 +85,12 @@ jobs:
8685
path: .cache/phpcs.json
8786
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }}
8887

88+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
89+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
8990
- name: Install Composer dependencies
9091
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
9192
with:
92-
composer-options: "--no-progress --no-ansi"
93+
custom-cache-suffix: ${{ steps.get-date.outputs.date }}
9394

9495
- name: Make Composer packages available globally
9596
run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH

.github/workflows/php-compatibility.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
with:
6767
php-version: '7.4'
6868
coverage: none
69-
tools: composer, cs2pr
69+
tools: cs2pr
7070

7171
- name: Log debug information
7272
run: |
@@ -84,10 +84,12 @@ jobs:
8484
path: .cache/phpcompat.json
8585
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcompat-cache-${{ hashFiles('**/composer.json', 'phpcompat.xml.dist') }}
8686

87+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
88+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
8789
- name: Install Composer dependencies
8890
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
8991
with:
90-
composer-options: "--no-progress --no-ansi"
92+
custom-cache-suffix: ${{ steps.get-date.outputs.date }}
9193

9294
- name: Make Composer packages available globally
9395
run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH

.github/workflows/phpunit-tests.yml

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
# - Sets environment variables.
3939
# - Checks out the repository.
4040
# - Sets up Node.js.
41-
# - Logs general debug information about the runner.
42-
# - Installs npm dependencies
43-
# - Configures caching for Composer.
41+
# - Sets up PHP.
4442
# - Installs Composer dependencies.
43+
# - Installs npm dependencies
44+
# - Logs general debug information about the runner.
4545
# - Logs Docker debug information (about the Docker installation within the runner).
4646
# - Starts the WordPress Docker container.
4747
# - Logs the running Docker containers.
@@ -112,45 +112,38 @@ jobs:
112112
node-version-file: '.nvmrc'
113113
cache: npm
114114

115+
##
116+
# This allows Composer dependencies to be installed using a single step.
117+
#
118+
# Since the tests are currently run within the Docker containers where the PHP version varies,
119+
# the same PHP version needs to be configured for the action runner machine so that the correct
120+
# dependency versions are installed and cached.
121+
##
122+
- name: Set up PHP
123+
uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0
124+
with:
125+
php-version: '${{ matrix.php }}'
126+
coverage: none
127+
128+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
129+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
130+
- name: Install Composer dependencies
131+
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
132+
with:
133+
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
134+
135+
- name: Install npm dependencies
136+
run: npm ci
137+
115138
- name: General debug information
116139
run: |
117140
npm --version
118141
node --version
119142
curl --version
120143
git --version
121144
svn --version
122-
123-
- name: Install npm dependencies
124-
run: npm ci
125-
126-
# This date is used to ensure that the Composer cache is refreshed at least once every week.
127-
# http://man7.org/linux/man-pages/man1/date.1.html
128-
- name: "Get last Monday's date"
129-
id: get-date
130-
run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT
131-
132-
- name: Get Composer cache directory
133-
id: composer-cache
134-
run: echo "composer_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
135-
136-
- name: Cache Composer dependencies
137-
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
138-
env:
139-
cache-name: cache-composer-dependencies
140-
with:
141-
path: ${{ steps.composer-cache.outputs.composer_dir }}
142-
key: ${{ runner.os }}-php-${{ matrix.php }}-date-${{ steps.get-date.outputs.date }}-composer-${{ hashFiles('**/composer.json') }}
143-
144-
- name: Install Composer dependencies
145-
run: |
146-
docker-compose run --rm php composer --version
147-
148-
# Install using `composer update` as there is no `composer.lock` file.
149-
if [ ${{ env.LOCAL_PHP }} == '8.2-fpm' ]; then
150-
docker-compose run --rm php composer update --ignore-platform-req=php+
151-
else
152-
docker-compose run --rm php composer update
153-
fi
145+
composer --version
146+
locale -a
154147
155148
- name: Docker debug information
156149
run: |

.github/workflows/test-coverage.yml

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
# - Sets environment variables.
3939
# - Checks out the repository.
4040
# - Sets up Node.js.
41-
# - Logs general debug information about the runner.
42-
# - Installs npm dependencies
43-
# - Configures caching for Composer.
41+
# - Sets up PHP.
4442
# - Installs Composer dependencies.
43+
# - Installs npm dependencies
44+
# - Logs general debug information about the runner.
4545
# - Logs Docker debug information (about the Docker installation within the runner).
4646
# - Starts the WordPress Docker container.
4747
# - Logs the running Docker containers.
@@ -78,6 +78,29 @@ jobs:
7878
node-version-file: '.nvmrc'
7979
cache: npm
8080

81+
##
82+
# This allows Composer dependencies to be installed using a single step.
83+
#
84+
# Since the tests are currently run within the Docker containers where the PHP version varies,
85+
# the same PHP version needs to be configured for the action runner machine so that the correct
86+
# dependency versions are installed and cached.
87+
##
88+
- name: Set up PHP
89+
uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2.22.0
90+
with:
91+
php-version: '7.4'
92+
coverage: none
93+
94+
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
95+
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
96+
- name: Install Composer dependencies
97+
uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
98+
with:
99+
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
100+
101+
- name: Install npm Dependencies
102+
run: npm ci
103+
81104
- name: Log debug information
82105
run: |
83106
echo "$GITHUB_REF"
@@ -87,36 +110,9 @@ jobs:
87110
curl --version
88111
git --version
89112
svn --version
113+
composer --version
90114
locale -a
91115
92-
- name: Install npm Dependencies
93-
run: npm ci
94-
95-
# This date is used to ensure that the Composer cache is refreshed at least once every week.
96-
# http://man7.org/linux/man-pages/man1/date.1.html
97-
- name: "Get last Monday's date"
98-
id: get-date
99-
run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT
100-
101-
- name: Get Composer cache directory
102-
id: composer-cache
103-
run: echo "composer_dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
104-
105-
- name: Cache Composer dependencies
106-
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
107-
env:
108-
cache-name: cache-composer-dependencies
109-
with:
110-
path: ${{ steps.composer-cache.outputs.composer_dir }}
111-
key: ${{ runner.os }}-php-${{ matrix.php }}-date-${{ steps.get-date.outputs.date }}-composer-${{ hashFiles('**/composer.json') }}
112-
113-
- name: Install Composer dependencies
114-
run: |
115-
docker-compose run --rm php composer --version
116-
117-
# Install using `composer update` as there is no `composer.lock` file.
118-
docker-compose run --rm php composer update
119-
120116
- name: Docker debug information
121117
run: |
122118
docker -v

0 commit comments

Comments
 (0)