1

I have setup a CircleCI job to run semantic-release, but I would like CircleCI to fail when no changes are found. i.e. when semantic-release outputs:

There are no relevant changes, so no new version is released

CircleCi snippet for the runline.

  - run:
      name: Semantic Release
      command: npm run semantic-release
halfer
  • 19,824
  • 17
  • 99
  • 186
jon_robins
  • 11
  • 1

3 Answers3

1

Good question. I haven't tested this and I don't know Node.js well in order to quickly test but here's my suggestion.

grep returns an exit code of 0 if it finds something and 1 if it doesn't. Any exit code other than 0 means a failure to CircleCI. Grep's -q flag means quiet, don't output text and the && means only run if the previous command passes. So, this might work for you:

  - run:
      name: Semantic Release
      # Fail if there are no changes
      command: npm run semantic-release | grep -q "There are no relevant changes, so no new version is released." && exit 1

Again, I haven't personally tested it so I don't know how semantic-release outputs things but this might work.

FelicianoTech
  • 3,894
  • 2
  • 13
  • 18
1

This is intentionally not supported by semantic-release, however, if you need your pipelines to fail if no release will be created, you can either search for that specific text as suggested, or you can use a plugin to do this.

npm install --save-dev commit-analyzer-fail-on-no-release

In your semantic-release configuration file, replace the default commit analyzer with commit-analyzer-fail-on-no-release. All configuration options pass through to the default plugin if you have configured @semantic-release/commit-analyzer.

.releaserc

{
  "plugins": [
    "commit-analyzer-fail-on-no-release"
   ]
 }

Learn more about this plugin

evelynhathaway
  • 1,670
  • 14
  • 18
0

semantic-release does not errors out in the case of no release on purpose.

If you add a commit that doesn't warrant a release (for example a commit that modify a comment in the code or the code formatting) you don't want your CI to fail.

In short, no making a release when no release is needed is a not an error case, therefore the CI should not errors out.