forked from ForceTower/Melon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversioning.gradle
29 lines (26 loc) · 1.32 KB
/
versioning.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
ext {
//noinspection SpellCheckingInspection
buildVersion = {
//Perform git commands
def git_sha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def commit_count = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim())
def last_tag = 'git rev-list --tags --no-walk --max-count=1'.execute([], project.rootDir).text.trim()
def new_commits = Integer.parseInt("git rev-list ${last_tag}..HEAD --count".execute([], project.rootDir).text.trim())
def postfix = "[release]"
def (major, minor, patch) = version.toLowerCase().replaceAll('-', '').tokenize('.')
if (patch.endsWith("dev")) {
patch = patch.replaceAll("[^0-9]","")
postfix = "[development]"
} else {
if (patch.endsWith("pr")) {
patch = patch.replaceAll("[^0-9]", "")
postfix = "[pre-release]"
}
}
(major, minor, patch, new_commits) = [major, minor, patch, new_commits].collect{it.toInteger()}
//For the version 12.7.4 will be generated the code: 21COUNT and the name: [12.7.4 build COUNT post]
def name = "${major}.${minor}.${patch} build ${commit_count} ${postfix}"
def code = (21 * 100000) + commit_count
return [code, name]
}
}