Alwaysblue
Alwaysblue

Reputation: 11830

increment git version with travis when publishing a repo

I want to Travis to publish npm whenever I accept dependent bot changes. I have added npm email and auth token.

My travis configuration is this right now (which I am not sure is correct or not)

language: node_js
node_js:
  - "node"
install:
  - "npm install"
script:
  - "npm run test"
before_deploy: 

deploy:
  provider: npm
  email: "$npm_email"
  api_key: "$npm_token"
  on:
    branch: production

Where npm test looks like this

  "scripts": {
    "test": "jest"
 }

How can I make travis to increment npm package version and have that package version also on the git? same for changelog.md?

Upvotes: 4

Views: 239

Answers (2)

cfstras
cfstras

Reputation: 1858

A nice fully-fledged solution for this is semantic-release.

When using semantic-release, your commit messages need to adhere to a specific format. You will then configure your travis pipeline to run semantic-release, which parses your commits, generates a changelog, a new version number, and pushes the changes as a new commit (for the changelog) and a new tag to your repo.

The setup is a little more involved, but you will have a stable solution which ensures your version numbers make sense. Also, you get "free" automatically generated changelogs.

There is also a recipe for travis which should help to get it set up.

Upvotes: 2

MikZuit
MikZuit

Reputation: 734

Setting a dependency version is a manual runtime or programming language task, Travis is CI & CD tool , you SHOULD NOT automated with travis.

You might need a tool to inspect packages, dependencies like Snyk so it might check vulnerabilities or posible upgradable packages.

Anyway under your own risk you could upgrade your packages in before_install like this:

language: node_js
node_js:
  - "node"
before_install:
  - "npm update <package name>"  ## change your package to update.
install:
  - "npm install"
script:
  - "npm run test"
before_deploy: 

deploy:
  provider: npm
  email: "$npm_email"
  api_key: "$npm_token"
  on:
    branch: production

Upvotes: 0

Related Questions