-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.xml
178 lines (169 loc) · 7.69 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
175
176
177
178
<?xml version="1.0" encoding="UTF-8"?>
<project name="version" description="versioning and scm related utilities" default="info" phingVersion="2.4.4">
<!-- ============================================ -->
<!-- Custom Properties -->
<!-- ============================================ -->
<property name="repo.dir" value="${project.basedir}" />
<!-- ============================================ -->
<!-- Custom Taskdefs -->
<!-- ============================================ -->
<taskdef classpath="${phingistrano.dir}" classname="version.GitDescribeTask" name="gitdescribe" />
<taskdef classpath="${phingistrano.dir}" classname="version.GitDiffTask" name="gitdiff" />
<taskdef classpath="${phingistrano.dir}" classname="version.GitLogTask" name="gitlog" />
<taskdef classpath="${phingistrano.dir}" classname="version.GitRemoteShowTask" name="gitremoteshow" />
<taskdef classpath="${phingistrano.dir}" classname="version.GitTagTask" name="gittag" />
<taskdef classpath="${phingistrano.dir}" classname="version.MimeMailTask" name="mimemail" />
<!-- ============================================ -->
<!-- Target: pushtags -->
<!-- ============================================ -->
<target name="pushtags">
<gitpush repository="${repo.dir}"
quiet="false"
tags="true" />
</target>
<!-- ============================================ -->
<!-- Target: checkoutdevelop -->
<!-- ============================================ -->
<target name="checkoutdevelop">
<gitcheckout repository="${repo.dir}"
branchname="develop"
quiet="false" />
</target>
<!-- ============================================ -->
<!-- Target: checkoutmaster -->
<!-- ============================================ -->
<target name="checkoutmaster">
<gitcheckout repository="${repo.dir}"
branchname="master"
quiet="false" />
</target>
<!-- ============================================ -->
<!-- Target: pull -->
<!-- ============================================ -->
<target name="pull">
<gitpull repository="${repo.dir}"
force="true"
quiet="false"
all="true" />
</target>
<!-- ============================================ -->
<!-- Target: tag -->
<!-- ============================================ -->
<target name="tag">
<!-- Checkout master branch and ensure it's up to date -->
<gitcheckout repository="${repo.dir}" branchname="master" />
<gitpull repository="${repo.dir}"
source="origin"
refspec="master" />
<!-- Pull and merge in the remote develop branch -->
<gitpull repository="${repo.dir}"
source="origin"
refspec="develop" />
<!-- Generate a custom log of changes since the last dated tag -->
<gitdescribe repository="${repo.dir}"
tags="true"
abbrev="0"
match="*-*-*.*"
outputProperty="mostRecentTag" />
<php function="trim" returnProperty="mostRecentTag">
<param value="${mostRecentTag}"/>
</php>
<gitlog repository="${repo.dir}"
since="${mostRecentTag}"
until="HEAD"
noMerges="true"
date="relative"
format="format:* %an [%ar] %s"
outputProperty="changeLog" />
<!-- Only tag & push if there were any changes made since the last version bump -->
<if>
<equals arg1="${changeLog}" arg2="" />
<then>
<echo msg="No changes made since last version bump. Nothing to do!" />
</then>
<else>
<echo msg="executing bumpversion with: ${repo.dir}" />
<!-- Make new dated tag, using aforementioned log as tag message -->
<tstamp>
<format property="tagStamp" pattern="%Y-%m-%d.%H%M%S" />
</tstamp>
<echo msg="Tagging as ${tagStamp}" />
<gittag repository="${repo.dir}"
annotate="true"
name="${tagStamp}"
message="${changeLog}" />
<!-- Push commits and tags -->
<gitpush repository="${repo.dir}" quiet="false" />
<gitpush repository="${repo.dir}"
quiet="false"
tags="true" />
</else>
</if>
<!-- Checkout develop branch -->
<gitcheckout repository="${repo.dir}" branchname="develop" />
</target>
<!-- ============================================ -->
<!-- Target: notify -->
<!-- ============================================ -->
<target name="notify">
<!-- Get two most recent tags -->
<gitdescribe repository="${repo.dir}"
tags="true"
match="*-*-*.*"
abbrev="0"
outputProperty="endTag"
committish="master" />
<php function="trim" returnProperty="endTag">
<param value="${endTag}"/>
</php>
<gitdescribe repository="${repo.dir}"
tags="true"
match="*-*-*.*"
abbrev="0"
committish="${endTag}^"
outputProperty="beginTag" />
<php function="trim" returnProperty="beginTag">
<param value="${beginTag}"/>
</php>
<!-- Generate a custom log of changes between the two tags -->
<gitlog repository="${repo.dir}"
since="${beginTag}"
until="${endTag}"
date="relative"
format="format:* %an [%ar] %s"
outputProperty="changeLog" />
<gitdiff repository="${repo.dir}"
shortstat="true"
commits="${beginTag}..${endTag}"
outputProperty="shortDiffStat" />
<php function="rtrim" returnProperty="shortDiffStat">
<param value="${shortDiffStat}"/>
</php>
<gitdiff repository="${repo.dir}"
stat="true"
commits="${beginTag}..${endTag}"
outputProperty="fullDiffStat" />
<php function="rtrim" returnProperty="fullDiffStat">
<param value="${fullDiffStat}"/>
</php>
<!-- Get the github remote origin (UserName/RepoName) -->
<gitremoteshow repository="${repo.dir}"
name="origin"
outputProperty="remoteOrigin" />
<php function="preg_replace" returnProperty="remoteOrigin">
<param value="!.*URL: [^\n]+(?:@|://)github.com(?:/|:)(.*)\.git.*!ms" />
<param value="$1" />
<param value="${remoteOrigin}" />
</php>
<!-- Human readable timestamp -->
<tstamp>
<format property="timeStamp" pattern="%A %B%e %Y, %I:%M%p %z" />
</tstamp>
<!-- And assemble it all into a nicely formatted email -->
<mimemail html="true"
from="${version.from}"
to="${version.to}"
subject="[${endTag}] Release of '${phing.project.name}': ${shortDiffStat}"
template="${phingistrano.dir}/version/notify.html" />
</target>
</project>