Skip to content

Commit 3169cf9

Browse files
authored
feat: include a hash of deno.lock files in the cache key automatically (denoland#98)
1 parent fd6b0ad commit 3169cf9

File tree

12 files changed

+1993
-830
lines changed

12 files changed

+1993
-830
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ jobs:
9292
uses: ./
9393
with:
9494
cache: true
95-
cache-hash: ${{ hashFiles('**/deno.lock') }}
9695

9796
- name: Download dependencies for cache
9897
run: deno install --global --no-config npm:cowsay@1.6.0
@@ -110,7 +109,6 @@ jobs:
110109
uses: ./
111110
with:
112111
cache: true
113-
cache-hash: ${{ hashFiles('**/deno.lock') }}
114112

115113
- name: Run with cached dependencies
116114
run: deno run --cached-only --no-config -RE npm:cowsay@1.6.0 "It works!"

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,38 @@ number.
144144

145145
### Caching dependencies downloaded by Deno automatically
146146

147-
Dependencies installed by Deno can be cached automatically, which is similar to
148-
the [`cache` option in `setup-node`](https://github.com/actions/setup-node).
147+
Dependencies installed by Deno can be cached automatically between workflow
148+
runs. This helps make your GH action run faster by not repeating caching work
149+
and network requests done by a previous run.
149150

150-
To enable the cache, use `cache: true`. It's recommended to also add the
151-
`cache-hash` property, to scope caches based on lockfile changes.
151+
To enable the cache, use `cache: true`.
152152

153153
```yaml
154154
- uses: denoland/setup-deno@v2
155155
with:
156156
cache: true
157-
cache-hash: ${{ hashFiles('**/deno.lock') }}
158157
```
159158

160159
> [!WARNING]
161160
> If an environment variable `DENO_DIR` is set for steps that run/download
162161
> dependencies, then `DENO_DIR` must also be set for the `denoland/setup-deno`
163162
> action, for the caching to work as intended.
163+
164+
By default, the cache is automatically keyed by:
165+
166+
- the github
167+
[job_id](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_id)
168+
- the runner os and architecture
169+
- a hash of the `deno.lock` files in the project
170+
171+
It is possible to customize the default hash
172+
(`${{ hashFiles('**/deno.lock') }}`) used as part of the cache key via the
173+
`cache-hash` input.
174+
175+
```yaml
176+
- uses: denoland/setup-deno@v2
177+
with:
178+
# setting `cache-hash` implies `cache: true` and will replace
179+
# the default cache-hash of `${{ hashFiles('**/deno.lock') }}`
180+
cache-hash: ${{ hashFiles('**/deno.json') }}
181+
```

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ inputs:
1717
description: Cache downloaded modules & packages automatically in GitHub Actions cache.
1818
default: "false"
1919
cache-hash:
20-
description: A hash used as part of the cache key. Use e.g. `$\{{ hashFiles('**/deno.lock') }}` to cache based on the lockfile contents.
20+
description: A hash used as part of the cache key, which defaults to a hash of the deno.lock files.
2121
outputs:
2222
cache-hit:
2323
description: A boolean indicating whether the cache was hit.

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"imports": {
1717
"@actions/cache": "npm:@actions/cache@^4.0.3",
1818
"@actions/core": "npm:@actions/core@^1.11.1",
19+
"@actions/glob": "npm:@actions/glob@^0.5.0",
1920
"@actions/tool-cache": "npm:@actions/tool-cache@^2.0.2",
2021
"@types/node": "npm:@types/node@^22.15.0",
2122
"@types/semver": "npm:@types/semver@^7.7.0",

deno.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cache-ByPW8-iO.mjs

Lines changed: 0 additions & 4 deletions
This file was deleted.

dist/cache-D7LLZXo3.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "./semver-DmxAwBYV.mjs";
2+
import { restoreCache, saveCache } from "./cache-zjpbixka.mjs";
3+
4+
export { restoreCache };

0 commit comments

Comments
 (0)