Pedro A
Pedro A

Reputation: 4323

How can I make semantic-release abort and fail if it would release a new major version?

I would like to add a check to semantic-release to only allow it to publish minor and patch releases. If it detects the need to perform a new major release, I want the process to be aborted and fail (instead of proceeding to perform the release). How can I do this?

Upvotes: 1

Views: 436

Answers (1)

evelynhathaway
evelynhathaway

Reputation: 1887

Existing Plugin

I have created an npm package for a plugin that does this.

evelynhathaway/semantic-release-fail-on-major-bump

npm install --save-dev semantic-release-fail-on-major-bump

.releaserc

{
    "plugins": [
        "semantic-release-fail-on-major-bump",
    ]
}

Custom Plugin

If the published package doesn't solve your specific needs, you can create a semantic-release plugin that implements the verifyRelease step and throws an error based on the next release type.

plugin/index.js

function verifyRelease (pluginConfig, context) {
    if (context.nextRelease.type === "major") {
        throw new Error("We cannot publish breaking changes at this time.");
    }
}

module.exports = {verifyRelease};

Learn how to make semantic-release plugins

Upvotes: 2

Related Questions