Important
It seems like this action is no longer necessary because actions/setup-node now supports caching out of the box. Please use it instead, as shown below:
steps:
- uses: actions/setup-node@v4
with: {node-version: 20, cache: 'npm'}
Composite GitHub Action which combines the perfect pairing of actions/setup-node with actions/cache for the caching.
Reducing all these workflow steps:
steps:
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: 19
- name: Determine npm cache directory path
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- name: Determine yarn cache directory path
id: yarn-cache-dir
shell: bash
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-
Down to this:
steps:
- {uses: gacts/setup-node-with-cache@v1, with: {node-version: 19}}
Or using node-version-file
for version selection:
steps:
- {uses: gacts/setup-node-with-cache@v1, with: {node-version-file: .node-version}}
Output values can be used on your choice, for example:
steps:
- uses: gacts/setup-node-with-cache@v1
id: setup-node
with: {node-version: 19}
- if: steps.setup-node.outputs.npm-cache-hit != 'true' # or `yarn-cache-hit`
run: npm ci
Tip
Use Dependabot to keep this action updated in your repository.
If you find any action errors - please, make an issue in the current repository.
This is open-sourced software licensed under the MIT License.