Update readme and examples to use v2

This commit is contained in:
Aiqiao Yan 2020-05-26 12:45:38 -04:00
parent 9ab95382c8
commit 581312be20
2 changed files with 120 additions and 71 deletions

View file

@ -8,6 +8,58 @@ This action allows caching dependencies and build outputs to improve workflow ex
See ["Caching dependencies to speed up workflows"](https://help.github.com/github/automating-your-workflow-with-github-actions/caching-dependencies-to-speed-up-workflows).
## What's New in V2
* Added support for caching multiple paths,
```yaml
- name: Cache multiple relative paths
uses: actions/cache@v2
with:
path: |
node_modules
dist
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
```yaml
- name: Cache multiple absolute paths
uses: actions/cache@v2
with:
path: |
~/cache
/path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
[glob patterns](https://github.com/actions/toolkit/tree/master/packages/glob),
```yaml
- name: Cache using glob patterns
uses: actions/cache@v2
with:
path: |
**/*.ts
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
and single file caches.
```yaml
- name: Cache single file
uses: actions/cache@v2
with:
path: cache.tar
key: ${{ runner.os }}
```
* Increased perfomance and improved cache sizes using `zstd` compression
> Note this feature is off for Windows runner that are using `bsdtar` (e.g., windows-latest hosted runner) due to a bug in ziping large random files with `bsdtar`
* Allowed caching for all events with a ref
> See [events that trigger workflow](https://help.github.com/en/actions/reference/events-that-trigger-workflows) for info on which events do not have a `GITHUB_REF`
* Released the [`@actions/cache`](https://github.com/actions/toolkit/tree/master/packages/cache) npm package to allow other actions to utilize caching
* Added a best-effort cleanup step to delete the archive after extraction to reduce storage space
## Usage
### Pre-requisites
@ -15,7 +67,8 @@ Create a workflow `.yml` file in your repositories `.github/workflows` directory
### Inputs
* `path` - A directory to store and save the cache
* `path` - Directories to store and save the cache. Supports pattern matching, multipath and single file cache
> See [`@actions/glob`](https://github.com/actions/toolkit/tree/master/packages/glob) for supported patterns.
* `key` - An explicit key for restoring and saving the cache
* `restore-keys` - An ordered list of keys to use for restoring the cache if no cache hit occurred for key
@ -46,7 +99,7 @@ jobs:
- name: Cache Primes
id: cache-primes
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: prime-numbers
key: ${{ runner.os }}-primes
@ -93,9 +146,11 @@ A cache key can include any of the contexts, functions, literals, and operators
For example, using the [`hashFiles`](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#hashfiles) function allows you to create a new cache when dependencies change.
```yaml
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: path/to/dependencies
path: |
path/to/dependencies
some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
@ -109,7 +164,7 @@ Additionally, you can use arbitrary command output in a cache key, such as a dat
echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
shell: bash
- uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
@ -130,7 +185,7 @@ Example:
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
- uses: actions/cache@v2
id: cache
with:
path: path/to/dependencies