Merging back to develop after running semantic-release
Here is the issue:
- Push to master
- CI pipeline runs semantic-release
- semantic-release updates changelog and package.json
- Changes never get back to develop branch
Normally this isn't a big issue other than you develop branch won't have the latest changelog info or the correct version in your package.json.
For us, we're building our Storybook documentation from the develop branch. We're pulling the changelog into Storybook so it's visible there, but it's pulling from the develop branch. Not ideal.
How to get the develop branch
The trick was understanding that Bitbucket only pulls the specific branch it needs. Initially I tried to just merge the changes into develop but it kept saying develop didn't exist.
git checkout develop// error: pathspec 'develop' did not match any file(s) known to git
clone: all
My first solution was to clone the entire repository so that the develop branch would exist. This was done by a Bitbucket pipeline property clone
. With this property you can specify the depth to pull, which is equivalent to the last x number of commit. Or by specifying all it will pull the entire repository.
pipelines:branches:master:- step:name: Deploy to Productionclone:depth: allscript:- ...
Clone can also be useful for steps that you're only working with artifacts of previous steps and don't need to clone anything. You can set clone enabled to false to save the time it would take to clone.
pipelines:branches:master:- step:name: Deploy to Productionclone:enabled: falsescript:- ...
git remote set-branches
If we clone the entire repo we're pulling a lot of stuff we just don't need and when we're dealing with CI pipelines we want to keep it to the minimum amount of work necessary.
By using the git remote set-branches command, we can add just the specific branch we need to our local (local to the CI) repo.
git remote set-branches --add origin develop
Now we can checkout the develop branch so we can merge the changes from master into it.
git fetchgit checkout developgit push
Done! Now every time we push to master it will run semantic-release then push the changelog and package.json changes back into develop automatically.