1.6.0 • Published 17 days ago

@sankhyalabs/semantic-release-backmerge v1.6.0

Weekly downloads
-
License
MIT
Repository
-
Last release
17 days ago

semantic-release-backmerge

semantic-release plugin to back-merge a release in the project's git repository.

Note: semantic-release in its core is not intended to be used with Git Flow where a stable (master/main) branch and a unstable branch (develop/next) exist. This plugin enables to use semantic-release with such branches, however it does NOT guarantee using semantic-release with Git Flow.

Especially automatic hotfix releases may not be possible as those usually lead to merge conflicts with develop that have to be resolved manually. In such cases the release workflow will fail, causing a red pipeline!

StepDescription
verifyConditionsVerify the access to the remote Git repository, the 'branchName' option configuration.
doneCreate a back-merge into the configured branch if the release is successful.

Install

$ npm i @sankhyalabs/semantic-release-backmerge -D

Usage

The plugin can be configured in the semantic-release configuration file:

Note: As this plugin will rebase your "develop" branch onto your "master" branch, you may not have any unstaged files in your workspace. If you do, you may set the clearWorkspace option to stash them and restore them with restoreWorkspace if needed.

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator", 
    ["@sankhyalabs/semantic-release-backmerge", {
      "branches": [
        { "from": "master", "to": "release" }, 
        { "from": "release", "to": "develop" }
      ],
      "plugins": [
        ["@semantic-release/exec", {
          "successCmd": "echo 'Version in master is ${nextRelease.version}' > test.txt && git add test.txt"
        }]
      ]
    }]
  ]
}

Configuration

Options

OptionsDescriptionDefault
branchesThe branches where the release is merged into. See branches.'develop'
backmergeStrategyHow to perform the backmerge. See backmergeStrategy.rebase
pluginsPlugins defined here may stage files to be included in a back-merge commit. See plugins.[]
messageThe message for the back-merge commit (if files were changed by plugins. See message.chore(release): Preparations for next release [skip ci]
forcePushIf set the back-merge will be force-pushed. See forcePush.false
skipCiPushThe push command will execute with skip ci (git push -o ci.skip). See skipCiPush.true
clearWorkspaceWhether to stash the current workspace before backmerge. See clearWorkspace.false
restoreWorkspaceRestore the stashed workspace after backmerge completed. See restoreWorkspace.false
mergeModeMode for merging (when backmergeStrategy=merge). See mergeMode.none

branches

Branch names that should receive the back-merge. If none is given, the default value is used. This argument takes a list of branch name strings or objects. A branch object looks like this: {"from": "master", "to": "dev"} In this example, a release from master branch is merged into dev branch. With that you can perform conditional backmerges, i.e. backmerges that only occur when merged from a certain branch.

Here is an example where all releases will backmerge into develop and releases from next branch will be backmerged into staging as well.

branches: ["develop", {"from": "master", "to": "release"}, {"from": "release", "to": "develop"}]

You may use Lodash template variables in branch name strings. The following variables are available:

ParameterDescription
branchThe branch from which the release is done.
branch.nameThe branch name.
branch.typeThe type of branch.
branch.channelThe distribution channel on which to publish releases from this branch.
branch.rangeThe range of semantic versions to support on this branch.
branch.prereleaseThe pre-release detonation to append to semantic versions released from this branch.

plugins

Use this if you have to make changes to the files for your development branch (e.g. setting a -dev version). It uses the same plugin structure as semantic-release, but only trigger the "success" step after rebase from develop onto master is done and just before it is pushed.

Note: Please make sure that the files you changed are staged to Git workspace. Only then they will be committed.

message

The message for the back-merge commit is generated with Lodash template. The following variables are available:

ParameterDescription
branchThe branch from which the release is done.
branch.nameThe branch name.
branch.typeThe type of branch.
branch.channelThe distribution channel on which to publish releases from this branch.
branch.rangeThe range of semantic versions to support on this branch.
branch.prereleaseThe pre-release detonation to append to semantic versions released from this branch.
lastReleaseObject with version, gitTag and gitHead of the last release.
nextReleaseObject with version, gitTag, gitHead and notes of the release being done.

allowSameBranchMerge

If you want to be able to back-merge into the same branch as the branch that was being released from, enable this setting.

Note: It is recommended to include [skip ci] in the commit message to not trigger a new build. Some CI service support the [skip ci] keyword only in the subject of the message.

forcePush

Setting this option will force-push the commits from back-merge onto the develop branch.

Warning: This will override commits that are not in the develop branch, so make sure that really is what you want!

skipCiPush

Setting this option will execute push with ci.skip to not trigger a new build. Even if the commit message doesn't have [skip ci] command, the CI pipeline will be skipped.

Note: The command git push -o ci.skip will be executed with push option. See push option.

clearWorkspace

Setting this option will stash all uncommitted changes from Git workspace before attempting rebase.

restoreWorkspace

Setting this option will restore the stashed changes after the backmerge completed.

backmergeStrategy

This setting will determine whether the develop branch should be rebased onto master or master should be merged into develop. Allowed values: rebase (default), merge

mergeMode

This setting will be used to determine how merge conflicts are resolved when using the merge backmerge strategy.

Allowed values: none (default), ours, theirs

none = no merge conflict resolve (process will abort on merge conflicts!) ours = apply changes from develop branch theirs = apply changes from master branch