feat: add built-in caching via inputs#89
Conversation
| cache-hit: | ||
| description: A boolean indicating whether the cache was hit. |
There was a problem hiding this comment.
This output can be used to conditionally run deno install. E.g.:
- uses: denoland/setup-deno@v2
id: deno
with:
cache: true
- if: steps.deno.outputs.cache-hit != 'true'
run: deno install
- run: deno testd844df8 to
b402db6
Compare
|
Here's a link to a PR where the Actions passes (after installing |
|
I've now rebased this PR on top of #95, which address remaining TODO's and issues, as long as bundling is seen as a valid addition by the Deno team. Personally, I think the improved performance and being able to use TS makes it worth it. |
| with: | ||
| cache: true | ||
| cache-hash: ${{ hashFiles('**/deno.lock') }} | ||
| ``` |
There was a problem hiding this comment.
I wonder if maybe this should be an implicit cache: true? Maybe something for a follow-up.
- uses: denoland/setup-deno@v2
with:
cache-hash: ${{ hashFiles('**/deno.lock') }}There was a problem hiding this comment.
In addition to that, maybe doing:
with:
cache: trueshould be an implicit cache-hash: ${{ hashFiles('**/deno.lock') }} and someone can disable this by doing cache-hash: ''
There was a problem hiding this comment.
Discussed internally and we'd like to make this automatically hash the deno.lock by default similar to how https://github.com/Swatinem/rust-cache does it by default. I'll open a PR that adds this shortly after merging this one then do a release.
There was a problem hiding this comment.
Ahh, yeah that could be nice; if cache-hash is set, cache: true is implied. I can for sure do a follow-up PR with that 😃
Note worth mentioning, cache-hash is not mandatory. I just had it in the README.md as I think it's best practice. So it's possible to just use cache: true. The primary cache key should then become `deno-cache-${RUNNER_OS}-${RUNNER_ARCH}-${GITHUB_JOB}-`
There was a problem hiding this comment.
Discussed internally and we'd like to make this automatically hash the deno.lock by default similar to how https://github.com/Swatinem/rust-cache does it by default. I'll open a PR that adds this shortly after merging this one then do a release.
Ahh, sure. Sounds like a good idea. I just looking at actions/setup-node, and did not look much at others. Improving defaults and having less boilerplate sounds great!
|
Thanks for fixing the remaining lockfile issues and more @dsherret, really glad to have this merged! It should simplify our GitHub Action config a lot 🎉 |
(cherry picked from commit fd6b0ad)
The `denoland/setup-deno` action recently added built-in caching (denoland/setup-deno#89, denoland/setup-deno#98). This makes it a lot simpler to add caching of the `DENO_DIR` during CI runs, without needing `@actions/cache` manual setup. This should speed up CI runs by avoiding downloading dependencies between every run.
This PR adds support for built-in caching to
denoland/setup-deno. I tried to take inspiration from howactions/setup-nodedid things, but the code here can be way simpler because we're only supporting downloads by Deno and the default cache location orDENO_DIR.Cache keys
restoreKey:deno-cache-${env.RUNNER_OS}-${env.RUNNER_ARCH}${restoreKey}-${env.GITHUB_JOB}-${input.cache-hash}One difference compared to the existing
setup-nodeaction, is that I includedGITHUB_JOBin the cache key. This means it's possible to restore a cache from another job, but each job will have it's own cache key.The benefit of including the job in the cache key, is we only download necessary files. For instance,
testmay download@std/testing, while other jobs do not. We also avoid corrupted caches, if e.g. abuildjob installs all dependencies except testing dependencies, then the cache will miss files needed by atestjob, even while using the same cache key.This is no issue for other package managers in NodeJS, which installs all packages. But with Deno, it's possible to install packages/files automatically while running a program. The user of this action can solve that themselves though, by adding to the
cache-hashinput (e.g.cache-hash: test-${{ hashFiles(...) }}).cache-hashinput for more granular cachesbuild/testjobs have the same cache key, thus keeps downloading dependencies for one or the otherUsage comparison
Given the requirements below, here's before/after compared to when being able to use the
setup-denoaction with changes in this PR:DENO_DIRfilesrestore-keysfor the following benefits:Making caching of installed dependencies built-in makes it a lot easier and less error prone to get great caching with 1 or 2 extra inputs to
denoland/setup-deno.Closes #31