GitHub Action
PHP Composer
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.
-
composer_version
: Major version to install. Basically any tag name from https://hub.docker.com/_/composer - i.e.1
or2
. Defaults tolatest
. -
command
: The composer command to run, defaults toinstall
. Set toget_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
.
-
composer_cache_dir
: where the composer cache is located, in case you want to useactions/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.
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 }}
See LICENSE file.
The idea came after some brainstorming in https://github.com/php-actions/composer.
Ernesto Baschny, cron IT GmbH