Skip to content

Placeholder default value and describe.tag do not appear compatible #128

@electrofelix

Description

@electrofelix

Trying to create a template repository for teams to create projects from and I'm finding that the describe.tag doesn't quite work with the placeholder default values functionality.

My configuration

version = '0.0.0-SNAPSHOT'
gitVersioning.apply {
    refs {
        considerTagsOnBranches = true
        tag('v(?<version>.*)') {
            version = '${ref.version}'
        }
        branch('main') {
            version = '${describe.tag.version.major:-0}.${describe.tag.version.minor:-0}.${describe.tag.version.patch.next:-0}-SNAPSHOT'
        }
        branch('.+') {
            version = '${describe.tag:-0.0.0}-${describe.distance:-1}-SNAPSHOT'
        }
    }
}

If there are no tags currently, this will work fine for the main branch, but I've discovered that describe.tag will return root instead of being replaced with 0.0.0. It seems like it should allow for the placeholder to take over here rather than always returning root in this case. Perhaps that was necessary before the placeholders functionality was available?

My work around is to use the following since it isn't an issue once you try to access the describe.tag.version:

version = '0.0.0-SNAPSHOT'
gitVersioning.apply {
    refs {
        considerTagsOnBranches = true
        tag('v(?<version>.*)') {
            version = '${ref.version}'
        }

        branch('main') {
            version = '${describe.tag.version.major:-0}.${describe.tag.version.minor:-0}.${describe.tag.version.patch.next:-0}-SNAPSHOT'
        }
        branch('.+') {
            version = '${describe.tag.version}-${describe.distance:-1}-SNAPSHOT'
        }
    }
}

So perhaps just a documentation note indicating that describe.tag will always return some value once the repository is not shallow?

Additionally this still breaks when the clone is shallow, and will result in the following:

* What went wrong:
A problem occurred evaluating root project 'develop-java-library-workflows'.
> java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalStateException: couldn't find matching tag in shallow git repository

This certainly makes sense if there were no default placeholders, and it's definitely useful to emit that no tag could be found in a shallow git repository, but it feels that with the placeholder with a default value defined that it should gracefully accept the default value instead?

This is mostly an issue with github actions/checkout and reusable workflows where not expecting to do full clones by default, nor is it straight forward to pass env vars to reusable workflows either.

For the moment I'll look at disabling or trying to make those unshallow, though I might try and automatically unshallow a clone with some scripting before the plugin applies.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions