Skip to content

1-liner npm install cache for GitHub Actions

License

Notifications You must be signed in to change notification settings

AgoraSystems/gha-npm-cache

 
 

Repository files navigation

gha-npm-cache

1-liner npm install cache for GitHub Actions

Status and support

  • ✔ stable
  • ✔ supported
  • ✖ no ongoing development

CI

GitHub Action caches improve build times and reduce network dependencies. However, writing the correct cache logic is tricky. You need to understand how the cache action (keys and restore keys) work. Did you know you're not supposed to cache the node_modules folder? The setup is different per OS and takes a lot of space in your workflows. Not anymore!

gha-npm-cache is a simple 1-liner that covers all use-cases, correctly:

Usage

Add this step before npm install:

- uses: c-hive/gha-npm-cache@v1

For example:

.github/workflows/ci.yml

name: CI

on: [push]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1

    - uses: c-hive/gha-npm-cache@v1

    - name: Install JS dependencies
      run: npm install
    - name: Test
      run: npm run test

Solution comparison

Native

- name: Get npm cache directory
  id: npm-cache
  run: |
    echo "::set-output name=dir::$(npm config get cache)"
- uses: actions/cache@v1
  with:
    path: ${{ steps.npm-cache.outputs.dir }}
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-node-

gha-npm-cache

- uses: c-hive/gha-npm-cache@v1

Similar actions

Conventions

This project follows C-Hive guides for code style, way of working and other development concerns.

License

The project is available as open source under the terms of the MIT License.

About

1-liner npm install cache for GitHub Actions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%