Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache deno modules #31

Open
jacque006 opened this issue Jun 9, 2022 · 5 comments · May be fixed by #89
Open

Cache deno modules #31

jacque006 opened this issue Jun 9, 2022 · 5 comments · May be fixed by #89

Comments

@jacque006
Copy link

It would be nice if this action had a way to cache deno modules that had been downloaded in previous runs, similarly to https://github.com/actions/setup-node#caching-global-packages-data

The cache looks like it is easy enough to find https://deno.land/manual/linking_to_external_code#linking-to-third-party-code . However, I'm unsure what the key/hash for lookup and download would be to:

  • Determine if a module had changed in any file.
  • Lookup existing module caches.

This part is easier with a NodeJS package manager such as npm or yarn as you can just use a hash of the lockfile.

@jespertheend
Copy link

I bet there's some way to do this using https://github.com/actions/cache, but I'm not sure what would be the right paths for hashFiles() and path

@GJZwiers
Copy link

GJZwiers commented Aug 9, 2022

I bet there's some way to do this using https://github.com/actions/cache, but I'm not sure what would be the right paths for hashFiles() and path

It can be achieved by pointing path to the location of DENO_DIR and calling hashFiles() on the lockfile that is written with deno cache --lock=<file> --lock-write. For example:

env:
  DENO_DIR: my_cache_directory

steps:
  - name: Cache Deno dependencies 
    uses: actions/cache@v2
    with:
      path: ${{ env.DENO_DIR }}
      key: ${{ hashFiles('lock.json') }}

Having an option in setup_deno to cache could be useful, although there is perhaps more diversity in what lockfile names people use compared to Node where it is almost always package-lock.json, npm-shrinkwrap.json or yarn.lock.

@csvn
Copy link

csvn commented Oct 8, 2024

This would be greatly appreciated. It would streamline action setup a lot to not have to manually setup actions/cache.

@joshdales
Copy link

Just discovered that there are also examples in actions/cache of setting it up with Deno https://github.com/actions/cache/blob/main/examples.md#deno. Thought I would share in case others come looking for more examples.

Though I agree with others that it would be nice if it was part of the deno action.

@csvn csvn linked a pull request Nov 25, 2024 that will close this issue
1 task
@csvn
Copy link

csvn commented Nov 25, 2024

I've created a PR for this now: #89. Unfortunately, @actions/cache is a package with a lot of dependencies, and the checked in /node_modules would become huge if it's just installed as-is.

image

I've opened the PR to get feedback. Perhaps the Deno team will just accept installing the dependencies and pushing them to the branch, or it might be required to add a build-step (similar to @actions/setup-node) to bundle everything into one file.

Hopefully, it should be possible to do something like below if the PR get's merged, and save a ton of boilerplate.

# Before
env:
  DENO_DIR: ${{ github.workspace }}/.deno

      - uses: denoland/setup-deno@v2
      - uses: actions/cache/restore@v4
        id: cache
        with:
          path: ${{ env.DENO_DIR }}
          key: cache-${{ runner.os }}-test-${{ hashFiles('deno.lock') }}
          restore-keys: cache-${{ runner.os }}
      - run: deno run -A npm:cowsay Hello!
      - uses: actions/cache/save@v4
        with:
          path: ${{ env.DENO_DIR }}
          key: ${{ steps.cache.outputs.cache-primary-key }}
# After
      - uses: denoland/setup-deno@v2
        with:
          cache: true
          cache-hash: ${{ hashFiles('deno.lock') }}
      - run: deno run -A npm:cowsay Hello!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants