-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
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.