-
Notifications
You must be signed in to change notification settings - Fork 11
/
fabfile.py
176 lines (140 loc) · 4.89 KB
/
fabfile.py
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
from fabric.api import local
import re
import sys
import os
import shutil
scala_version_path = 'project/Version.scala'
gradle_version_path = 'aeromock-dsl/gradle.properties'
gradle_tmp_path = 'tmp_gradle_version'
scala_tmp_path = 'tmp_scala_version'
versions_path = 'versions.txt'
versions_tmp_path = 'tmp_versions.txt'
def snapshot_release():
# build aeromock-dsl
local('./aeromock-dsl/gradlew -p aeromock-dsl install uploadArchives')
# build aeromock
local('./sbt publishSigned')
def release(next_version):
# remove SNAPSHOT scala
to_release_version_scala()
# remove SNAPSHOT Gradle
to_release_version_gradle()
release_version = get_release_version()
# build aeromock-dsl
local('./aeromock-dsl/gradlew -p aeromock-dsl install uploadArchives')
# build aeromock
local('./sbt publishSigned')
# update versions.txt
update_versions_file(release_version)
# commit & tag release version
commit('pre tag commit \'%s\'.' % release_version)
tag_name = 'v%s' % release_version
local('git tag %s' % tag_name)
# to snapshot version
to_snapshot_version_scala(next_version)
to_snapshot_version_gradle(next_version)
# commit snapshot version
commit('- new version commit: \'%s-SNAPSHOT\'.' % next_version)
# push
local('git push origin master')
local('git push origin %s' % tag_name)
def to_release_version_scala():
p = re.compile('"\s*([0-9A-Z\-\.]*)-SNAPSHOT\s*"')
try:
version_file = open(scala_version_path, 'r')
write_file = open(scala_tmp_path, 'w')
for line in version_file:
result = p.search(line)
if result:
write_file.write(' val aeromock = "%s"\n' % result.group(1))
else:
write_file.write(line)
finally:
version_file.close()
write_file.close()
os.remove(scala_version_path)
shutil.move(scala_tmp_path, scala_version_path)
def to_release_version_gradle():
p = re.compile('\s*version\s*=\s*([0-9A-Z\-\.]*)-SNAPSHOT\s*')
try:
version_file = open(gradle_version_path, 'r')
write_file = open(gradle_tmp_path, 'w')
for line in version_file:
result = p.search(line)
if result:
write_file.write('version=%s\n' % result.group(1))
else:
write_file.write(line)
finally:
version_file.close()
write_file.close()
os.remove(gradle_version_path)
shutil.move(gradle_tmp_path, gradle_version_path)
def to_snapshot_version_scala(next_version):
p = re.compile('"\s*[0-9A-Z\-\.]*\s*"')
try:
version_file = open(scala_version_path, 'r')
write_file = open(scala_tmp_path, 'w')
for line in version_file:
result = p.search(line)
if result:
write_file.write(' val aeromock = "%s-SNAPSHOT"\n' % next_version)
else:
write_file.write(line)
finally:
version_file.close()
write_file.close()
os.remove(scala_version_path)
shutil.move(scala_tmp_path, scala_version_path)
def to_snapshot_version_gradle(next_version):
p = re.compile('\s*version\s*=\s*[0-9A-Z\-\.]+\s*')
try:
version_file = open(gradle_version_path, 'r')
write_file = open(gradle_tmp_path, 'w')
for line in version_file:
result = p.search(line)
if result:
write_file.write('version=%s-SNAPSHOT\n' % next_version)
else:
write_file.write(line)
finally:
version_file.close()
write_file.close()
os.remove(gradle_version_path)
shutil.move(gradle_tmp_path, gradle_version_path)
def get_release_version():
p = re.compile('\s*version\s*=\s*([0-9A-Z\-\.]*)\s*')
try:
version_file = open(gradle_version_path, 'r')
version = version_file.read()
result = p.search(version)
if result:
return result.group(1)
else:
raise SystemError('cannot get release version!')
finally:
version_file.close()
def update_versions_file(release_version):
try:
versions_file = open(versions_path, 'r')
write_file = open(versions_tmp_path, 'w')
write_file.write(release_version + '\n')
for line in versions_file:
write_file.write(line)
finally:
versions_file.close()
write_file.close()
os.remove(versions_path)
shutil.move(versions_tmp_path, versions_path)
def finish_release(release_version, next_version):
# add files
local('git add -A')
# commit release version
local('git commit -m "[Aeromock Release Task][ci skip] pre tag commit \'%s\'."' % release_version)
# create tag
local('git tag v%s' % release_version)
def commit(message):
# add files
local('git add -A')
# commit
local('git commit -m "[Aeromock Release Task][ci skip] %s"' % message)