Skip to content

Commit 193e240

Browse files
authored
Recommend caching COMPOSER_CACHE_DIR over vendor/
Caching the vendor directory as-is could produce various unwanted and hard to debug problems. For example: - vendor/autoload* would not be dumped again based on new changes to code and composer.json configuration - vendor/installed.json would not be updated with changes to Composer version See this thread which caused github.com/actions/cache to recommend not caching vendor, but instead cache the Composer cache dir: actions/cache#32 (comment) which is based on travis-ci/travis-ci#4579 (comment)
1 parent be4d170 commit 193e240

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
Caching dependencies for faster builds
5252
--------------------------------------
5353
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.
54+
Github actions supports dependency caching, allowing Composer downloads 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 download files over the network at all if the cache is valid.
5555

5656
Example workflow (taken from https://github.com/PhpGt/Dom):
5757

@@ -66,6 +66,19 @@ jobs:
6666
6767
steps:
6868
- uses: actions/checkout@v1
69+
70+
- name: Get Composer Cache Directory
71+
id: composer-cache
72+
run: |
73+
echo "::set-output name=dir::$(composer config cache-files-dir)"
74+
75+
- name: Cache Composer Downloads
76+
uses: actions/cache@v1
77+
with:
78+
path: ${{ steps.composer-cache.outputs.dir }}
79+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
80+
restore-keys: |
81+
${{ runner.os }}-composer-
6982
7083
- name: Cache PHP dependencies
7184
uses: actions/cache@v1
@@ -78,7 +91,7 @@ jobs:
7891
...
7992
```
8093

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.
94+
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 Composer cache directory will be persisted between workflows.
8295

8396
[php-actions-phpunit]: https://github.com/marketplace/actions/phpunit-php-actions
8497
[php-actions-phpspec]: https://github.com/marketplace/actions/phpspec-php-actions

0 commit comments

Comments
 (0)