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

[1.13.1] Evaluating scmVersion.version prevents further updates to the extension #392

Closed
mateuszkwiecinski opened this issue Mar 29, 2021 · 12 comments

Comments

@mateuszkwiecinski
Copy link

Context

Using Gradle extensions often requies caling afterEvaluate block to read user data as they are not available right after registering an extension.
I have to defer configuring axion-release-plugin exactly for that reason. After migrating to 1.13.1 I noticed there is an additional limiatation introduced in that version.

Repro steps

Given following code and having a tag prefix1.2.3 on one of previous commits

plugins {
    id 'pl.allegro.tech.build.axion-release' version '1.13.1'
}

// logger.quiet("Invalid version $scmVersion.version")

afterEvaluate {
    scmVersion.tag {
        prefix = "prefix"
    }

    logger.quiet("Valid version $scmVersion.version")
    version = scmVersion.version
}

./gradlew currentVersion will print 1.2.3-SNAPSHOT, which is expected.

However, If I uncomment the code, the ./gardlew currentVersion tasks returns 0.1.0-SNAPSHOT.

Expected result

I'd expect evaluating scmVersion.version doesn't have side effects.

Unfortunately I couldn't find in the code why it happens and what the consequences might be. That's definitely a behavior change when compared with 1.12.1 and doesn't seem to be expected behavior in Gradle ecosystem.

@bgalek
Copy link
Member

bgalek commented Mar 29, 2021

I'll look at this tomorrow! Thanks for detailed issue submission!

@bgalek
Copy link
Member

bgalek commented Mar 29, 2021

@grational isn't that also Your case?

@mateuszkwiecinski
Copy link
Author

Just FYI: afterEvaluate block isn't needed. Simpler repro could be:

logger.quiet("Invalid version $scmVersion.version")
scmVersion.tag.prefix = "prefix"
logger.quiet("Valid version $scmVersion.version")

the latter will always print 0.1.0-SNAPSHOT

@dominikbrandon
Copy link
Contributor

@mateuszkwiecinski I wanted to look into that, but I couldn't reproduce the issue. Would you mind sharing more details?

I tried running ./gradlew currentVersion having the following build.gradle:

plugins {
    id 'pl.allegro.tech.build.axion-release' version '1.13.1'
}

logger.quiet("Invalid version $scmVersion.version")

afterEvaluate {
    scmVersion.tag {
        prefix = "prefix"
    }

    logger.quiet("Valid version $scmVersion.version")
    version = scmVersion.version
}

and

plugins {
    id 'pl.allegro.tech.build.axion-release' version '1.13.1'
}

logger.quiet("Invalid version $scmVersion.version")
scmVersion.tag.prefix = "prefix"
logger.quiet("Valid version $scmVersion.version")

Both approaches resulted in the following output:

➜  ./gradlew currentVersion

> Configure project :
Invalid version 1.2.4-SNAPSHOT
Valid version 1.2.4-SNAPSHOT

> Task :currentVersion

Project version: 1.2.4-SNAPSHOT

These are the commits I have in the repo (please note the tag).

commit db32635816e9d262a867b2b941f0153cb5bf523b (HEAD -> main)
Date:   Fri Oct 15 15:19:23 2021 +0200

    commit message

commit ddb9c6edabb76adb19068da93294e8d72d90b39a (tag: v1.2.3)
Date:   Fri Oct 15 15:11:40 2021 +0200

    commit message

And these are the tags:

➜  git tag
v1.2.3

@mateuszkwiecinski
Copy link
Author

mateuszkwiecinski commented Oct 18, 2021

@dominikbrandon Thanks for looking into the issue.

Result you're getting Project version: 1.2.4-SNAPSHOT is not valid for your setup. The expected output is 0.1.0-SNAPSHOT. The plugin ignores scmVersion.tag.prefix = "prefix" you set and continues using default v prefix.
Please do push new tag: git tag prefix7.8.9 and then see what happens if you comment logger.quiet("Invalid version $scmVersion.version") line out

@dominikbrandon
Copy link
Contributor

Ok, I got it now. Thanks for the explanation. You're right that this gets cached. You can see that here. When you look inside the ensureVersionExists(), you'll notice that the version gets resolved only once, at the first attempt. It's unclear to me why it works like that - I can only suspect it's for performance reasons. Maybe @bgalek knows what's behind that?

I can see two approaches here. First is to drop this caching mechanism, which sounds unsafe considering the fact that somebody explicitly made it work like that. We can only do that knowing the author's intention. Second is to introduce another method, e.g. getUncachedVersion(), which would return the version omitting the cached one. Actually there is already such a method, but it doesn't work as intended, because there is still the context cached.

@mateuszkwiecinski would such another accessor solve the problem for you?
@bgalek what do you think about that? Which way do you suggest taking?

@bgalek
Copy link
Member

bgalek commented Oct 19, 2021

As I recall it was performance issue for big repositories, additional method sounds ok to me ;)

@bgalek bgalek closed this as completed in 905f32c Oct 24, 2021
@manideepla
Copy link

manideepla commented May 28, 2024

Hi, sorry for bringing up an old issue, but I'm getting this while running a CI pipeline. The ./gradlew currentVersion is always returning 0.1.0 no matter what the latest tag is.

I'm depending on this output to do something else. Can I get some hint on overcoming this please?

@bgalek
Copy link
Member

bgalek commented May 29, 2024

hi!
maybe you did a sparse checkout/shallow clone?
check if you have full repository history since it's needed to get current version ;)

@manideepla
Copy link

No, it's a clean checkout via the the typical Azure Devops pipeline task. Strangely, it's working okay locally though.

@dominikbrandon
Copy link
Contributor

Maybe Azure isn't fetching the tags?

@manideepla
Copy link

manideepla commented Jun 5, 2024

It actually is, it's working in a different pipeline well.

Can you hint anything please? What details might help you to help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants