Skip to content

Commit aa0fea1

Browse files
csvncrowlKats
authored andcommitted
feat: add built-in caching via inputs (#89)
(cherry picked from commit fd6b0ad)
1 parent db3496c commit aa0fea1

File tree

14 files changed

+79754
-35972
lines changed

14 files changed

+79754
-35972
lines changed

.github/workflows/test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,41 @@ jobs:
8080
- name: Check binary exists
8181
run: deno_foo -V
8282

83+
test-setup-cache:
84+
runs-on: ${{ matrix.os }}
85+
strategy:
86+
matrix:
87+
os: [ubuntu-latest, windows-latest, macos-latest]
88+
steps:
89+
- uses: actions/checkout@v4
90+
91+
- name: Setup Deno
92+
uses: ./
93+
with:
94+
cache: true
95+
cache-hash: ${{ hashFiles('**/deno.lock') }}
96+
97+
- name: Download dependencies for cache
98+
run: deno install --global --no-config npm:[email protected]
99+
100+
test-cache:
101+
needs: test-setup-cache
102+
runs-on: ${{ matrix.os }}
103+
strategy:
104+
matrix:
105+
os: [ubuntu-latest, windows-latest, macos-latest]
106+
steps:
107+
- uses: actions/checkout@v4
108+
109+
- name: Setup Deno
110+
uses: ./
111+
with:
112+
cache: true
113+
cache-hash: ${{ hashFiles('**/deno.lock') }}
114+
115+
- name: Run with cached dependencies
116+
run: deno run --cached-only --no-config -RE npm:[email protected] "It works!"
117+
83118
lint:
84119
runs-on: ubuntu-latest
85120
steps:

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,23 @@ number.
141141
142142
- run: echo "Deno version is ${{ steps.deno.outputs.deno-version }}"
143143
```
144+
145+
### Caching dependencies downloaded by Deno automatically
146+
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).
149+
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.
152+
153+
```yaml
154+
- uses: denoland/setup-deno@v2
155+
with:
156+
cache: true
157+
cache-hash: ${{ hashFiles('**/deno.lock') }}
158+
```
159+
160+
> [!WARNING]
161+
> If an environment variable `DENO_DIR` is set for steps that run/download
162+
> dependencies, then `DENO_DIR` must also be set for the `denoland/setup-deno`
163+
> action, for the caching to work as intended.

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@ inputs:
1313
deno-binary-name:
1414
description: The name to use for the binary.
1515
default: "deno"
16+
cache:
17+
description: Cache downloaded modules & packages automatically in GitHub Actions cache.
18+
default: "false"
19+
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.
1621
outputs:
22+
cache-hit:
23+
description: A boolean indicating whether the cache was hit.
1724
deno-version:
1825
description: "The Deno version that was installed."
1926
release-channel:
2027
description: "The release channel of the installed version."
2128
runs:
2229
using: "node20"
2330
main: "dist/main.mjs"
31+
post: "dist/post.mjs"
32+
post-if: always()

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"build": "deno run -A scripts/build.ts"
1515
},
1616
"imports": {
17+
"@actions/cache": "npm:@actions/cache@^4.0.3",
1718
"@actions/core": "npm:@actions/core@^1.11.1",
1819
"@actions/tool-cache": "npm:@actions/tool-cache@^2.0.2",
1920
"@types/node": "npm:@types/node@^22.15.0",

0 commit comments

Comments
 (0)