Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is `npm version` not committing the updated package.json?

I'm using Travis to publish an npm module to npmjs.org.

The relevant part of .travis.yml is:

before_deploy:
  - npm version minor
  - git config credential.helper "store --file=.git/credentials"
  - echo "https://${GH_TOKEN}:@github.com" > .git/credentials
  - git push && git push --tags

I'm seeing that the tag is created, but the change to package.json is not making it to the git repo.

Looking at the logs from travis-ci.org, I see:

$ npm version minor
v1.3.0

$ git config credential.helper "store --file=.git/credentials"

$ echo "https://${GH_TOKEN}:@github.com" > .git/credentials

$ git push && git push --tags
Everything up-to-date
Counting objects: 6, done.
Delta compression using up to 16 threads.
Compressing objects:  25% (1/4)   
Compressing objects:  50% (2/4)   
Compressing objects:  75% (3/4)   
Compressing objects: 100% (4/4)   
Compressing objects: 100% (4/4), done.
Writing objects:  25% (1/4)   
Writing objects:  50% (2/4)   
Writing objects:  75% (3/4)   
Writing objects: 100% (4/4)   
Writing objects: 100% (4/4), 411 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To https://github.com/Jellyvision/basecamp-api.git
 * [new tag]         v1.3.0 -> v1.3.0

So, it's pretty clear that the change to package.json didn't get added or committed, since the push shows that everything is up to date.

The new tag is pushed up, for what it's worth.

When I run npm version minor locally, I see the new commit being generated as expected, so I'm guessing this is environment related, but I can't find anything in the documentation that suggests that npm version would work differently in a CI environment.

Any suggestions as to what's going on here?

like image 514
Dancrumb Avatar asked Nov 10 '22 03:11

Dancrumb


1 Answers

We created this publish.sh script to first update the npm package version and then updating our repository ...

#!/bin/sh
npm version $1
git push --follow-tags
npm publish

Example Usage:

%> ./publish.sh 2.2.41

Notice the use of git push --follow-tags. This has the effect of changing the version in the package.json file, creating a tag release in git using the version in the package.json and updating the master branch.

like image 102
ra9r Avatar answered Nov 15 '22 05:11

ra9r