如何为semantic-release/github插件push标签时添加--no-verify至execaOptions
解决semantic-release/github插件推送标签时跳过Git钩子的问题
方案1:临时修改Git配置(最简单直接)
通过临时设置Git仓库级配置,让git push自动跳过钩子,执行完语义化发布后再恢复配置:
# 临时开启push跳过钩子 git config push.noVerify true # 执行语义化发布命令 npx semantic-release --branches release --no-ci # 恢复原配置(若之前未设置过该配置,直接删除即可) git config --unset push.noVerify
原理是git push --no-verify等价于通过git config push.noVerify true启用仓库级跳过设置,semantic-release调用git push --tag时会自动应用该配置,无需修改插件代码或原有配置。
方案2:自定义semantic-release插件(精准控制范围)
如果需要仅针对github插件的publish步骤生效,而非全局修改Git配置,可以编写极简自定义插件,在github插件执行push前临时修改配置,执行后自动恢复:
- 在项目根目录创建
custom-no-verify-plugin.js:
module.exports = { publish: async (pluginConfig, context) => { // 临时设置push跳过钩子 await context.exec('git', ['config', 'push.noVerify', 'true']); try { // 不干扰原有流程,让github插件继续执行publish return; } finally { // 无论发布成功/失败,都恢复原配置 await context.exec('git', ['config', '--unset', 'push.noVerify']); } }, };
- 在
release.config.js中引入该自定义插件,放在@semantic-release/github之前:
module.exports = { branches: ['release'], plugins: [ './custom-no-verify-plugin.js', '@semantic-release/github', // 其他插件... ], };
补充说明
目前semantic-release/github插件未暴露直接传递--no-verify参数的配置项,插件内部调用git push时也未预留额外参数入口,因此只能通过上述间接方式实现需求。
内容的提问来源于stack exchange,提问作者WesternGun
相关产品推荐
相关产品推荐

