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

Adding some APIs #93

Closed
bric3 opened this issue Jan 4, 2023 · 9 comments
Closed

Adding some APIs #93

bric3 opened this issue Jan 4, 2023 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@bric3
Copy link

bric3 commented Jan 4, 2023

In my build script depending, I wrote some tasks that depends on the computed version, and some on the old version.

Typically choosing the repository to upload artifacts weather the version is a snapshot or a release (alpha, beta, rc, final). In another project I'm working on there's the concept of EAP (early access preview).
Currently I have created my own functions that parse the version. But it would be useful if the plugin could provide those.

E.g.

fun isSnapshot(version: Any) = version.toString().endsWith("-SNAPSHOT") 
        || version.toString().matches(Regex(".*\\.\\d+\\+[0-9a-f]+")) // .54+6a08d70

Another thing that I'm currently doing differently is getting the last tag (and possibly the commit id), which could be used to trigger some tasks.

@JavierSegoviaCordoba JavierSegoviaCordoba self-assigned this Jan 4, 2023
@JavierSegoviaCordoba
Copy link
Owner

I am doing something similar to that but outside of semver plugin, in Hubdle or Gradle Extensions.

There is a Gradle issue to transform version: Any to version: Provider<Any>, but personally I think they should avoid Any and use a specific and deterministic type, even if it is String.

We can add a val Project.isSnapshot: Provider<Boolean> getter, indeed I think I should refactor the one I have to return a Provider.

public val Project.isSnapshot: Boolean
    get() = version.toString().endsWith("-SNAPSHOT", ignoreCase = true)

Change to

public val Project.isSnapshot: Provider<Boolean>
    get() = provider { version.toString().endsWith("-SNAPSHOT", ignoreCase = true) }

And in semver plugin I could just expose it:

public val Project.isSnapshot: Provider<Boolean>
    get() = com.javiersc.gradle.extensions.project.isSnapshot

The reason to expose a Provider is to clearly indicate it should be consumed in tasks or lazy configurations and avoid getting its value in the configuration phase. Indeed, version.toString() is calling get() internally.

Additionally, we could add more for common values like isAlpha, isBeta, isRC, isFinal and so on.

@JavierSegoviaCordoba JavierSegoviaCordoba added the enhancement New feature or request label Jan 4, 2023
@JavierSegoviaCordoba
Copy link
Owner

Fixed with 0b8156d

@JavierSegoviaCordoba
Copy link
Owner

JavierSegoviaCordoba commented Jan 4, 2023

Added those ones in isVersionExtension.kt:

  • Project.isAlpha: Provider<Boolean> extension
  • Project.isNotAlpha: Provider<Boolean> extension
  • Project.isBeta: Provider<Boolean> extension
  • Project.isNotBeta: Provider<Boolean> extension
  • Project.isDev: Provider<Boolean> extension
  • Project.isNotDev: Provider<Boolean> extension
  • Project.isRC: Provider<Boolean> extension
  • Project.isNotRC: Provider<Boolean> extension
  • Project.isSnapshot: Provider<Boolean> extension
  • Project.isNotSnapshot: Provider<Boolean> extension

@bric3
Copy link
Author

bric3 commented Jan 5, 2023

Ah cool !
I think the not variants like isNotSnapshot are not needed, as prefixing with ! or using the .not postfix in kotlin should be enough.

Also what about the API about reading the previous git tag, since it's used to compute the current version.

Maybe also reading the commit hash of the related tag. And the current commit hash as a commodity (can be used to set an entry in the manifest).

@JavierSegoviaCordoba
Copy link
Owner

Also what about the API about reading the previous git tag, since it's used to compute the current version.

Maybe also reading the commit hash of the related tag. And the current commit hash as a commodity (can be used to set an entry in the manifest).

How would you consume those values? in a lambda in the plugin extension for example?

@bric3
Copy link
Author

bric3 commented Mar 7, 2023

I'm not sure how I would consume those, I think possibly accessing those values in a custom task, or from another task.

@JavierSegoviaCordoba
Copy link
Owner

Maybe the semver extension can have a provider with those values which can be mapped to another task input/s.

What do you think?

@JavierSegoviaCordoba
Copy link
Owner

Fixed on f63fd5e

@bric3
Copy link
Author

bric3 commented Mar 9, 2023

Maybe the semver extension can have a provider with those values which can be mapped to another task input/s.

I think that should be the right thing.

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