配置语义发布以通过 CLI 发布预发布

use*_*882 5 semantic-versioning semantic-release

我的目标是配置semantic-release为从受保护的分支创建标签,如下所示:

\n
npx semantic-release --plugins @semantic-release/commit-analyzer --branches {'name': 'release/super-feature', 'prerelease': true}\n
Run Code Online (Sandbox Code Playgroud)\n

我期待该标签1.0.0-super-feature被创建。但是,我遇到了一个例外:

\n
[semantic-release] \xe2\x80\xba \xe2\x9c\x96  EINVALIDBRANCH A branch is invalid in the `branches` configuration.\nEach branch in the branches configuration (https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches) must be either a string, a regexp or an object with a name property.\nYour configuration for the problematic branch is ``.\n[10:03:55 AM] [semantic-release] \xe2\x80\xba \xe2\x9c\x96  EINVALIDBRANCH A branch is invalid in the `branches` configuration.\nEach branch in the branches configuration (https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches) must be either a string, a regexp or an object with a name property.\nYour configuration for the problematic branch is ``.\nAggregateError: \n    SemanticReleaseError: A branch is invalid in the `branches` configuration.\n        at module.exports (/usr/local/lib/node_modules/semantic-release/lib/get-error.js:6:10)\n        at /usr/local/lib/node_modules/semantic-release/lib/verify.js:36:19\n        at Array.forEach (<anonymous>)\n        at module.exports (/usr/local/lib/node_modules/semantic-release/lib/verify.js:32:12)\n        at async run (/usr/local/lib/node_modules/semantic-release/index.js:54:3)\n        at async module.exports (/usr/local/lib/node_modules/semantic-release/index.js:260:22)\n        at async module.exports (/usr/local/lib/node_modules/semantic-release/cli.js:55:5)\n    SemanticReleaseError: A branch is invalid in the `branches` configuration.\n        at module.exports (/usr/local/lib/node_modules/semantic-release/lib/get-error.js:6:10)\n        at /usr/local/lib/node_modules/semantic-release/lib/verify.js:36:19\n        at Array.forEach (<anonymous>)\n        at module.exports (/usr/local/lib/node_modules/semantic-release/lib/verify.js:32:12)\n        at async run (/usr/local/lib/node_modules/semantic-release/index.js:54:3)\n        at async module.exports (/usr/local/lib/node_modules/semantic-release/index.js:260:22)\n        at async module.exports (/usr/local/lib/node_modules/semantic-release/cli.js:55:5)\n    at module.exports (/usr/local/lib/node_modules/semantic-release/lib/verify.js:41:11)\n    at processTicksAndRejections (internal/process/task_queues.js:97:5)\n    at async run (/usr/local/lib/node_modules/semantic-release/index.js:54:3)\n    at async module.exports (/usr/local/lib/node_modules/semantic-release/index.js:260:22)\n    at async module.exports (/usr/local/lib/node_modules/semantic-release/cli.js:55:5) {\n  name: 'AggregateError'\n}\n
Run Code Online (Sandbox Code Playgroud)\n

您能否帮助我了解问题所在 - CLI 参数或我的期望?

\n

jca*_*dan 0

根据语义发布文档,我们无法通过 CLI 定义插件选项:

注意:插件选项不能通过 CLI 参数定义,必须在配置文件中定义。

但是,@semantic-release/exec的插件配置 可以通过 CLI 参数调用。不知道其他插件是否也是这样。

@gyomu at #753提供了一个示例命令行,其中包含使用@semantic-release/exec 中的配置选项的参数

npx -p @semantic-release/exec -p semantic-release semantic-release --dry-run --plugins "@semantic-release/commit-analyzer,@semantic-release/exec" --analyzeCommits @semantic-release/commit-analyzer --verifyRelease @semantic-release/exec --verifyReleaseCmd 'echo ${nextRelease.version} > nextRelease.txt'
Run Code Online (Sandbox Code Playgroud)

但是,要操作分支,我必须执行以下操作:

$ echo '{"branches":["master",{"name":"super-feature","prerelease":true}]}' > .releaserc.json && npx semantic-release --dry-run --no-ci --plugins=@semantic-release/commit-analyzer
...
The next release version is 3.8.0-super-feature.1
Run Code Online (Sandbox Code Playgroud)

请记住,根据docs,必须列出发布分支,并且目标分支必须位于远程位置:

注意:如果您的存储库没有发布分支,则语义发布将失败并显示 ERELEASEBRANCHES 错误消息。如果您使用默认配置,可以通过推送主分支来修复此错误。

注意:一旦配置了语义发布,任何有权在这些分支之一上推送提交的用户都将能够发布版本。建议保护这些分支,例如使用 GitHub 保护的分支。

我还发现无法在分支名称中使用正斜杠 (/)。因此,请考虑super-feature改用。