Composer (php-actions)
ActionsTags
(2)Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
If you are running tests like PHPUnit, phpspec or Behat in your Github actions, chances are you will need to install your project's dependencies using Composer.
Create your Github Workflow configuration in .github/workflows/ci.yml
or similar.
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: php-actions/composer@v1
# ... then your own project steps ...
By default, adding - uses: php-actions/composer@v1
into your workflow will run composer install
, as install
is the default command name.
You can issue custom commands by passing a command
input, like so:
...
jobs:
build:
...
- name: Install dependencies
uses: php-actions/composer@v1
with:
command: your-command-here
Github actions supports dependency caching, allowing the vendor/
directory contents to be cached between workflows, as long as the composer.lock
file has not changed. This produces much faster builds, as the composer install
command does not have to be run at all if the cache is valid.
Example workflow (taken from https://github.com/PhpGt/Dom):
name: CI
on: [push]
jobs:
build:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v1
- name: Cache PHP dependencies
uses: actions/cache@v1
with:
path: vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
- uses: php-actions/composer@master
...
In the example above, the "key" is passed to the Cache action that consists of a hash of the composer.lock file. This means that as long as the contents of composer.lock doesn't change between workflows, the vendor directory will be persisted between workflows.
Composer (php-actions) is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.