在合并请求中使用 husky 在 gitlab 上编辑包版本

问题描述

我想在 Gitlab 上进行合并时编辑我的包版本。我尝试过这样的赫斯基,但它不起作用。

{
   "hooks":{
       "pre-commit": "npm run lint:fix","post-merge": "(git-branch-is staging && npm version minor || git-branch-is master && npm version major) && git add . && git commit -m \"new version\"",}
}

我像这样尝试使用 Gitlab-CI

enable_merge:
  stage: staging_deploy
  only:
    - staging
  script:
    - npm version minor

然后我收到一条错误消息

$ npm version minor
v0.5.0
npm ERR! code 128
npm ERR! Command Failed: git commit -m 0.5.0
npm ERR! 
npm ERR! *** Please tell me who you are.
npm ERR! 
npm ERR! Run
npm ERR! 

我不能在本地做,因为分支 staging 和 master 是受保护的

解决方法

由于这是在 CI 中运行,因此 git 可能没有设置其配置,尤其是当您提交时它用于作者的 user.nameuser.email。我会在 before_script 步骤中添加这些:

enable_merge:
  stage: staging_deploy
  only:
    - staging
  before_script:
    - git config --global user.name "Gitlab CI"
    - git config --global user.email "[email protected]"
  script:
    - npm version minor