Skip to content

Commit

Permalink
update readme for cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed May 14, 2024
1 parent b3af7b4 commit 205f122
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
38 changes: 16 additions & 22 deletions workflow-steps/cache/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
## Usage

```yaml
- name: Git Cache Step
uses: 'nrwl/nx-cloud-workflows/v1.1/workflow-steps/cache/main.yaml'
env:
KEY: '"yarn" | yarn.lock'
PATHS: 'node_modules'
BASE_BRANCH: 'main'
- name: Git Cache Step
uses: 'nrwl/nx-cloud-workflows/v4/workflow-steps/cache/main.yaml'
inputs:
key: 'package-lock.json|yarn.lock|pnpm-lock.yaml'
paths: 'node_modules'
base_branch: 'main'
```

### Options
### Inputs

#### KEY
#### `key` <img src="https://img.shields.io/badge/default_value-%27package--lock%2Ejson%7Cyarn%2Elock%7Cpnpm--lock%2Eyaml%27-D3D3D3" style="vertical-align: middle;">

The keys can contain a combination of strings or globs that need to be hashed.

For example, this cache entry will get busted if any of the files under `scripts/*` changes:

```yaml
KEY: '"some-string" | scripts/*'
key: '"some-string" | scripts/*'
```

Note how "some-string" has quotes around it. This is important and tells the step to key it as-is, and not try to look
Expand All @@ -28,52 +28,46 @@ with that name to hash.
You can also point it directly to a specific file to be hashed:

```yaml
KEY: '"some-string" | yarn.lock'
key: '"some-string" | yarn.lock'
```

#### PATHS
#### `paths` <img src="https://img.shields.io/badge/required-E53935" style="vertical-align: middle;">

You will normally upload a single folder under a key:

```yaml
PATHS: 'node_modules'
paths: 'node_modules'
```

But you can optionally upload multiple folders, and they will all be restored in the same location if there is a cache
hit:

```yaml
PATHS: |
paths: |
folder_one
folder_two/folder_three
foo/bar/abc
```

All above locations will be cached and subsequently restored.

#### BASE_BRANCH
#### `base-branch`

For security reasons, this step will only write cache entries **for the current branch only**. This isolation is
essential, for example, for open source projects, where anyone can create PRs and potentially push malicious artefacts
to the cache.

So by default, if you do not pass the `BASE_BRANCH`, the cache step will only attempt to restore caches written **by the
So by default, if you do not pass the `base-branch`, the cache step will only attempt to restore caches written **by the
current branch only**. This can be fine, as any subsequent pushes to your PR will re-use the cache, and all the commits
that go into your
`main` branch will also re-use the cache.

However, for an extra optimisation, we recommend setting:

```yaml
BASE_BRANCH: 'main' # or another branch
base-branch: 'main' # or another branch
```

This will ensure that when you first open a PR, if a cached entry isn't found for the current branch, it will try to
look at entries
on your default protected branch (usually `main`).






1 change: 0 additions & 1 deletion workflow-steps/cache/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ inputs:
required: true
- name: base-branch
description:
default: 'main'

definition:
using: 'node'
Expand Down

0 comments on commit 205f122

Please sign in to comment.