Skip to content

Commit

Permalink
Merge pull request #329 from actions/aiyan/v2-release-doc
Browse files Browse the repository at this point in the history
Update readme and examples to use v2
  • Loading branch information
Aiqiao Yan authored and GitHub committed May 26, 2020
2 parents 9ab9538 + e6c708b commit b820478
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 73 deletions.
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,36 @@ 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

* Added support for multiple paths, [glob patterns](https://github.com/actions/toolkit/tree/master/packages/glob), and single file caches.

```yaml
- name: Cache multiple paths
uses: actions/cache@v2
with:
path: |
~/cache
!~/cache/exclude
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
```
* Increased performance and improved cache sizes using `zstd` compression for Linux and macOS runners
* 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

Refer [here](https://github.com/actions/cache/blob/v1/README.md) for previous versions

## Usage

### Pre-requisites
Create a workflow `.yml` file in your repositories `.github/workflows` directory. An [example workflow](#example-workflow) is available below. For more information, reference the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file).

### Inputs

* `path` - A directory to store and save the cache
* `path` - A list of files, directories, and wildcard patterns to cache and restore. 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

Expand Down Expand Up @@ -46,7 +68,7 @@ jobs:
- name: Cache Primes
id: cache-primes
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: prime-numbers
key: ${{ runner.os }}-primes
Expand Down Expand Up @@ -93,9 +115,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') }}
```

Expand All @@ -109,7 +133,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') }}
Expand All @@ -130,7 +154,7 @@ Example:
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
- uses: actions/cache@v2
id: cache
with:
path: path/to/dependencies
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Cache artifacts like dependencies and build outputs to improve wor
author: 'GitHub'
inputs:
path:
description: 'A directory to store and save the cache'
description: 'A list of files, directories, and wildcard patterns to cache and restore'
required: true
key:
description: 'An explicit key for restoring and saving the cache'
Expand Down
Loading

0 comments on commit b820478

Please sign in to comment.