Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
package

GitHub Action

PHP Composer

v1

PHP Composer

package

PHP Composer

Use the Composer CLI in your Github Actions

Installation

Copy and paste the following snippet into your .yml file.

              

- name: PHP Composer

uses: baschny/php-composer-action@v1

Learn more about this action in baschny/php-composer-action

Choose a version

baschny/php-composer-action

This GitHub action allows to run the latest composer on your source code.

It uses the official composer docker image and allows efficient caching of downloaded assets.

Input

  • composer_version: Major version to install. Basically any tag name from https://hub.docker.com/_/composer - i.e. 1 or 2. Defaults to latest.

  • command: The composer command to run, defaults to install. Set to get_config to only generate the output variables of the composer setup (for use in cache, see example below)

  • args: Other command line arguments to pass to composer, defaults to --optimize-autoloader --no-progress

  • github_oauth: If your composer needs access to a private repo, configure the github OAuth token to use here. For example it could come from a secret, i.e. secrets.GITHUB_OAUTH.

Output

  • composer_cache_dir: where the composer cache is located, in case you want to use actions/cache

  • composer_major_version: the detected major version of composer, useful to have a separate cache tag based on this, since there can be slight differences in the caches between major versions.

  • composer_version: the exact composer version, in case you want to output this somewhere.

Example Workflow

name: PHP Building Workflow

on: [push]

jobs:

  composer_install:
    runs-on: ubuntu-latest

    env:
      COMPOSER_VERSION: 1

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Get composer cache directory
        id: composer_config
        uses: baschny/php-composer-action@v1
        with:
          composer_version: ${{ env.COMPOSER_VERSION }}
          command: get_config

      - name: Cache composer downloads
        uses: actions/cache@v2
        with:
          path: ${{ steps.composer_config.outputs.composer_cache_dir }}
          key: composer-v${{ steps.composer_config.outputs.composer_major_version }}

      - name: Run composer install
        uses: baschny/php-composer-action@v1
        with:
          composer_version: ${{ env.COMPOSER_VERSION }}
          command: install
          #github_oauth: ${{ secret.GITHUB_OAUTH }}

License

See LICENSE file.

See also

The idea came after some brainstorming in https://github.com/php-actions/composer.

Author

Ernesto Baschny, cron IT GmbH