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.
- 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.lock
file, which reflects dependency versions.
- 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: 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
-
Checkout Code:
- Action:
actions/checkout@v4
- Description: Checks out the project code so that Composer can install dependencies based on the
composer.json
andcomposer.lock
files.
- 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_OUTPUT
for 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.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-
- Action:
-
Install Composer Dependencies:
- Run Command:
composer install ${{ inputs.args }}
- Description: Runs the
composer install
command with the providedargs
to install the project's dependencies, optimizing for performance based on the specified arguments.
- Run Command:
Description
v1
Latest