Skip to content

Commit be4d170

Browse files
author
Greg Bowler
committed
Document caching
1 parent 9754dde commit be4d170

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

README.md

+55-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,63 @@ jobs:
2323

2424
steps:
2525
- uses: actions/checkout@v1
26-
- uses: phpactions/composer@master
26+
- uses: php-actions/composer@v1
2727
# ... then your own project steps ...
2828
```
2929

30+
Running custom commands
31+
-----------------------
32+
33+
By default, adding `- uses: php-actions/composer@v1` into your workflow will run `composer install`, as `install` is the default command name.
34+
35+
You can issue custom commands by passing a `command` input, like so:
36+
37+
```yaml
38+
...
39+
40+
jobs:
41+
build:
42+
43+
...
44+
45+
- name: Install dependencies
46+
uses: php-actions/composer@v1
47+
with:
48+
command: your-command-here
49+
```
50+
51+
Caching dependencies for faster builds
52+
--------------------------------------
53+
54+
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.
55+
56+
Example workflow (taken from https://github.com/PhpGt/Dom):
57+
58+
```yaml
59+
name: CI
60+
61+
on: [push]
62+
63+
jobs:
64+
build:
65+
runs-on: [ubuntu-latest]
66+
67+
steps:
68+
- uses: actions/checkout@v1
69+
70+
- name: Cache PHP dependencies
71+
uses: actions/cache@v1
72+
with:
73+
path: vendor
74+
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
75+
76+
- uses: php-actions/composer@master
77+
78+
...
79+
```
80+
81+
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.
82+
3083
[php-actions-phpunit]: https://github.com/marketplace/actions/phpunit-php-actions
3184
[php-actions-phpspec]: https://github.com/marketplace/actions/phpspec-php-actions
32-
[php-actions-behat]: https://github.com/marketplace/actions/behat-php-actions
85+
[php-actions-behat]: https://github.com/marketplace/actions/behat-php-actions

0 commit comments

Comments
 (0)