Closed sschuberth closed 10 months ago
you can just pipe the output
./gradlew printVersion | grep 'Version: ' | awk -F' ' '{print $2}'
1.1.0-SNAPSHOT+001.sha.46a17d8
But it would be nice if that wouldn't be needed.
But it would be nice if that wouldn't be needed.
Exactly. I was also playing with ./gradlew -q :properties --property version
(after assigning version = semver.version
in my project), but that doesn't work either out of the box due to https://github.com/gradle/gradle/issues/19918.
Sure, if it helps removing the separator and creating three different print tasks sounds good. I'm not sure if you could get rid of the other stuff gradle prints when running a task.
I build my docker images when pushing a tag or branch in github actions and grabs the version from the tag or branch name like this:
- name: Set env
run: echo VERSION=${GITHUB_REF##*/} >> $GITHUB_ENV
- name: Pushes to docker registry
run: |
docker push $IMAGE_NAME:$VERSION
docker push $IMAGE_NAME:latest
I'm not sure if you could get rid of the other stuff gradle prints when running a task.
That's what the -q
in ./gradlew -q
does 😀
The new tasks is implemented in version 0.5.2
You could also call some executable from gradle giving you access to every variant of version output similar to this:
tasks.create<Exec>("build") {
executable = "dotnet"
args("build",
solutionFile,
"--configuration",
configuration,
"-p:Version=${semver.semVersion.major}.${semver.semVersion.minor}.${semver.semVersion.patch}.0",
"-p:AssemblyInformationalVersion=${semver.semVersion}")
}
IMO it's misleading in the context of the
releaseVersion
task, which usessemver.version
, that theprintVersion
task does not:https://github.com/jmongard/Git.SemVersioning.Gradle/blob/8ffe01be99382e07e239c5a7a183c11972d97297/src/main/kotlin/git/semver/plugin/gradle/GitSemverPlugin.kt#L17-L25
I propose to introduce new tasks with the following mapping:
printVersion
semver.version
printInfoVersion
semver.infoVersion
printSemVersion
semver.semVersion
Also, all of these tasks should really just print the version, without any "--------------------" separator or "Version: " prefix or similar. That way, e.g.
./gradlew -q printVersion
could be used to pipe the calculated version to somewhere else (like a Docker image build).