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.

4

1 回答 1

6

自从我弄清楚以来,我正在回答我自己的问题。我在 build.gradle 应用程序级别创建了一个任务,然后通过创建一个 env 变量从 travis.yml 文件中调用它。

在应用程序级别 build.gradle:首先确保您正确添加了 Firebase appDistribution 代码块:

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

}

在 travis.yml 中:

env:
    - RELEASE_NOTES="getCommitMessage"
...

script:
    - free -m
    - ./gradlew $RELEASE_NOTES
于 2019-11-20T02:21:05.713 回答