Created
August 30, 2016 18:23
-
-
Save richardradics/f046eb81619fae6e758abfe804bfe23c to your computer and use it in GitHub Desktop.
Supercharge CI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ext.releseNotesPath = "build/tmp/crashlytics_release_notes.txt" | |
def executeGitCommand(command) { | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine command | |
standardOutput = stdout | |
} | |
stdout.toString().trim() | |
} | |
def getCommitCount() { | |
executeGitCommand(['git', 'rev-list', 'HEAD', '--count']) | |
} | |
def getTagsSortedByDate() { | |
executeGitCommand(['git', 'for-each-ref', '--sort=taggerdate', '--format', "%(refname)", 'refs/tags']) | |
} | |
def getCommitMessagesSinceTag(tag) { | |
executeGitCommand(['git', 'log', tag + '..HEAD', '--no-merges', '--format=format:%s']) | |
} | |
def isCIMachine() { | |
return project.hasProperty('versionName'); | |
} | |
def setupReleaseNotesFromCommitMessages() { | |
gradle.taskGraph.addTaskExecutionListener(new TaskExecutionListener() { | |
@Override | |
void beforeExecute(Task task) { | |
if (task.name.startsWith("crashlyticsUploadDistribution")) { | |
String variantCapitalized = task.name.replaceFirst("^crashlyticsUploadDistribution", "") | |
String[] split = variantCapitalized.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])") | |
String flavor = split[0].toLowerCase() | |
String lastFlavorTag = null | |
getTagsSortedByDate().eachLine { tag -> | |
String tagName = tag.replaceFirst("^refs/tags/", "") | |
if (!tagName.contains("_")) { | |
return | |
} | |
String tagFlavor = tagName.split("_")[0].toLowerCase() | |
if (!tagFlavor.equals(flavor)) { | |
return | |
} | |
lastFlavorTag = tagName | |
} | |
file(ext.releseNotesPath).write getCommitMessagesSinceTag(lastFlavorTag) | |
} | |
} | |
@Override | |
void afterExecute(Task task, TaskState state) { | |
} | |
}) | |
} | |
if (isCIMachine()) { | |
android.buildTypes.each { buildType -> | |
buildType.ext.betaDistributionGroupAliases = "supercharge" | |
buildType.ext.betaDistributionReleaseNotesFilePath = file(ext.releseNotesPath).absoluteFile.path | |
} | |
setupReleaseNotesFromCommitMessages() | |
android.defaultConfig.versionName = versionName | |
android.defaultConfig.versionCode = Integer.valueOf(getCommitCount()) | |
} | |
ext { | |
isCIMachine = this.&isCIMachine | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment