2024-09-14 20:17:44 +02:00
2024-09-14 16:44:18 +00:00
2024-09-14 20:17:44 +02:00

Setup Composer Action

This action sets up and installs Composer dependencies for PHP projects, with caching to speed up builds by reusing previously installed dependencies. It includes customizable installation arguments and file hashing for cache keys.

Action Overview

  • Name: Setup Composer
  • Description: Install and cache Composer dependencies for PHP projects.

Inputs

  • args (optional):

    • Type: string
    • Default: --verbose --prefer-dist --no-progress --no-interaction --optimize-autoloader --ignore-platform-reqs
    • Description: Arguments passed to the composer install command. This allows for customizing how Composer installs the project's dependencies.
  • file (optional):

    • Type: string
    • Default: **/composer.lock
    • Description: Specifies the file to be hashed for the cache key. By default, it uses the composer.lock file, which reflects dependency versions.

Usage Example

Heres an example of how to use this action in a workflow to install Composer dependencies and cache them based on the composer.lock file:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Setup Composer Dependencies
        uses: your-repo/setup-composer-action@v1
        with:
          args: '--no-dev --optimize-autoloader'
          file: 'composer.lock'

In this example, the action will install Composer dependencies without development dependencies, using the composer.lock file to manage caching.

Action Workflow

This action is executed as a composite action with the following steps:

Steps

  1. Checkout Code:

    • Action: actions/checkout@v4
    • Description: Checks out the project code so that Composer can install dependencies based on the composer.json and composer.lock files.
  2. Authenticate Registry:

    • Run Command:
      composer config --global http-basic.git.qlic.nl ${{ vars.REGISTRY_USERNAME }} ${{ vars.REGISTRY_PASSWORD }}
      
    • Description: Configures Composer to authenticate against a private registry using the provided credentials.
  3. Get Composer Cache Directory:

    • Run Command:
      echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
      
    • Description: Retrieves the Composer cache directory path and stores it in the GITHUB_OUTPUT for later use in caching.
  4. Cache Composer Dependencies:

    • Action: actions/cache@v4
    • Description: Caches the Composer dependencies based on the hashed file provided (composer.lock by default). The cache is restored if available, speeding up future builds.
    • Key: ${{ runner.os }}-composer-${{ hashFiles(inputs.file) }}
    • Restore Keys: ${{ runner.os }}-composer-
  5. Install Composer Dependencies:

    • Run Command:
      composer install ${{ inputs.args }}
      
    • Description: Runs the composer install command with the provided args to install the project's dependencies, optimizing for performance based on the specified arguments.
Description
Installs composer dependencies and caches them
Readme 52 KiB
v1 Latest
2025-02-05 18:33:08 +00:00