jmongard / Git.SemVersioning.Gradle

Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages.
https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin
Apache License 2.0
38 stars 4 forks source link

The `printVersion` should print `semver.version` #22

Closed sschuberth closed 10 months ago

sschuberth commented 10 months ago

IMO it's misleading in the context of the releaseVersion task, which uses semver.version, that the printVersion 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:

Task Variable Used
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).

mrt181 commented 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.

sschuberth commented 10 months ago

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.

jmongard commented 10 months ago

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      
sschuberth commented 10 months ago

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 😀

jmongard commented 10 months ago

The new tasks is implemented in version 0.5.2

jmongard commented 10 months ago

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}")
}