'How can I get branch name in semantic-release?

I am trying to create semantic releases with a tag format which includes the branch name. The .releaserc file looks something like this:

{
    "name": "Inder Semantic Release",
    "version": "2.1.0",
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator"
    ],
    "tagFormat": "${want_branch_name_here}-${version}",
    "branches": ['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}, {name: 'gpu', prerelease: true}, {name: 'non-root'}]    
}

I will want to get the branch name in the tag format automatically (i.e. replace ${want_branch_name_here} with the required var that will have the value of branch name), is there a way to achieve that?



Solution 1:[1]

Try giving tags while executing command semantic-release rather than defining tagFormat in releaserc

npx semantic-release -t v\${version}-$(git rev-parse --abbrev-ref HEAD)

Gives you a version like v1.0.2-master

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1