0

I want to edit my package version when I make a merge on Gitlab. I try with Husky like that but it's not working.

{
   "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\"",
   }
}

And I try with Gitlab-CI like that

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

And I get an error message

$ 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! 

I can't do it on local because branches staging and master are protected

Monsieur Sam
  • 333
  • 1
  • 6
  • 20

1 Answers1

0

Since this is running in CI, git likely doesn't have its config set up, especially with user.name and user.email which it uses for the author when you commit. I'd add these in a before_script step:

enable_merge:
  stage: staging_deploy
  only:
    - staging
  before_script:
    - git config --global user.name "Gitlab CI"
    - git config --global user.email "an-email-address@example.com"
  script:
    - npm version minor
Adam Marshall
  • 6,369
  • 1
  • 29
  • 45