如果要发布新的主要版本,我该如何使语义发布中止并失败?

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

我想对 semantic-release 添加一个检查以仅允许它发布次要版本和补丁版本。如果它检测到需要执行新的主要版本,我希望进程中止并失败(而不是继续执行版本)。我该怎么做?

现有插件

我已经为执行此操作的插件创建了一个 npm 包。

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",
    ]
}

自定义插件

如果发布的包不能解决您的特定需求,您可以创建一个语义发布插件来实现 verifyRelease 步骤并根据下一个发布类型抛出错误。

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