From be4d170aebb14d45c0931c0af5760234927c1754 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Sun, 8 Dec 2019 13:09:04 +0000 Subject: [PATCH] Document caching --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0db775d..afc7c9b 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,63 @@ jobs: steps: - uses: actions/checkout@v1 - - uses: phpactions/composer@master + - uses: php-actions/composer@v1 # ... then your own project steps ... ``` +Running custom commands +----------------------- + +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: + +```yaml +... + +jobs: + build: + + ... + + - name: Install dependencies + uses: php-actions/composer@v1 + with: + command: your-command-here +``` + +Caching dependencies for faster builds +-------------------------------------- + +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): + +```yaml +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. + [php-actions-phpunit]: https://github.com/marketplace/actions/phpunit-php-actions [php-actions-phpspec]: https://github.com/marketplace/actions/phpspec-php-actions -[php-actions-behat]: https://github.com/marketplace/actions/behat-php-actions \ No newline at end of file +[php-actions-behat]: https://github.com/marketplace/actions/behat-php-actions