greenkeeperio / greenkeeper-lockfile

:lock: Your lockfile, up to date, all the time
https://greenkeeper.io
182 stars 73 forks source link

How to make this work with `npm ci`? #156

Open Stupidism opened 6 years ago

Stupidism commented 6 years ago

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

freaktechnik commented 6 years ago

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

daffl commented 6 years ago

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).

espy commented 6 years ago

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.

BerkeleyTrue commented 6 years ago

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

freaktechnik commented 6 years ago

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.

karolis-sh commented 5 years ago

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;
idolize commented 4 years ago

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

freaktechnik commented 4 years ago

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.