mirror of
https://github.com/actions/cache.git
synced 2025-03-13 11:47:00 +00:00
Update yarn example
The yarn-cache directory will grow infinitely big if it is restored every run and never cleared. A large cache will slow down builds, and might lead to increased storage costs. GitHub also offers no way to manually purge the cache, so there is no manual workaround either. I choose weekly since I figured it's long enough have cache hits for most builds, but not too long for the cache to grow gigantic.
This commit is contained in:
parent
0781355a23
commit
5838d7f7d1
1 changed files with 8 additions and 1 deletions
|
@ -225,11 +225,18 @@ The yarn cache directory will depend on your operating system and version of `ya
|
||||||
id: yarn-cache-dir-path
|
id: yarn-cache-dir-path
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||||
|
|
||||||
|
# Use week number for automatically purging the cache every week. This is
|
||||||
|
# useful because caching yarn-cache would otherwise lead it to grow
|
||||||
|
# indefinitely since old dependencies are never purged.
|
||||||
|
- name: Get week number
|
||||||
|
id: week-number
|
||||||
|
run: echo "::set-output name=value::$(date +%W)"
|
||||||
|
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v2
|
||||||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
key: ${{ runner.os }}-${{ steps.week-number.outputs.value }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-yarn-
|
${{ runner.os }}-yarn-
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Reference in a new issue