Skip to content

gacts/setup-node-with-cache

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Logo

Setup Node environment with a Cache

Release version Build Status License

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@v3
    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@v3
    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@v3
    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 maintain your gacts/setup-node-with-cache version updated in your GitHub workflows.

Support

Issues Issues

If you find any action errors - please, make an issue in the current repository.

License

This is open-sourced software licensed under the MIT License.