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 installcommand. This allows for customizing how Composer installs the project's dependencies.
- Type:
-
file (optional):
- Type:
string - Default:
**/composer.lock - Description: Specifies the file to be hashed for the cache key. By default, it uses the
composer.lockfile, which reflects dependency versions.
- Type:
-
token (optional):
- Type:
string - Default:
pkdt-*** - Description: Deploy token to globally authenticate with packistry
- Type:
Usage Example
Here’s 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: https://git.qlic.nl/actions/setup-composer@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
-
Checkout Code:
- Action:
actions/checkout@v4 - Description: Checks out the project code so that Composer can install dependencies based on the
composer.jsonandcomposer.lockfiles.
- Action:
-
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.
- Run Command:
-
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_OUTPUTfor later use in caching.
- Run Command:
-
Cache Composer Dependencies:
- Action:
actions/cache@v4 - Description: Caches the Composer dependencies based on the hashed file provided (
composer.lockby default). The cache is restored if available, speeding up future builds. - Key:
${{ runner.os }}-composer-${{ hashFiles(inputs.file) }} - Restore Keys:
${{ runner.os }}-composer-
- Action:
-
Install Composer Dependencies:
- Run Command:
composer install ${{ inputs.args }} - Description: Runs the
composer installcommand with the providedargsto install the project's dependencies, optimizing for performance based on the specified arguments.
- Run Command: