axion-release-plugin icon indicating copy to clipboard operation
axion-release-plugin copied to clipboard

Tags always without branch name?

Open mrchass opened this issue 5 years ago • 10 comments

When using VersionCreator "versionWithBranch" I would not only expect "currentVersion" command to return branch suffix on version but also "release" command to create an identical tag in git repository. But git tags only consists of the plain version (like with 'simple' version creation), no mattern from which branch it was called. I minimized my config to exclude any sideeffects:

scmVersion {
    tag {
        prefix = 'version'
    }
    versionCreator 'versionWithBranch'
 }

Is this difference in version creation between these two command intended? Does version decoration only work for cosonle output via "currentVersion" command?

mrchass avatar Nov 13 '19 12:11 mrchass

Some more footage:

> Task :currentVersion
Project version: 1.1.2-feature-test-versioning-2-SNAPSHOT

VS

> Task :verifyRelease
DRY-RUN: uncommitted changes: true
Looking for uncommitted changes.. FAILED

Staged changes:

Unstaged changes:
    modified: build.gradle

DRY-RUN: ahead of remote: false
Checking if branch is ahead of remote..
Checking for snapshot versions..

> Task :release
Creating tag: version-1.1.2
DRY-RUN: creating tag with name: version-1.1.2
Pushing all to remote: origin
DRY-RUN: pushing to remote: origin

mrchass avatar Nov 13 '19 12:11 mrchass

Just like you stated, version decoration works only for output.

The way i see it, version works regardless of branch. Say you had my-feature branch and created a release. Then you merge this branch back to master. Would you want to have release-1.0.0-my-feature tag created even though the my-feature branch no longer exists?

adamdubiel avatar Nov 13 '19 12:11 adamdubiel

I'd like to achieve unique version/build tags over multiple branches. The suffix should only be appended if not on master branch. If merged back to master it should have the "next" master branch's version without suffix. Feature branch versions should start with the current master branch's version and will increment only on build index (via PreleaseVersionIncrementer). Simple example: master 1.10.1 my-feature 1.10.1-b1-my-feature my-feature 1.10.1-b2-my-feature my-feature 1.10.1-b3-my-feature master 1.10.2

mrchass avatar Nov 13 '19 13:11 mrchass

Decorators can help you achieve with regards to version output. However tags do not contain this information and currently there is no way to achieve it.

adamdubiel avatar Nov 13 '19 13:11 adamdubiel

I was playing around with custom (de)serializers but I could not create a tag with appended branch name. Would you name this difference between version output and tagging a feature? Otherwise I would try to find a way to allign this.

mrchass avatar Nov 13 '19 14:11 mrchass

Yes, this is definitely a feature and "works as designed", not a problem or miscalculation. I would not want to change this behaviour, at least not by default (could be changed as a optional flag). However the logic behind parsing tags is already quite sophisticated and adding another element might be hard.

adamdubiel avatar Nov 13 '19 14:11 adamdubiel

OK, to be honest, that is what I have been expected. ;-) To be able to create at least my own decorated version it would be sufficient to only add the scm position as parameter for serializers, like for deserialisation. so it would be possible to include the branch name into the tag. But I think for now I will help myself with a workaround. I will tag manually on feature branches and only do that with the release task on master branch. Thanks for now, probably we will see a more build related tagging approach in a future version! That would be nice!

mrchass avatar Nov 13 '19 17:11 mrchass

@mrchass I managed to achieve something similiar to what you tried:

scmVersion {
    tag.prefix = "${System.getenv("BRANCH_NAME")}"

    ignoreUncommittedChanges = true
    versionCreator {version, position -> position.getBranch() + "_" + version }
}

I use Jenkins for builds which provides BRANCH_NAME by default but I imagine it's possible to do something similiar with all CI servers. This way i get unique tag line per branch. I needed this because I have multiple long lived branches which never merge, with different flavours of project and without this I had constant tag name conflicts.

PAKalucki avatar Jan 15 '20 19:01 PAKalucki

I came across this issue when looking for being able to produce version with branch name. Finally I have decided to use custom tag serializer to solve my problem.

@mrchass It doesn't fully fit your case, but maybe would be enough. We use tag serializer together with useHighestVersion = true and we are fine with having common versioning on all branches. That means unique versions throughout all branches. With your example it would be:

master 1.10.1
my-feature 1.10.2-my-feature
my-feature 1.10.3-my-feature
my-feature 1.10.4-my-feature
master 1.10.5

Configuration could look like this:

tag {
  serialize = { rules, version ->
    def branch = Repository.shortenRefName(project.property("release.overriddenBranchName"))
    if (branch != 'master') {
      def sanitizedBranch = new VersionSanitizer().sanitize(branch)
      return rules.prefix ? rules.prefix + rules.versionSeparator + version + rules.versionSeparator + sanitizedBranch : version + rules.versionSeparator + sanitizedBranch
    }

    return rules.prefix ? rules.prefix + rules.versionSeparator + version : version
  }
}

jozala avatar Jan 29 '20 22:01 jozala

Having same issue. Like @mrchass mentioned adding ScmPosition as parameter for serialiser would do the job

wstrzalka avatar Jul 02 '20 13:07 wstrzalka