Skip to content

Best Practices for when to generate a Git Tag using this plugin and CI/CD #4

@TylerMcCraw

Description

@TylerMcCraw

I'd be interested in hearing your thoughts on best practices for how/when you create a Git Tag when also using CI/CD for builds.
I've run into some curiosities when using the plugin with our CI environment.

For instance, the version code may start out as 1.2.3 on my development branch.
If my override function computes this versionCode as:
semVer.major * 10000 + semVer.minor * 100 + semVer.patch + gitTag.commitsSinceLatestTag
then this will produce a versionCode as:
10203

Now, let's say I've committed 7 times since the creation of the Git Tag and I want CI to run tests and deploy an internal/beta build.
This means that the newest versionCode will now be:
10203 + 7 == 10210

When I create a PR pointed from development branch to master and CI generates a production/Play Store build the gitTag.commitsSinceLatestTag is going to return 0.
This means that the versionCode is going to be lower than the latest development build:
10203 + 0 == 10203

This is problematic because we want our builds to always be incremental.
I would have expected the version code for the Play Store release to be 10210 or higher.

I feel like either I create the Git Tag on the wrong branch which causes commitsSinceLatestTag to return 0 or I'm not understanding the best practice for generating a version code.
Any help is much appreciated.

Currently, I am working around this by using a different function for generating the version code:
This simply computes number of commits by using a git command to count the number of revisions since the latest major version tag.

    overrideVersionCode { gitTag, _ ->
        def semVer = SemVer.fromGitTag(gitTag)
        def majorVersion = semVer.major.toString()
        def commitsSinceLastTag = ['sh', '-c', "git rev-list $majorVersion.0.0..HEAD --count"].execute().text.trim().toInteger()
        semVer.major * 10000 + commitsSinceLastTag
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions