Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
electrofelix opened this issue Jul 6, 2023 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@electrofelix
Copy link

electrofelix commented Jul 6, 2023

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.

@qoomon qoomon self-assigned this Jul 7, 2023
@qoomon qoomon added the enhancement New feature or request label Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants