setup-composer/README.md

81 lines
3.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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.
- **packistry-token** (optional):
- **Type:** `string`
- **Default:** `pkdt-***`
- **Description:** Deploy token to authenticate with packistry
## 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:
```yaml
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
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:**
```bash
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:**
```bash
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:**
```bash
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.