-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.gradle
executable file
·118 lines (98 loc) · 3.31 KB
/
build.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* Important: You have to have at least on tag set with git - git tag v0.1
*
* Follow these steps:
*
* git commit -am "Whatever..."
* git push origin
* gradle sVIY wC && pub publish
*
* Git commands should be clear
*
* gradle sVIY - is a shortcut to "gradle setVersionInYaml"
* gradle wC - ist a shortcut to "gradel writeChangeLog"
*
* The && means if everything went OK with the gradle tasks execute pub publish
*/
ext.gitExtendedVersionX = {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
}
def version = stdout.toString().trim().replaceFirst("v","").replaceFirst('-(?!.*-).*','').replaceFirst("-",".");
if(version.indexOf(".") == version.lastIndexOf(".")) {
version = version + ".0"
}
return version;
}
def readTags() {
def tags = []
def proc = "git tag -l".execute()
proc.in.eachLine { line -> tags += line}
tags.sort {}
Collections.reverse( tags )
tags
}
def getChangeLog(final String range) {
def stdout = new ByteArrayOutputStream()
exec {
if(range == null || range == "") {
commandLine 'git', 'log', "--pretty=format:$changelogformat"
} else {
commandLine 'git', 'log',range , "--pretty=format:$changelogformat"
}
standardOutput = stdout
}
stdout.toString();
}
version = gitExtendedVersionX() // Sample: 0.5.4-19
ext {
ghaccount = "MikeMitterer"
ghproject = "git-init"
// pretty-format: http://opensource.apple.com/source/Git/Git-19/src/git-htmldocs/pretty-formats.txt
//changelogformat = "<li>%s (<a href=\"http://github.com/$ghaccount/$ghproject/commit/%H\">%h</a>)</li>"
changelogformat = "* %s [%h](http://github.com/$ghaccount/$ghproject/commit/%H)"
yamlFilename = "pubspec.yaml"
}
task showVersion() << {
print version
}
task setVersionInYaml << {
final File yamlfile = file(yamlFilename)
String contents = yamlfile.text;
contents = contents.replaceFirst(/version: .*/,"version: $version");
yamlfile.write(contents, 'UTF-8')
}
task writeChangeLog(dependsOn: setVersionInYaml) {
def linksForChangeLog = "";
def tags = readTags();
if(tags.size > 1) {
linksForChangeLog += "###$ghproject ChangeLog v$version###\n\n"
// linksForChangeLog += "$ghproject ChangeLog ###v$version###\n"
linksForChangeLog += getChangeLog("...${tags[0]}")
linksForChangeLog += "\n\n"
for (int i = 0; i < tags.size - 1; i++) {
def changes = getChangeLog("${tags[i]}...${tags[i+1]}")
if(changes == "") {
continue;
}
linksForChangeLog += "###${tags[i]}###\n"
linksForChangeLog += changes
linksForChangeLog += "\n\n"
}
linksForChangeLog += "###${tags[tags.size - 1]}###\n"
linksForChangeLog += getChangeLog("${tags[tags.size - 1]}")
} else if(tags.size == 1) {
linksForChangeLog += "###v$version###\n"
linksForChangeLog += getChangeLog("")
} else {
linksForChangeLog += getChangeLog("")
}
doLast {
final File configFile = file('CHANGELOG.md')
//final String contents = "###Changes:###\n$linksForChangeLog"
configFile.write(linksForChangeLog, 'UTF-8')
//print contents
}
}