Make WordPress Core


Ignore:
Timestamp:
11/18/2022 02:50:52 PM (2 years ago)
Author:
desrosj
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/test-coverage.yml

    r54851 r54856  
    3939  # - Checks out the repository.
    4040  # - Sets up Node.js.
     41  # - Sets up PHP.
     42  # - Installs Composer dependencies.
     43  # - Installs npm dependencies
    4144  # - Logs general debug information about the runner.
    42   # - Installs npm dependencies
    43   # - Configures caching for Composer.
    44   # - Installs Composer dependencies.
    4545  # - Logs Docker debug information (about the Docker installation within the runner).
    4646  # - Starts the WordPress Docker container.
     
    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: |
     
    88111          git --version
    89112          svn --version
     113          composer --version
    90114          locale -a
    91 
    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
    119115
    120116      - name: Docker debug information
Note: See TracChangeset for help on using the changeset viewer.