<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[54856] trunk/.github/workflows: Build/Test Tools: Improve how Composer dependencies are installed.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/54856">54856</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/54856","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>desrosj</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-11-18 14:50:52 +0000 (Fri, 18 Nov 2022)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/53841">#53841</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkgithubworkflowscodingstandardsyml">trunk/.github/workflows/coding-standards.yml</a></li>
<li><a href="#trunkgithubworkflowsphpcompatibilityyml">trunk/.github/workflows/php-compatibility.yml</a></li>
<li><a href="#trunkgithubworkflowsphpunittestsyml">trunk/.github/workflows/phpunit-tests.yml</a></li>
<li><a href="#trunkgithubworkflowstestcoverageyml">trunk/.github/workflows/test-coverage.yml</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkgithubworkflowscodingstandardsyml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/.github/workflows/coding-standards.yml</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/.github/workflows/coding-standards.yml      2022-11-17 18:13:47 UTC (rev 54855)
+++ trunk/.github/workflows/coding-standards.yml        2022-11-18 14:50:52 UTC (rev 54856)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,7 +56,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">   # - Runs PHPCS on the `tests` directory without warnings suppressed.
</span><span class="cx" style="display: block; padding: 0 10px">   # - Generate a report for displaying `test` directory issues as pull request annotations.
</span><span class="cx" style="display: block; padding: 0 10px">   # - Ensures version-controlled files are not modified or deleted.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px">   phpcs:
</span><span class="cx" style="display: block; padding: 0 10px">     name: PHP coding standards
</span><span class="cx" style="display: block; padding: 0 10px">     runs-on: ubuntu-latest
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -72,7 +71,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         with:
</span><span class="cx" style="display: block; padding: 0 10px">           php-version: '7.4'
</span><span class="cx" style="display: block; padding: 0 10px">           coverage: none
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-          tools: composer, cs2pr
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          tools: cs2pr
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">       # This date is used to ensure that the PHPCS cache is cleared at least once every week.
</span><span class="cx" style="display: block; padding: 0 10px">       # http://man7.org/linux/man-pages/man1/date.1.html
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -86,10 +85,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">           path: .cache/phpcs.json
</span><span class="cx" style="display: block; padding: 0 10px">           key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }}
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+      # 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.
</ins><span class="cx" style="display: block; padding: 0 10px">       - name: Install Composer dependencies
</span><span class="cx" style="display: block; padding: 0 10px">         uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
</span><span class="cx" style="display: block; padding: 0 10px">         with:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-          composer-options: "--no-progress --no-ansi"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          custom-cache-suffix: ${{ steps.get-date.outputs.date }}
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">       - name: Make Composer packages available globally
</span><span class="cx" style="display: block; padding: 0 10px">         run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH
</span></span></pre></div>
<a id="trunkgithubworkflowsphpcompatibilityyml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/.github/workflows/php-compatibility.yml</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/.github/workflows/php-compatibility.yml     2022-11-17 18:13:47 UTC (rev 54855)
+++ trunk/.github/workflows/php-compatibility.yml       2022-11-18 14:50:52 UTC (rev 54856)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,7 +66,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         with:
</span><span class="cx" style="display: block; padding: 0 10px">           php-version: '7.4'
</span><span class="cx" style="display: block; padding: 0 10px">           coverage: none
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-          tools: composer, cs2pr
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          tools: cs2pr
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">       - name: Log debug information
</span><span class="cx" style="display: block; padding: 0 10px">         run: |
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -84,10 +84,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">           path: .cache/phpcompat.json
</span><span class="cx" style="display: block; padding: 0 10px">           key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcompat-cache-${{ hashFiles('**/composer.json', 'phpcompat.xml.dist') }}
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+      # 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.
</ins><span class="cx" style="display: block; padding: 0 10px">       - name: Install Composer dependencies
</span><span class="cx" style="display: block; padding: 0 10px">         uses: ramsey/composer-install@83af392bf5f031813d25e6fe4cd626cdba9a2df6 # v2.2.0
</span><span class="cx" style="display: block; padding: 0 10px">         with:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-          composer-options: "--no-progress --no-ansi"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          custom-cache-suffix: ${{ steps.get-date.outputs.date }}
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">       - name: Make Composer packages available globally
</span><span class="cx" style="display: block; padding: 0 10px">         run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH
</span></span></pre></div>
<a id="trunkgithubworkflowsphpunittestsyml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/.github/workflows/phpunit-tests.yml</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/.github/workflows/phpunit-tests.yml 2022-11-17 18:13:47 UTC (rev 54855)
+++ trunk/.github/workflows/phpunit-tests.yml   2022-11-18 14:50:52 UTC (rev 54856)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -38,10 +38,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">   # - Sets environment variables.
</span><span class="cx" style="display: block; padding: 0 10px">   # - Checks out the repository.
</span><span class="cx" style="display: block; padding: 0 10px">   # - Sets up Node.js.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  # - Sets up PHP.
+  # - Installs Composer dependencies.
+  # - Installs npm dependencies
</ins><span class="cx" style="display: block; padding: 0 10px">   # - Logs general debug information about the runner.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-  # - Installs npm dependencies
-  # - Configures caching for Composer.
-  # - Installs Composer dependencies.
</del><span class="cx" style="display: block; padding: 0 10px">   # - Logs Docker debug information (about the Docker installation within the runner).
</span><span class="cx" style="display: block; padding: 0 10px">   # - Starts the WordPress Docker container.
</span><span class="cx" style="display: block; padding: 0 10px">   # - Logs the running Docker containers.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -112,6 +112,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">           node-version-file: '.nvmrc'
</span><span class="cx" style="display: block; padding: 0 10px">           cache: npm
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+      ##
+      # 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
+
</ins><span class="cx" style="display: block; padding: 0 10px">       - name: General debug information
</span><span class="cx" style="display: block; padding: 0 10px">         run: |
</span><span class="cx" style="display: block; padding: 0 10px">           npm --version
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -119,39 +142,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">           curl --version
</span><span class="cx" style="display: block; padding: 0 10px">           git --version
</span><span class="cx" style="display: block; padding: 0 10px">           svn --version
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          composer --version
+          locale -a
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-      - 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.
-          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
-
</del><span class="cx" style="display: block; padding: 0 10px">       - name: Docker debug information
</span><span class="cx" style="display: block; padding: 0 10px">         run: |
</span><span class="cx" style="display: block; padding: 0 10px">           docker -v
</span></span></pre></div>
<a id="trunkgithubworkflowstestcoverageyml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/.github/workflows/test-coverage.yml</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/.github/workflows/test-coverage.yml 2022-11-17 18:13:47 UTC (rev 54855)
+++ trunk/.github/workflows/test-coverage.yml   2022-11-18 14:50:52 UTC (rev 54856)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -38,10 +38,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">   # - Sets environment variables.
</span><span class="cx" style="display: block; padding: 0 10px">   # - Checks out the repository.
</span><span class="cx" style="display: block; padding: 0 10px">   # - Sets up Node.js.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  # - Sets up PHP.
+  # - Installs Composer dependencies.
+  # - Installs npm dependencies
</ins><span class="cx" style="display: block; padding: 0 10px">   # - Logs general debug information about the runner.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-  # - Installs npm dependencies
-  # - Configures caching for Composer.
-  # - Installs Composer dependencies.
</del><span class="cx" style="display: block; padding: 0 10px">   # - Logs Docker debug information (about the Docker installation within the runner).
</span><span class="cx" style="display: block; padding: 0 10px">   # - Starts the WordPress Docker container.
</span><span class="cx" style="display: block; padding: 0 10px">   # - Logs the running Docker containers.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,6 +78,29 @@
</span><span class="cx" style="display: block; padding: 0 10px">           node-version-file: '.nvmrc'
</span><span class="cx" style="display: block; padding: 0 10px">           cache: npm
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+      ##
+      # 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
+
</ins><span class="cx" style="display: block; padding: 0 10px">       - name: Log debug information
</span><span class="cx" style="display: block; padding: 0 10px">         run: |
</span><span class="cx" style="display: block; padding: 0 10px">           echo "$GITHUB_REF"
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -87,36 +110,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">           curl --version
</span><span class="cx" style="display: block; padding: 0 10px">           git --version
</span><span class="cx" style="display: block; padding: 0 10px">           svn --version
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          composer --version
</ins><span class="cx" style="display: block; padding: 0 10px">           locale -a
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-      - 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
-
</del><span class="cx" style="display: block; padding: 0 10px">       - name: Docker debug information
</span><span class="cx" style="display: block; padding: 0 10px">         run: |
</span><span class="cx" style="display: block; padding: 0 10px">           docker -v
</span></span></pre>
</div>
</div>

</body>
</html>