Giter Club home page Giter Club logo

npm-install's Introduction

npm-install semantic-release renovate-app badge

GitHub Action for install npm dependencies with caching without any configuration

CI

Example Status
main this repo
basic basic example
shrinkwrap shrinkwrap example
Yarn yarn example
without lock file without lockfile example
subfolders subfolders example
Node version Node version example

Examples

Basic

This example should cover 95% of use cases.

If you use npm ci or yarn --frozen-lockfile on CI to install NPM dependencies - this Action is for you. Simply use it, and your NPM modules will be installed and the folder ~/.npm or ~/.cache/yarn will be cached. Typical use:

name: main
on: [push]
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    name: Build and test
    steps:
      - uses: actions/checkout@v3
      - uses: bahmutov/npm-install@v1
      - run: npm t

See bahmutov/npm-install-action-example npm-install-action-example.

Subfolders

If your repository contains packages in separate folders, install each one separately

repo/
  app1/
    package-lock.json
  app2/
    yarn.json
name: main
on: [push]

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    name: Build and test
    steps:
      - uses: actions/checkout@v3

      - uses: bahmutov/npm-install@v1
        with:
          working-directory: app1
      - uses: bahmutov/npm-install@v1
        with:
          working-directory: app2

      - name: App1 tests
        run: npm t
        working-directory: app1
      - name: Run app2
        run: node .
        working-directory: app2

See npm-install-monorepo-example npm-install-monorepo-example.

You can also specify multiple subfolders in a single action; one subfolder per line.

name: main
on: [push]

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    name: Build and test
    steps:
      - uses: actions/checkout@v3
      - uses: bahmutov/npm-install@v1
        with:
          working-directory: |
            app1
            app2

Use lock file

By default, this action will use a lock file like package-lock.json, npm-shrinkwrap.json or yarn.lock. You can set useLockFile: false to use just package.json which might be better for building libraries.

- uses: bahmutov/npm-install@v1
  with:
    useLockFile: false

Use time-based rolling cache

By default, yarn and npm dependencies will be cached according to the exact hash of the lockfile (if enabled) or the package.json. This will cause cache misses when the dependencies change, which can be slower than re-installing for big projects. To re-use the cache across runs with different lockfiles/dependencies, you can enable the useRollingCache option, which will restore the cache from more keys. It will expire the cache once a month to keep it from growing too large, see the Cache Snowballing & Rolling Cache expiry below.

- uses: bahmutov/npm-install@v1
  with:
    useRollingCache: true

useRollingCache is defaulted to false.

Production dependencies

You can install just the production dependencies (without installing dev dependencies) by setting an environment variable NODE_ENV variable

- uses: bahmutov/npm-install@v1
  env:
    NODE_ENV: production

Custom install command

You can use your own install command

- uses: bahmutov/npm-install@v1
  with:
    install-command: yarn --frozen-lockfile --silent

See example-install-command.yml

Add cache prefix

If you are installing different individual tools, you might want to have different caches. You can insert custom cache prefix strings into the cache keys. For example, let's install two different tools, each cache will be separate.

- name: Install tool A
  uses: bahmutov/npm-install@v1
  with:
    # use just package.json checksum
    useLockFile: false
    install-command: 'npm install tool-a'
    cache-key-prefix: tool-a

- name: Install tool B
  uses: bahmutov/npm-install@v1
  with:
    # use just package.json checksum
    useLockFile: false
    install-command: 'npm install tool-b'
    cache-key-prefix: tool-b

The first cache will have key npm-tool-a-... and the second cache will have key npm-tool-b-...

Node version

If you need to use a specific Node version, use the actions/setup-node before installing the dependencies.

- uses: actions/checkout@v3
  # pick the Node version to use and install it
  # https://github.com/actions/setup-node
  - uses: actions/setup-node@v3
    with:
      node-version: 18
  - uses: bahmutov/npm-install@v1

See example-node-version.yml

External examples

Name Description
npm-install-example Shows how to use this action

NPM

If you are writing your own GitHub Action and would like to use this action as a utility function, import it and run it.

const { npmInstallAction } = require('npm-install')
await npmInstallAction()

Debugging

You can see verbose messages from GitHub Actions by setting the following secrets (from Debugging Actions Guide)

ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true

Tip: environment variable ACTIONS_STEP_DEBUG enables debug messages from this action itself, try it first.

Testing

Using Mocha and Sinon.js following the guide How to set up Mocha with Sinon.js. You can find the tests in test folder. In general:

  • all environment inputs are done inside the action, so they can be stubbed and controlled during tests
  • there are separate workflows in .github/workflows that match examples. Each workflow uses this action to install dependencies

Cache Snowballing & Rolling Cache expiry

By default, this action will cache dependencies using an exacty hashs of the lock file (like package-lock.json, npm-shrinkwrap.json or yarn.lock). If you change any dependencies, there will be a cache miss. This is the default cache key strategy to avoid unbounded growth of the cache, as if you don't expire the cache, it will continue being added to. See this post for more details on this issue.

To get better cache hit rates without the cache size snowballing, you can turn on this action's useRollingCache option, which will allow old caches to be re-used when your dependencies change, at the expense of some snowballing. Instead of letting the cache grow forever, this action resets it every month by including the current month in the cache key.

The rule of thumb is this: if re-installing your dependencies doesn't take very long, you can avoid superfluous cache restores by keeping useRollingCache off. This is the recommended setup for small projects. For big projects where installing the dependencies takes a long time, and cache restores are faster, useRollingCache will provide a performance improvement.

Links

Small print

Author: Gleb Bahmutov <[email protected]> Β© 2019

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2019 Gleb Bahmutov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm-install's People

Contributors

agilgur5 avatar alexbjorlig avatar bahmutov avatar bertg avatar jbutko avatar mikemcc399 avatar perrin4869 avatar renovate-bot avatar renovate[bot] avatar thinca avatar yenhub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

npm-install's Issues

Set up e2e tests using subfolders

In the workflows, we could create subfolders that would use ${{ github.sha }} to install this action from the current push. Then it would be a true end-to-end test for the current commit

error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.

Hi,
I used this library to have some cache on my action when using yarn install, it was working fine until I did some refactor around my dependencies and now I'am having the following error:

error Your lockfile needs to be updated, but yarn was run with --frozen-lockfile`.

Here is my github action:

name: Push storybook to s3

on: [pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: client
    steps:
      - uses: actions/setup-node@v1
      - uses: actions/checkout@v1
      - uses: bahmutov/npm-install@v1
        with:
          working-directory: client
      - name: "yarn build-storybook"
        run: yarn build-storybook

Do you have any idea ?

Error when installing packages

Hey πŸ‘‹

Our checks started failing about 2 days ago with a reserveCache failed error (see below). The error is very sporadic and will usually fix itself when we run the checks again.

reserveCache failed: Cache already exists. Scope: refs/heads/dependabot/npm_and_yarn/testing-library/jest-dom-5.11.3, Key: yarn-linux-x64-a81ae0ca03461d6790722af5d4c65aa4f4cd99693156b291b879b1fdacf3941f460c2fba5f9aafc8b9a8dbbbeb6d5ca9a551489d773bd02d23a8ae52ce6497ea, Version: db8d7573c9c1e018880f416d1266a74a2aca6c42332d4f92d877cf07990531be

I noticed a new release was made 2 days ago. Do you think the new release is causing the issue?

v1.8.16 breaks cache miss installs when the yarn cache dir != ~/.yarn/cache (windows, yarn2+, etc.)

Starting with v1.8.16, we're seeing failures in windows-latest workflows whenever there's a cache miss (i.e. dependencies change ... for cache hits it's still working). This happens on any version of node:

saving NPM modules
Error: Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.
    at Object.<anonymous> (D:\a\_actions\bahmutov\npm-install\v1\dist\index.js:44373:19)
    at Generator.next (<anonymous>)
    at fulfilled (D:\a\_actions\bahmutov\npm-install\v1\dist\index.js:44239:58)
Error: Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.

Might be due to a recent underlying change in actions/cache? The same workflow works fine on ubuntu-latest, fwiw. The relevant workflow config is:

  test:
    name: "πŸ§ͺ Test: (OS: ${{ matrix.os }} Node: ${{ matrix.node }})"
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
        node: ${{ fromJSON(inputs.node_version) }}
    runs-on: ${{ matrix.os }}
    steps:
      - name: πŸ›‘ Cancel Previous Runs
        uses: styfle/[email protected]

      - name: ⬇️ Checkout repo
        uses: actions/checkout@v3

      - name: βŽ” Setup node ${{ matrix.node }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
          cache: "yarn"

      - name: πŸ“₯ Install deps
        uses: bahmutov/npm-install@v1

Here's a failing windows run using the latest v1 (v1.8.16). Here's a succeeding windows run using v1.8.15. Apart from that workflow change, the checkouts are identical.

Using yarn but ignoring lockfile

Given a project with a yarn.lock and calling the action with useLockFile: false, I was surprised that it actually runs npm install, instead of yarn --no-lockfile. I would have expected the latter.

This seems to be intentional, looking at this code, but I wonder why?

Add --production flag

Often I need to avoid devDependencies installing (for security reasons).

How I can do it with your awesome tool?

Yarn v3

Thanks for the great action, When i use it with yarn v3 berry - it is not re-using the cache.
Any guide on how to get it working with yarn v3 berry

Thanks!

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Make action fault-tolerant when using caching

We are currently seeing outage of the caching on the side of Github (see issue: actions/cache#820). While this is something they have to fix, I think this action should be fault-tolerant when cache is unavailable, which means refetching and reinstalling all dependencies. Right now the action is failing with: getCacheEntry failed: Cache service responded with 503. This has been the case before (related: actions/cache#698).

One of the proposed solutions to make sure cache never gets in the way of building and deploying again, was making all setup-{} actions on the side of Github more fault tolerant (actions/cache#698 (comment)). I think this should be implemented in this action as well.

The README is outdated Warning: Unexpected input(s) 'useRollingCache'

Warning: Unexpected input(s) 'useRollingCache', valid inputs are ['working-directory', 'useLockFile', 'install-command']
Run bahmutov/[email protected]
running npm-install GitHub Action
trying to restore cached NPM modules
npm cache hit undefined
installing NPM dependencies
npm at "/usr/local/bin/npm"
/usr/local/bin/npm ci

Also looks like bahmutov/npm-install does not get cached anymore.

Allow cache key prefix

It would be nice to be able to clear the cache or bust the cache is some way. Based on actions/cache#2 the only way is to just modify the cache key (such as adding -v2- to it).
Why would this be needed? Not 100% sure, but I think my yarn cache is bad. It hits the cache and restores, but yarn still fetches the packages and takes a long time. Since the cache is not updated after a hit, I would need to force a cache miss in order to fix this.

(On second thought, another option might be to replace the cache after successful install. But that seems pointless as 99% of the time if the cache it, then the cache probably will not change. Though I think things like TravisCI or CircleCI do save every run)

Excluded version from package-lock hash

First of all, thanks for this great package! This is definitely something that is needed in the eco system.

I was curious what the cache was keyed on and starting reading the source. I see that you hash the lock file which is great, without it the cache can easily balloon in size as package versions are bumped, and the old cache is always retained πŸ˜…

There is one annoying thing with the package-lock format though, it includes the version of the app itself. That means that the cache will be invalidated not only when the dependencies change, but when the version of the app/library changes.

In another tool, I've worked around this by always setting the root version property in package-lock to 0.0.0, which lets the (in that case Docker) cache work across version bumps:

https://github.com/LinusU/scandium/blob/2d6eb942f7c10f1d5c91b71b31dd542f335ad142/lib/builder.js#L37-L38

How would you feel about doing something similar here?

I'm thinking something like:

const packageLockData = JSON.parse(fs.readFileSync('package-lock.json'))
const packageLockHash = hasha.fromString(JSON.stringify({ ...packageLockData, version: '0.0.0' }))

I'd be happy to submit a PR πŸš€

npm ERR! cb() never called!

I know this is not directly under this action's control, but I am raising it here, in case there is some effect.

I'm getting the following error intermittently:

Run bahmutov/npm-install@v1
  with:
running npm-install GitHub Action
trying to restore cached NPM modules
npm cache hit undefined
installing NPM dependencies
npm at "/opt/hostedtoolcache/node/14.17.0/x64/bin/npm"
/opt/hostedtoolcache/node/14.17.0/x64/bin/npm ci
npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-06-19T10_45_41_566Z-debug.log
Error: The process '/opt/hostedtoolcache/node/14.17.0/x64/bin/npm' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:969:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:952:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:846:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
Error: The process '/opt/hostedtoolcache/node/14.17.0/x64/bin/npm' failed with exit code 1

Any clues?

decompress cache to subfolder

Hi

I have a config:

   - uses: bahmutov/npm-install@v1
      if: needs.check.outputs.build_web_clients == 'true'
      with:
          working-directory: src/SoMeSociety.Brandarmies/Client.Shared

but it seems the cache is decompressed to a different folder and thus not speeding up my build. what am I missing?

Screenshot 2021-10-08 090418

Thanks!

Decoding error: Restored data doesn't match checksum

I'm seeing the following error all of the sudden:

Run bahmutov/npm-install@v1
running npm-install GitHub Action
trying to restore cached NPM modules
Received 0 of 1116313[24](https://github.com/mycompany/myapp/runs/5839241098?check_suite_focus=true#step:7:24) (0.0%), 0.0 MBs/sec
Received 67108864 of 111631324 (60.1%), 32.0 MBs/sec
Received 107437020 of 111631324 (96.2%), 34.1 MBs/sec
Received 111631324 of 111631324 (100.0%), 33.4 MBs/sec
Cache Size: ~106 MB (111631324 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/0357bdf5-a49b-4316-b5d6-7[25](https://github.com/mycompany/myapp/runs/5839241098?check_suite_focus=true#step:7:25)[26](https://github.com/mycompany/myapp/runs/5839241098?check_suite_focus=true#step:7:26)0f9b538/cache.tzst -P -C /home/runner/work/myapp/myapp
/*stdin*\ : Decoding error (36) : Restored data doesn't match checksum 
/usr/bin/tar: Child returned status 1
/usr/bin/tar: Error is not recoverable: exiting now
Error: Tar failed with error: The process '/usr/bin/tar' failed with exit code 2
    at /home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:[34](https://github.com/mycompany/myapp/runs/5839241098?check_suite_focus=true#step:7:34)844:19
    at Generator.throw (<anonymous>)
    at rejected (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:34786:65)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Error: Tar failed with error: The process '/usr/bin/tar' failed with exit code 2

The npm-install action ran successfully minutes before in a PR workflow. The log above is from an extremely similar manual deployment workflow that looks like this:

name: Manual deployment workflow
on:
  workflow_dispatch:
    inputs:
      GIT_COMMIT_TO_PROMOTE:
        description: 'Git commit SHA to promote'
        required: true
      ENV_TO_PROMOTE_TO:
        description: 'Environment to promote to'
        required: true
jobs:
  manual-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Set up environment
        run: #sets a bunch of environment variables
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.GIT_COMMIT_TO_PROMOTE }}
          fetch-depth: 0
      - uses: actions/setup-node@v2
        with:
          node-version: '16'
          registry-url: 'https://npm.pkg.github.com'
          scope: '@mycompany'
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GIT_PACKAGE_TOKEN }}
      - id: install-dependencies
        name: Install dependencies
        uses: bahmutov/npm-install@v1

Error: getCacheEntry failed: Cache service responded with 503

I have seen this error pop up several times in the past few days

image

The error seems to originate from this code, which does not seem to be part of this repository

function retry(name, method, getStatusCode, maxAttempts = constants_1.DefaultRetryAttempts, delay = constants_1.DefaultRetryDelay, onError = undefined) {
    return __awaiter(this, void 0, void 0, function* () {
        let errorMessage = '';
        let attempt = 1;
        while (attempt <= maxAttempts) {
            let response = undefined;
            let statusCode = undefined;
            let isRetryable = false;
            try {
                response = yield method();
            }
            catch (error) {
                if (onError) {
                    response = onError(error);
                }
                isRetryable = true;
                errorMessage = error.message;
            }
            if (response) {
                statusCode = getStatusCode(response);
                if (!isServerErrorStatusCode(statusCode)) {
                    return response;
                }
            }
            if (statusCode) {
                isRetryable = isRetryableStatusCode(statusCode);
                errorMessage = `Cache service responded with ${statusCode}`;
            }
            core.debug(`${name} - Attempt ${attempt} of ${maxAttempts} failed with error: ${errorMessage}`);
            if (!isRetryable) {
                core.debug(`${name} - Error is not retryable`);
                break;
            }
            yield sleep(delay);
            attempt++;
        }
        throw Error(`${name} failed: ${errorMessage}`);
    });
}

I've set ACTIONS_STEP_DEBUG to true for future runs and will let you know if that yields any helpful information.

The source code above suggests that maxAttempts might be configurable? Is there an option I can set to retry requests in case of a 503?

Fails if package.json contains a postinstall script

The action fails if the package.json has a postinstall script.

running npm-install GitHub Action
trying to restore cached NPM modules
Received 46333806 of 46333806 (100.0%), 113.3 MBs/sec
Cache Size: ~44 MB (46333806 B)
/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/0bf3a688-e24c-4407-aa2c-bb4db5f3f360/cache.tzst -P -C /home/runner/work/my-first-snowpack-app/my-first-snowpack-app
npm cache hit npm-linux-x64-83c08d0d97d3a4a980fbc96a7f9dbcf64e82c51adc8063d4022dce4513a7bbf4674998859f107eb1e0097f4c4acb90e62cb14d5202fbf9bee1628f3db7eca31c
installing NPM dependencies
npm at "/usr/local/bin/npm"
/usr/local/bin/npm ci

> [email protected] postinstall /home/runner/work/my-first-snowpack-app/my-first-snowpack-app/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"


> [email protected] postinstall /home/runner/work/my-first-snowpack-app/my-first-snowpack-app/node_modules/esbuild
> node install.js


> [email protected] postinstall /home/runner/work/my-first-snowpack-app/my-first-snowpack-app/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"

npm ERR! Cannot read property 'length' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-02-09T20_49_10_427Z-debug.log
Error: The process '/usr/local/bin/npm' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:969:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:952:18)
    at ChildProcess. (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:846:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

cy.yml

name: CI

on: [push, pull_request]

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout πŸ›Ž
      uses: actions/checkout@v2
    - name: Install NPM dependencies πŸ“¦
      uses: bahmutov/npm-install@v1
    - name: Check code style 🧩
      run: npm run lint
    - name: Check types 🧩
      uses: icrawl/action-tsc@v1
    - name: Run unit tests πŸ§ͺ
      run: npm t

package.json

{
  "scripts": {
    "build": "snowpack build",
    "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx}\"",
    "lint": "xo",
    "postinstall": "is-ci || husky install",
    "start": "snowpack dev",
    "test": "web-test-runner \"src/**/*.test.tsx\""
  },
  "dependencies": {
    "react": "^17.0.0",
    "react-dom": "^17.0.0"
  },
  "devDependencies": {
    "@commitlint/cli": "^11.0.0",
    "@commitlint/config-conventional": "^11.0.0",
    "@snowpack/plugin-dotenv": "^2.0.5",
    "@snowpack/plugin-react-refresh": "^2.4.0",
    "@snowpack/plugin-typescript": "^1.2.0",
    "@snowpack/web-test-runner-plugin": "^0.2.0",
    "@testing-library/react": "^11.0.0",
    "@types/chai": "^4.2.13",
    "@types/mocha": "^8.2.0",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@types/snowpack-env": "^2.3.2",
    "@web/test-runner": "^0.12.0",
    "chai": "^4.2.0",
    "husky": "^5.0.9",
    "is-ci": "^2.0.0",
    "lint-staged": "^10.5.4",
    "prettier": "^2.0.5",
    "prettier-plugin-package": "^1.3.0",
    "prettier-plugin-sorted": "^2.0.0",
    "snowpack": "^3.0.1",
    "typescript": "^4.0.0",
    "xo": "^0.37.1"
  },
  "xo": {
    "space": true,
    "prettier": true,
    "envs": [
      "es2020",
      "node",
      "browser",
      "mocha"
    ]
  }
}

npm ERR! fsevents not accessible from chokidar

It was working fine and then suddenly turned into this.

Run bahmutov/npm-install@v1
running npm-install GitHub Action
trying to restore cached NPM modules
npm cache hit undefined
installing NPM dependencies
npm at "/opt/hostedtoolcache/node/14.17.4/x64/bin/npm"
/opt/hostedtoolcache/node/14.17.4/x64/bin/npm ci
npm ERR! fsevents not accessible from chokidar

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-08-04T21_41_58_419Z-debug.log
Error: The process '/opt/hostedtoolcache/node/14.17.4/x64/bin/npm' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:969:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:952:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:846:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
Error: The process '/opt/hostedtoolcache/node/14.17.4/x64/bin/npm' failed with exit code 1

Yarn Berry (yarn 2) support

Context

Yarn 2 (Berry) was released recently and does not seem to be compatible with this action. --frozen-lockfile has been deprecated in favour of --immutable, and the format of the yarn.lock has changed.

There seems to be a handy new version property at the top of the yarn.lock file for yarn@2 for detecting the version:

__metadata:
  version: 4

Here's the output from GitHub Actions:

CI Output
Run bahmutov/[email protected]
running npm-install GitHub Action
trying to restore cached NPM modules
restoring cache /home/runner/.cache/yarn
primary key yarn-linux-x64-409b01bf62cebe1069e54d446bcc46c2361735696e33fc069e2aff8495f1982c9c81a1a642c27c8d650596a484c6d58b4ac99baf221baed836ebdb5b15ea88a4
Cache not found for input keys: yarn-linux-x64-409b01bf62cebe1069e54d446bcc46c2361735696e33fc069e2aff8495f1982c9c81a1a642c27c8d650596a484c6d58b4ac99baf221baed836ebdb5b15ea88a4, yarn-linux-x64-.
npm cache hit false
installing NPM dependencies using Yarn
yarn at "/usr/bin/yarn"
/usr/bin/yarn --frozen-lockfile
yarn install v1.21.1
[1/5] Validating package.json...
[2/5] Resolving packages...
warning @commitlint/cli > babel-polyfill > [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning @commitlint/cli > babel-polyfill > babel-runtime > [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: The process '/usr/bin/yarn' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/bahmutov/npm-install/v1.1.0/dist/index.js:896:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/bahmutov/npm-install/v1.1.0/dist/index.js:879:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/bahmutov/npm-install/v1.1.0/dist/index.js:779:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Motivation

Yarn 2 (Berry) was released last month. It created a complex rift in the npm community. Many hate it, many love it, most are "staying out of the way" and don't want much to do with it.

I've never used yarn, but as of the 2x release, I'm liking it. It makes mono repositories a lot easier to deal with. I wrote something about it here. I'd love for this action to detect and support yarn@2. It doesn't seem to be going away, and it's a fairly simple implementation. I'm going to have to revert to manually installing dependencies for the moment.

Unexpected input for 'working-directory'

Hi @bahmutov,
first of all thanks for the action and for your hard work on cypress ecosystem. It's a fantastic testing tool.

I have an issue with defining working directory, I am getting following error during build:

##[warning]Unexpected input 'working-directory', valid inputs are ['']

I think it's the same issue like cypress github action had: #141 - working-directory attribute is missing in action.yml. Looks like without the definition in action.yml the action is not working correctly.

cache node_modules/.cache

Would it make sense to cache node_modules/.cache? This would greatly speed up all sorts of builds and transpilers (such as babel) that store there cache there

Q: `useRollingCache: true` still results in `npm ci`, but `npm ci` removes `node_modules`?

I’m trying to make a build (mdx-js/mdx) much faster, and am testing useRollingCache: true. It doesn’t seem to do much. Could that be because it still uses npm ci (proof from workflow), but npm ci is faster if:

  • The node_modules folder is missing or empty.

due to:

  • If a node_modules is already present, it will be automatically removed before npm ci begins its install.

(citations from npm ci docs)

(see also this post by De Voorhoede)

Error with bahmutov/npm-install@v1

Hello,

one of my pipeline - not modified from 2 months - defines this step:

`

  • uses: bahmutov/npm-install@v1
    with:
    working-directory: frontend
    `

The previous week, this step runs successfully.

`

Run bahmutov/npm-install@v1
running npm-install GitHub Action
trying to restore cached NPM modules
Received 117104878 of 117104878 (100.0%), 108.4 MBs/sec
Cache Size: ~112 MB (117104878 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/c1b9c05c-4b75-4f27-9257-dcc569abecfe/cache.tzst -P -C /home/runner/work/equipe-de-france/equipe-de-france
npm cache hit yarn-linux-x64-425bc2d37dca3f79a1fdff8734e4c94af78779cfbe6ab7b8df71909b2a78bc382f506b318e1f64b08d5e93c2a57a028cdefedf29a335d2e526d133ecf05b1079
installing NPM dependencies using Yarn
yarn at "/usr/local/bin/yarn"
/usr/local/bin/yarn --frozen-lockfile
yarn install v1.22.17
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
warning "@zeit/next-css > [email protected]" has unmet peer dependency "webpack@^4.0.0".
warning "@zeit/next-css > [email protected]" has unmet peer dependency "webpack@^4.4.0".
warning "@zeit/next-sass > [email protected]" has unmet peer dependency "webpack@^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
warning "next-images > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning "next-images > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning " > [email protected]" has unmet peer dependency "@types/[email protected]".
warning " > [email protected]" has unmet peer dependency "react-is@>= 16.8.0".
warning " > [email protected]" has unmet peer dependency "[email protected]".
warning " > [email protected]" has incorrect peer dependency "[email protected]".
warning " > [email protected]" has incorrect peer dependency "[email protected]".
[5/5] Building fresh packages...
Done in 151.82s.
all done, exiting

`

Today, the step is suddenly failing and I don't know why.
bahmutov_error.txt

Does someone have an idea?

Thanks
Rachel

Failure on initial build (`npm cache hit undefined`)

Hi! I am trying to get started with this action. I have the job defined as follows:

jobs:
  npm:
    name: Install/Cache Node Dependencies
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: bahmutov/npm-install@v1
        with:
          working-directory: frontend-server

But on the initial build it seems to think undefined as a cache key is a hit?

2020-10-21T18:44:31.0250591Z running npm-install GitHub Action
2020-10-21T18:44:31.0307580Z trying to restore cached NPM modules
2020-10-21T18:44:31.1088182Z npm cache hit undefined
2020-10-21T18:44:31.1089088Z installing NPM dependencies
2020-10-21T18:44:31.1119956Z npm at "/usr/local/bin/npm"
2020-10-21T18:44:31.1124089Z [command]/usr/local/bin/npm ci
2020-10-21T18:45:08.1532741Z npm ERR! code ENOENT
2020-10-21T18:45:08.1534647Z npm ERR! syscall open
2020-10-21T18:45:08.1537232Z npm ERR! path /home/runner/work/web/web/frontend-server/node_modules/npm/node_modules/is-date-object/package.json
2020-10-21T18:45:08.1554327Z npm ERR! errno -2
2020-10-21T18:45:08.1589285Z npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/web/web/frontend-server/node_modules/npm/node_modules/is-date-object/package.json'
2020-10-21T18:45:08.1591026Z npm ERR! enoent This is related to npm not being able to find a file.
2020-10-21T18:45:08.1592548Z npm ERR! enoent 
2020-10-21T18:45:09.1393468Z 
2020-10-21T18:45:09.1397189Z npm ERR! A complete log of this run can be found in:
2020-10-21T18:45:09.1399714Z npm ERR!     /home/runner/.npm/_logs/2020-10-21T18_45_08_187Z-debug.log
2020-10-21T18:45:09.1676706Z Error: The process '/usr/local/bin/npm' failed with exit code 254
2020-10-21T18:45:09.1695647Z     at ExecState._setResult (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:962:25)
2020-10-21T18:45:09.1697991Z     at ExecState.CheckComplete (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:945:18)
2020-10-21T18:45:09.1700080Z     at ChildProcess.<anonymous> (/home/runner/work/_actions/bahmutov/npm-install/v1/dist/index.js:839:27)
2020-10-21T18:45:09.1701542Z     at ChildProcess.emit (events.js:210:5)
2020-10-21T18:45:09.1702855Z     at maybeClose (internal/child_process.js:1021:16)
2020-10-21T18:45:09.1704119Z     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
2020-10-21T18:45:09.1708308Z ##[error]The process '/usr/local/bin/npm' failed with exit code 254

Any idea if this is something I am doing wrong and might be able to resolve?

`tar` issues on Windows and macOS

Hey, thanks for making this to simplify the cache config for GitHub Actions!

I'm trying to add this to TSDX to try to speed up our CI in jaredpalmer/tsdx#625, but we run a test matrix including Windows and macOS, and we're getting tar usage errors there that make caching not possible on those platforms πŸ˜•

On Windows, getting: tar.exe: Option --force-local is not supported
Run link: https://github.com/jaredpalmer/tsdx/pull/625/checks?check_run_id=518042349

On macOS, getting: tar: could not chdir to '/Users/runner/.cache/yarn'
Run link: https://github.com/jaredpalmer/tsdx/pull/625/checks?check_run_id=518042358

Allow specifying working directory

So that we can install modules from subfolders like this situation

root/
  app1/
    package.json
  app2/
    yarn.json

That would be something like

name: main
on: [push]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      # install dependencies for app1
      - uses: bahmutov/npm-install@v1
        with:
          working-directory: app1
      # install dependencies for app2
      - uses: bahmutov/npm-install@v1
        with:
          working-directory: app2

Cache node_modules

When using something deterministic such as package-lock.json, would it make sense to try and cache the node_modules directly and skip having to run npm install altogether?

Getting error when running a project that depends on esbuild

Hi,
I'm writing a react library using tsdx which recommends using this action.
My library has a devDependency of esbuild, which causes this beauty:

Run bahmutov/[email protected]
running npm-install GitHub Action
trying to restore cached NPM modules
npm cache hit undefined
installing NPM dependencies
npm at "/opt/hostedtoolcache/node/14.18.[3](https://github.com/liorp/react-hotkeys-docs-hook/runs/5069688276?check_suite_focus=true#step:4:3)/x6[4](https://github.com/liorp/react-hotkeys-docs-hook/runs/5069688276?check_suite_focus=true#step:4:4)/bin/npm"
/opt/hostedtoolcache/node/14.18.3/x64/bin/npm ci
npm ERR! esbuild-android-arm64 not accessible from esbuild

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-02-04T16_43_[5](https://github.com/liorp/react-hotkeys-docs-hook/runs/5069688276?check_suite_focus=true#step:4:5)2_[6](https://github.com/liorp/react-hotkeys-docs-hook/runs/5069688276?check_suite_focus=true#step:4:6)15Z-debug.log
Error: The process '/opt/hostedtoolcache/node/14.18.3/x64/bin/npm' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/bahmutov/npm-install/v1.6.0/dist/index.js:969:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/bahmutov/npm-install/v1.6.0/dist/index.js:952:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/bahmutov/npm-install/v1.6.0/dist/index.js:846:2[7](https://github.com/liorp/react-hotkeys-docs-hook/runs/5069688276?check_suite_focus=true#step:4:7))
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:2[8](https://github.com/liorp/react-hotkeys-docs-hook/runs/5069688276?check_suite_focus=true#step:4:8)3:5)
Error: The process '/opt/hostedtoolcache/node/[14](https://github.com/liorp/react-hotkeys-docs-hook/runs/5069688276?check_suite_focus=true#step:4:14).[18](https://github.com/liorp/react-hotkeys-docs-hook/runs/5069688276?check_suite_focus=true#step:4:18).3/x64/bin/npm' failed with exit code 1

What's wrong?

Add support for `pnpm`

Currently, this Action is only looking for an package-lock.json/npm-shrinkwrap.json or yarn.lock.
It would be awesome if it would look for pnpm-lock.yaml/pnpm-lock.yml as well.

lockFilename: useYarn ? yarnFilename : npmFilename

Use-case for this: we're using this Action in all @remix-run default stacks (indie-stack, blues-stack & grunge-stack), but people using Remix are either using npm, pnpm or yarn.

separate release job in the workflow

To avoid situation like https://github.com/bahmutov/npm-install/runs/453466017?check_suite_focus=true

Run cycjimmy/semantic-release-action@v2
Error: Command failed: npm ci --only=prod
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/path
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/home/path'
npm ERR!  [OperationalError: EACCES: permission denied, mkdir '/home/path'] {
npm ERR!   cause: [Error: EACCES: permission denied, mkdir '/home/path'] {
npm ERR!     errno: -13,
npm ERR!     code: 'EACCES',
npm ERR!     syscall: 'mkdir',
npm ERR!     path: '/home/path'
npm ERR!   },
npm ERR!   isOperational: true,
npm ERR!   stack: "Error: EACCES: permission denied, mkdir '/home/path'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/home/path'
npm ERR! }

the release went wrong because one of the tests allowed core.exportVariable('npm_config...') to happen, changing the environment. If we separate the release job into its own container, the tests will never affect it.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/example-basic.yml
.github/workflows/example-install-command.yml
.github/workflows/example-node-version.yml
.github/workflows/example-performance.yml
.github/workflows/example-rolling-cache.yml
.github/workflows/example-shrinkwrap.yml
.github/workflows/example-subfolders.yml
.github/workflows/example-without-lock-file.yml
.github/workflows/example-yarn.yml
.github/workflows/main.yml
  • cycjimmy/semantic-release-action v3
npm
package.json
  • @actions/cache 3.2.4
  • @actions/core 1.10.1
  • @actions/exec 1.1.1
  • @actions/io 1.1.3
  • @bahmutov/print-env 2.1.2
  • hasha 5.2.2
  • quote 0.4.0
  • semantic-release 23.0.8
nvm
.nvmrc

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.