Can this module be used from other JavaScript actions?
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:12
- Comments:28 (13 by maintainers)

Top Related StackOverflow Question
@actions/cache@0.1.0is 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
@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