qoomon / maven-git-versioning-extension

This extension will set project version, based on current Git branch or tag.
GNU General Public License v3.0
305 stars 87 forks source link

Match a tag instead of branch #253

Closed kjozsa closed 1 year ago

kjozsa commented 1 year ago

Our scenario: the branch HEAD also has a tag (say, v1.25.0). If I checkout the branch, this plugin matches the branch, generating a version like 1.25.1-SNAPSHOT. If I checkout the tag directly instead (which refers to the same commit as the branch head!), then the generated version is 1.25.0, right what I'd expect.

Would it be possible to match the tag on the branch's changeset when the branch is checked out, instead of the branch itself? That would make it really convenient to just create a tag on the HEAD of the branch and automatically end up with a release version when built by CI/CD..

Can you consider this feature, even as an optinal one, enabled by some config setting?

qoomon commented 1 year ago

you can use the option considerTagsOnBranches see the readme

kjozsa commented 1 year ago

wow, that sounds exactly like what I need!! Let me test on Monday and I'll close my question then - thanks much!

kjozsa commented 1 year ago

Thanks, that does exactly what I was looking for :)

merikan commented 1 year ago

@kjozsa Sorry to bother you, but do you have an example of the configuration to get the same behavior as jgitver? Just in the process of creating a release and can't quite get it to work.

kjozsa commented 1 year ago

here's my config

<configuration xmlns="https://github.com/qoomon/maven-git-versioning-extension"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="https://github.com/qoomon/maven-git-versioning-extension https://qoomon.github.io/maven-git-versioning-extension/configuration-9.4.0.xsd">

  <refs considerTagsOnBranches="true">
    <ref type="tag">
      <pattern><![CDATA[v(?<version>.*)]]></pattern>
      <version>${ref.version}</version>
      <properties>
        <project.build.outputTimestamp>${commit.timestamp}</project.build.outputTimestamp>
      </properties>
    </ref>
    <ref type="branch">
      <pattern>(main|release.*)</pattern>
      <version>${describe.tag.version.major}.${describe.tag.version.minor}.${describe.tag.version.patch.next}-SNAPSHOT</version>
      <properties>
        <project.build.outputTimestamp>${commit.timestamp}</project.build.outputTimestamp>
      </properties>
    </ref>
    <ref type="branch">
      <pattern><![CDATA[feature/(?<feature>.+)]]></pattern>
      <version>${describe.tag.version}-${ref.feature}-SNAPSHOT</version>
      <properties>
        <project.build.outputTimestamp>${commit.timestamp}</project.build.outputTimestamp>
      </properties>
    </ref>
  </refs>
  <rev>
    <version>${commit}</version>
  </rev>
</configuration>