Search code examples
semantic-release

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

  • 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