Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,41 @@ jobs:
- name: Check binary exists
run: deno_foo -V

test-setup-cache:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4

- name: Setup Deno
uses: ./
with:
cache: true
cache-hash: ${{ hashFiles('**/deno.lock') }}

- name: Download dependencies for cache
run: deno install --global --no-config npm:[email protected]

test-cache:
needs: test-setup-cache
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4

- name: Setup Deno
uses: ./
with:
cache: true
cache-hash: ${{ hashFiles('**/deno.lock') }}

- name: Run with cached dependencies
run: deno run --cached-only --no-config -RE npm:[email protected] "It works!"

lint:
runs-on: ubuntu-latest
steps:
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,23 @@ number.

- run: echo "Deno version is ${{ steps.deno.outputs.deno-version }}"
```

### Caching dependencies downloaded by Deno automatically

Dependencies installed by Deno can be cached automatically, which is similar to
the [`cache` option in `setup-node`](https://github.com/actions/setup-node).

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

```yaml
- uses: denoland/setup-deno@v2
with:
cache: true
cache-hash: ${{ hashFiles('**/deno.lock') }}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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') }}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to that, maybe doing:

with:
  cache: true

should be an implicit cache-hash: ${{ hashFiles('**/deno.lock') }} and someone can disable this by doing cache-hash: ''

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}-`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here: #98


> [!WARNING]
> If an environment variable `DENO_DIR` is set for steps that run/download
> dependencies, then `DENO_DIR` must also be set for the `denoland/setup-deno`
> action, for the caching to work as intended.
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ inputs:
deno-binary-name:
description: The name to use for the binary.
default: "deno"
cache:
description: Cache downloaded modules & packages automatically in GitHub Actions cache.
default: "false"
cache-hash:
description: A hash used as part of the cache key. Use e.g. `$\{{ hashFiles('**/deno.lock') }}` to cache based on the lockfile contents.
outputs:
cache-hit:
description: A boolean indicating whether the cache was hit.
Comment on lines +22 to +23
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 test

deno-version:
description: "The Deno version that was installed."
release-channel:
description: "The release channel of the installed version."
runs:
using: "node20"
main: "dist/main.mjs"
post: "dist/post.mjs"
post-if: always()
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build": "deno run -A scripts/build.ts"
},
"imports": {
"@actions/cache": "npm:@actions/cache@^4.0.3",
"@actions/core": "npm:@actions/core@^1.11.1",
"@actions/tool-cache": "npm:@actions/tool-cache@^2.0.2",
"@types/node": "npm:@types/node@^22.15.0",
Expand Down
Loading