-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.xml
174 lines (142 loc) · 6.11 KB
/
build.xml
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?xml version="1.0" encoding="UTF-8"?>
<project name="LieLink" default="zip" basedir=".">
<property name="egrepexec" value="/usr/bin/egrep"/>
<target name="updateversionnumber" depends="changelog">
<echo>## UPDATING VERSION NUMBER ##</echo>
<!-- Echo the version number. -->
<echo>Version number: ${lielink.version}</echo>
<!-- Replace the version number and date in the init.m file. -->
<replaceregexp file="${basedir}/LieLink/VersionNumber.m" match="(.*)" replace="${lielink.version}" byline="true" />
</target>
<target name="zip" depends="changelog,updateversionnumber">
<echo>## CREATING ZIP FILE ##</echo>
<!-- Zip everything in a distributable file. -->
<zip
destfile="${basedir}/dist/LieLink.${git.newversion}.zip"
includes="LieLink/LiE/**/*,LieLink/Kernel/init.m,LieLink/LieLink.m,LieLink/VersionNumber.m,LieLink/Extensions.m"
basedir="." update="no"
>
<zipfileset dir="." includes="CHANGELOG,LICENSE,README.md" prefix="LieLink"/>
</zip>
</target>
<!-- Macro for getting the date of a Git tag. -->
<macrodef name="get-git-date">
<attribute name="tag" />
<attribute name="num" />
<sequential>
<exec dir="." executable="git" failonerror="true" outputproperty="git.date.@{num}">
<arg line="log @{tag} --simplify-by-decoration --pretty=format:%ad --date=short --reverse -1" />
</exec>
</sequential>
</macrodef>
<!-- Macro for getting the Git commit logs of one tag. -->
<macrodef name="get-git-log">
<attribute name="range" />
<attribute name="numlog" />
<sequential>
<exec dir="." executable="git" failonerror="true" outputproperty="git.fulllog.@{numlog}">
<arg line="log --pretty=format:%s @{range}" />
</exec>
<echo file="log.temp">${git.fulllog.@{numlog}}</echo>
<exec dir="." executable="${egrepexec}" outputproperty="git.log.@{numlog}">
<arg line="-v -i 'version number|merge|merging|build|README' log.temp" />
</exec>
</sequential>
</macrodef>
<target name="changelog">
<echo>## UPDATING CHANGELOG ##</echo>
<!-- Get the date. -->
<tstamp>
<format property="TODAY_LIELINK" pattern="yyyy-M-d" />
</tstamp>
<!-- Get a list of tags from Git. -->
<exec dir="." executable="git" failonerror="true" outputproperty="git.tags">
<arg line="for-each-ref --sort='*authordate' --format='%(refname:short)' refs/tags" />
</exec>
<echo>Git tags:</echo>
<echo>${git.tags}</echo>
<!-- Get the current tag from Git. If the current commit doesn't have a tag, it fails. -->
<exec dir="." executable="git" failonerror="false" outputproperty="git.currenttag">
<arg line="describe --exact-match HEAD" />
</exec>
<echo>Current tag: ${git.currenttag}</echo>
<!-- Get the last tag. -->
<exec dir="." executable="git" failonerror="false" outputproperty="git.lasttag">
<arg line="describe --abbrev=0" />
</exec>
<echo>Last tag: ${git.lasttag}</echo>
<!-- Get the number of commits since the last tag. -->
<exec dir="." executable="git" failonerror="false" outputproperty="git.commitssincetag">
<arg line="rev-list ${git.lasttag}..HEAD --count" />
</exec>
<echo>Commits since last tag: ${git.commitssincetag}</echo>
<!-- Parse the Git tags into a nicely formatted log with Javascript. -->
<script language="javascript">
<![CDATA[
/* Create tasks. */
var echo = project.createTask("echo");
var getgitdate = project.createTask("get-git-date");
var getgitlog = project.createTask("get-git-log");
/* Get the list of tags, and split them into an array. */
tags = project.getProperty("git.tags").replace("\r", "").split("\n");
/* Determine if the current commit sits on the last tag.
If so, use the name of the last tag as the version number.
If not, use the name of the last tag plus the number of commits away from it. */
var lastversion = tags[tags.length-1].replace("v","");
if(tags[tags.length-1] == String(project.getProperty("git.currenttag")))
{
getgitdate.setDynamicAttribute("tag",tags[tags.length - 1]);
getgitdate.setDynamicAttribute("num",tags.length - 1);
getgitdate.execute();
var newdate = (project.getProperty("git.date." + (tags.length - 1))).replace("-0","-").split("-").join(", ");
var newversion = lastversion;
}
else
{
var newversion = lastversion + "." + String(project.getProperty("git.commitssincetag"));
var newdate = project.getProperty("TODAY_LIELINK").split("-").join(", ");
tags = (tags.join("\n") + "\nHEAD").split("\n");
}
project.setProperty("git.newversion",newversion);
project.setProperty("quoted.version","\"" + newversion + "\"");
/* Also set a string that matches the formatting in the init.m file. */
project.setProperty(
"lielink.version",
"{\"" + newversion + "\", {" + newdate + "}}"
);
/* Create the formatted log by looping over the tags. */
var output = 'LieLink changelog\n=================\n\n';
var versionheader = '';
for (var i = tags.length - 1; i > -1; i--) {
versionheader = "v" + tags[i].replace("HEAD", newversion) + ", ";
/* Get the date of the tag. */
getgitdate.setDynamicAttribute("tag",tags[i]);
getgitdate.setDynamicAttribute("num",i);
getgitdate.execute();
versionheader += project.getProperty("git.date." + i);
output += versionheader + "\n";
output += new Array(versionheader.length + 1).join( "-" ) + "\n\n";
/* Get the log of this particular tag. */
var range = '';
if(i > 0)
{
range += tags[i-1] + "..";
}
range += tags[i];
getgitlog.setDynamicAttribute("range", range);
getgitlog.setDynamicAttribute("numlog",i);
getgitlog.execute();
output += " * " + project.getProperty("git.log." + i).replace("\n", "\n * ") + "\n\n";
echo.setMessage("Formatted changelog for " + tags[i]);
echo.perform();
}
/* Send the formatted log back to Ant. */
project.setProperty("git.log", output);
]]>
</script>
<!-- Delete the temporary log file. -->
<delete file="log.temp" />
<!-- Write the changelog to a file. -->
<echo file="${basedir}/CHANGELOG">${git.log}</echo>
</target>
</project>