4

We use Travis CI and deploy dev and QA builds continuously - and recently set up Firebase App Distribution. I'd like to be able to use the git commit message as "release notes" for dev and QA builds, and automate that in gradle where firebaseAppDistribution is. For example:

build.Gradle:

 generateGitCommitMessage() {
// get last commit message after > Task :app:assemble and before > Task :app:appDistributionUpload
return commitMessage
    }

firebaseAppDistribution {
            groups = "Android"
            // Automate capturing commit message in a string (or txt file) for dev builds
            releaseNotes="${generateGitCommitMessage()}"
        }

Is it possible to capture the current commit message entered when a commit is pushed, in Gradle? AppDistribution in Travis happens at the end, right before the apk is uploaded, after > Task :app:assemble, so I'm hoping it is.

I've researched some similar scripts such as https://kapie.com/2016/gradle-generate-release-notes/ and https://medium.com/@lowcarbrob/android-pro-tip-generating-your-apps-changelog-from-git-inside-build-gradle-19a07533eec4 but we don't tag builds, so these didn't really work for my situation, and I'm not very familiar with groovy.

Thanks in advance.

rdmcbath
  • 305
  • 1
  • 9

1 Answers1

7

I'm answering my own question since I figured it out. I created a task in build.gradle app level that I then call from the travis.yml file by creating an env variable.

In app level build.gradle: first make sure you have your firebase appDistribution code block added properly:

firebaseAppDistribution {
            groups = "Android"
            releaseNotesFile="./release-notes.txt"
        }

task getCommitMessage {
doLast ( {
    println "Generating release notes (release-notes.txt)"
    def releaseNotes = new File('release-notes.txt')
    releaseNotes.delete()
    releaseNotes << "[[ Commit message for this build: ]]\n"
    def cmdLine = "git log --format=%B -n 1"
    def procCommit = cmdLine.execute()
    procCommit.in.eachLine { line -> releaseNotes << line + "\n" }
    releaseNotes << "\n\n\n"
});

}

In travis.yml:

env:
    - RELEASE_NOTES="getCommitMessage"
...

script:
    - free -m
    - ./gradlew $RELEASE_NOTES
rdmcbath
  • 305
  • 1
  • 9