Standard-version: Step committing message

Created on 25 Mar 2019  Â·  5Comments  Â·  Source: conventional-changelog/standard-version

I've seen that the message in the commit step is not correct. That is the message that is displayed on the terminal when executing a release script that creates the commit. Instead of committing CHANGELOG.md I'd expect it to be committing package.json package-lock.json CHANGELOG.md or just committing staged files.
I'm running standard-version 5.0.1.

$ npm run release

> ...
> standard-version --skip.commit --skip.tag

✔ Running lifecycle script "prerelease"
ℹ - execute command: "if [[ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]]; then exit -1; fi"
✔ bumping version in package.json from 3.4.0 to 3.4.1
✔ bumping version in package-lock.json from 3.4.0 to 3.4.1
✔ outputting changes to CHANGELOG.md

$ npm run release:ok

> ...
> standard-version --sign --commit-all --skip.bump --skip.changelog

✔ Running lifecycle script "precommit"
ℹ - execute command: "git add package.json package-lock.json CHANGELOG.md"
✔ committing CHANGELOG.md
husky > commit-msg (node v11.10.0)

â§—   input: chore(release): 3.4.1
✔   found 0 problems, 0 warnings
    (Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )



✔ tagging release v3.4.1
ℹ Run `git push --follow-tags origin master && npm publish` to publish

package.json

  "scripts": {
    "release": "standard-version --skip.commit --skip.tag",
    "release:ok": "standard-version --sign --commit-all --skip.bump --skip.changelog",
    "release:publish": "git push --follow-tags"
  },
  "standard-version": {
    "scripts": {
      "prerelease": "if [[ \"$(git rev-parse --abbrev-ref HEAD)\" != \"master\" ]]; then exit -1; fi",
      "precommit": "git add package.json package-lock.json CHANGELOG.md"
    }
  },
}
bug help wanted triaged

All 5 comments

Looks like a minor bug. PR welcome!

I've just tested with the following snippet and that shows the correct message for committing .... I've had a brief look at the standard-version code and looks like the arguments are passed through correctly. Issue seems to only appear when not all steps are performed at once. E.g. in my example above I run the following two commands, where the second command seems to only commit the CHANGELOG.md. In the _Example 2_, I also don't need to manually git add anything and no need to use --commit-all.
So, seems like the second step doesn't do the expected steps. I'll have a more detailed look at the standard-version scripts when I have time. Some pointers to where to look would be greatly appreciated.

  1. standard-version --skip.commit --skip.tag
  2. standard-version --sign --skip.bump --skip.changelog


Example 2

$ yarn standard-version --sign --dry-run

> ...
> standard-version --sign "--dry-run"

✔ Running lifecycle script "prerelease"
ℹ - execute command: "if [[ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]]; then exit -1; fi"
✔ bumping version in package.json from 0.1.0 to 0.2.0
✔ bumping version in package-lock.json from 0.1.0 to 0.2.0
✔ created CHANGELOG.md
✔ outputting changes to CHANGELOG.md

---
...
---

✔ committing package-lock.json and package.json and CHANGELOG.md
✔ tagging release v0.2.0
ℹ Run `git push --follow-tags origin master && npm publish` to publish

I did some researching and it is definitely due to the steps being separated. More specifically, bump not being executed on release:ok so bump.getUpdatedConfigs() returns nothing. Therefore, toAdd here does not contain the _package.json_ and _package-lock.json_.

@stevemao This issue is also worse than I described in my previous messages since package.json and package-lock.json are also not added to git, so it will only commit the CHANGELOG.md in my release:ok script.

An easy fix, in my case at least, could be to

  1. Add an postcommit script that will git add the package.json and package-lock.json
  2. Add the following code just above this line, which will result in the message ✔ committing CHANGELOG.md and all staged files
```javascript
  if (args.commitAll) {
    msg += ' and %s'
    paths.push('all staged files');
  }
```

I think a nicer solution would be to somehow know what files were updated in the _bump_ step so those can be automatically added. Would that be a feasible option? I'm not sure how that would work, maybe by separating the updateConfigs function in bump in one function that determines which files need to be updated, that function can then be called from the commit step instead, and another function that actually performs the update?

Based on the reactions on above points, I'll be happy to change the code and create an PR for it.

@vidavidorra Thanks for the write up and time spent on investigating this issue. I believe you know more than us at this point and a big PR might be hard for us to merge (but PR still welcome!!). @bcoe @hutson any thoughts? @vidavidorra perhaps you could join our slack channel and have a chat with people. Cheers.

I've added this in #320, which was released in v6.0.0 so I'll close this.

Was this page helpful?
0 / 5 - 0 ratings