greenkeeper-lockfile icon indicating copy to clipboard operation
greenkeeper-lockfile copied to clipboard

How to make this work with `npm ci`?

Open Stupidism opened this issue 6 years ago • 8 comments

I tried in travis and circleci:

install:
  - npm i -g npm@6
  - npm ci

# greenkeeper update npm lockfile
before_install:
  - npm install -g greenkeeper-lockfile@1
  - greenkeeper-lockfile-update
after_success:
  - greenkeeper-lockfile-upload
  - bash <(curl -s https://codecov.io/bash)

      - run:
          name: Install greenkeeper-lockfile
          command: npm i greenkeeper-lockfile@1
      - run:
          name: Update lock file
          command: ./node_modules/.bin/greenkeeper-lockfile-update
      - run:
          name: Install dependencies in ci mode
          command: npm ci
# Prevent to upload lockfile twice, because travis will upload, too.
#      - run:
#          name: Upload new lock file
#          command: ./node_modules/.bin/greenkeeper-lockfile-upload

But it always complains:

This build should not update the lockfile. It could be a PR, not a branch build.

ci scripts: travis circleci

ci results: travis circleci

Stupidism avatar May 25 '18 06:05 Stupidism

It seems travis now defaults to npm ci, which means this is much more often a problem.

Traivs CI run: https://travis-ci.org/freaktechnik/github-stub/builds/386634973 .travis.yml: https://github.com/freaktechnik/github-stub/blob/67273161087b04074aa829be1f134dd52088f2ee/.travis.yml

freaktechnik avatar Jun 01 '18 13:06 freaktechnik

It looks like this will be happening now for all new Greenkeeper PRs with a breaking version change that run on the latest Node. It can be solved by reverting the default script in your .travis.yml to

install: npm install

I ended up getting the same error message as @Stupidism setting up greenkeeper-lockfile and digging into the code a little, I'm wondering if the travis.correctBuild flag at https://github.com/greenkeeperio/greenkeeper-lockfile/blob/master/ci-services/travis.js#L14 should really check if it is a Greenkeeper PR branch.

That's what seems to be happening for some other CI services already (e.g. for Codeship at https://github.com/greenkeeperio/greenkeeper-lockfile/blob/master/ci-services/codeship.js#L33).

daffl avatar Jun 02 '18 18:06 daffl

Hi @daffl , thanks for jumping in here, that is indeed the way to go for now 👍

We’ve got the problem on our list and will deal with it within the monorepo PR for gk-lockfile that we’re currently working on.

espy avatar Jun 03 '18 08:06 espy

I've created a script that will conditionally use npm install/npm ci on travis ci depending on whether the branch is a greenkeeper branch.

A gist including travis config example. https://gist.github.com/BerkeleyTrue/ff98c0aa27c21e1616f6bf910f444aee

BerkeleyTrue avatar Jun 05 '18 03:06 BerkeleyTrue

install: case $TRAVIS_BRANCH in greenkeeper*) npm i;; *) npm ci;; esac; is a one-liner to make the same choice as the script by @BerkeleyTrue directly in the .travis.yml.

freaktechnik avatar Jun 15 '18 19:06 freaktechnik

For node 9 I had to add:

before_install:
  - if [[ `npm -v` != 6* ]]; then npm install -g npm@6; fi

So the full'ish script:

node_js:
  - '10'
  - '9'
  - '8'
before_install:
  - if [[ `npm -v` != 6* ]]; then npm install -g npm@6; fi
install: case $TRAVIS_BRANCH in greenkeeper*) npm i;; *) npm ci;; esac;

karolis-sh avatar Dec 11 '18 21:12 karolis-sh

Any update as to when we can expect a more official fix? Thanks!

idolize avatar Dec 10 '19 23:12 idolize

https://blog.greenkeeper.io/announcing-native-lockfile-support-85381a37a0d0 or https://blog.greenkeeper.io/private-dependency-support-for-native-lockfiles-8083348060e3 is the more official fix.

freaktechnik avatar Dec 10 '19 23:12 freaktechnik