question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can this module be used from other JavaScript actions?

See original GitHub issue

I am trying to write a JavaScript action that runs npm ci and caches ~/.npm and ~/.cache/Cypress folders. I can use this action from YML file like this

# https://github.com/actions/cache
- name: Cache node modules
  uses: actions/cache@v1
  with:
    path: ~/.npm
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-node-

- name: Cache Cypress binary
  uses: actions/cache@v1
  with:
    path: ~/.cache/Cypress
    key: cypress-${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
    restore-keys: |
      cypress-${{ runner.os }}-node-

- name: install dependencies
  env:
    # make sure every Cypress install prints minimal information
    CI: 1
  run: npm ci

But I would like to have our own Cypress action that does the caching and NPM install for the user, something like

- name: Install NPM and Cypress
  uses: @cypress/github-action

This means from Cypress GH action JS code I need to call restore and save files in this action. I have tried but without success, for example

// after executing `npm ci` successfully
const homeDirectory = os.homedir()
const npmCacheDirectory = path.join(homeDirectory, '.npm')

core.saveState('path', npmCacheDirectory)
core.saveState('key', 'abc123')
core.saveState('restore-keys', 'abc123')

console.log('loading cache dist restore')
require('cache/dist/restore')

which gives me

done installing NPM modules
loading cache dist restore
##[error]Input required and not supplied: path
##[error]Node run failed with exit code 1

I think this particular error is due to a different core singleton between “regular” npm module and ncc- bundled actions/cache one. But in general, do you have by any chance a plan to document how to use this module from JavaScript? I could write TypeScript and bundle it as a top level action, which should bundle actions/cache code I think.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:28 (13 by maintainers)

github_iconTop GitHub Comments

17reactions
aiqiaoycommented, May 15, 2020

@actions/cache@0.1.0 is released. Please try it out and file issues under the toolkit repo if you encountered any issue. Feedback is welcomed!

Code is here.

Cache action v2 (which we are releasing later this month) will be using the cache node package https://github.com/actions/cache/pull/313

15reactions
joshmgrosscommented, Dec 10, 2019

@Cyberbeni Yes that’s an option.

We’re working on moving the core cache logic into a package (@actions/cache) that will live in the actions toolkit

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript modules - MDN Web Docs
The first thing you do to get access to module features is export them. This is done using the export statement. ... You...
Read more >
Modules, introduction - The Modern JavaScript Tutorial
A module is just a file. One script is one module. As simple as that. Modules can load each other and use special...
Read more >
How do I use event handlers between JavaScript module files ...
You can either use the EventEmitter object directly or you can derive from it and create your own object that has all the...
Read more >
Using events: Modules talking to modules | Human JavaScript
Sometimes modules are dependent on other modules but we still want to be able to keep them loosely coupled? One good technique is...
Read more >
Understanding Modules and Import and Export Statements in ...
In this tutorial, you will learn what a JavaScript module is and how to use import and export to organize your code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found