/
autobuild.py
executable file
·471 lines (367 loc) · 16.1 KB
/
autobuild.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#!/usr/bin/python
# coding=utf-8
#
# Script for performing automated build events.
# http://dengine.net/dew/index.php?title=Automated_build_system
#
# The Build Pilot (pilot.py) is responsible for task distribution
# and management.
import sys
import os
import subprocess
import shutil
import time
import string
import glob
import builder
import pickle
import zipfile
from builder.git import *
from builder.utils import *
def pull_from_branch():
"""Pulls commits from the repository."""
git_pull()
def create_build_event():
"""Creates and tags a new build for with today's number."""
print 'Creating a new build event.'
git_pull()
# Identifier/tag for today's build.
todaysBuild = todays_build_tag()
# Tag the source with the build identifier.
git_tag(todaysBuild)
# Prepare the build directory.
ev = builder.Event(todaysBuild)
ev.clean()
#if prevBuild:
update_changes()
def todays_platform_release():
"""Build today's release for the current platform."""
print "Building today's build."
ev = builder.Event()
git_pull()
git_checkout(ev.tag() + builder.config.TAG_MODIFIER)
# We'll copy the new files to the build dir.
os.chdir(builder.config.DISTRIB_DIR)
existingFiles = os.listdir('releases')
print 'platform_release.py...'
os.system("python platform_release.py > %s 2> %s" % ('buildlog.txt', 'builderrors.txt'))
currentFiles = os.listdir('releases')
for n in existingFiles:
currentFiles.remove(n)
for n in currentFiles:
# Copy any new files.
remote_copy(os.path.join('releases', n), ev.file_path(n))
if builder.config.APT_REPO_DIR:
# Copy also to the appropriate apt directory.
arch = 'i386'
if '_amd64' in n: arch = 'amd64'
remote_copy(os.path.join('releases', n),
os.path.join(builder.config.APT_REPO_DIR,
builder.config.APT_DIST + '/main/binary-%s' % arch, n))
# Also the build logs.
remote_copy('buildlog.txt', ev.file_path('doomsday-out-%s.txt' % sys_id()))
remote_copy('builderrors.txt', ev.file_path('doomsday-err-%s.txt' % sys_id()))
if 'linux' in sys_id():
remote_copy('dsfmod/fmod-out-%s.txt' % sys_id(), ev.file_path('fmod-out-%s.txt' % sys_id()))
remote_copy('dsfmod/fmod-err-%s.txt' % sys_id(), ev.file_path('fmod-err-%s.txt' % sys_id()))
git_checkout(builder.config.BRANCH)
def sign_packages():
"""Sign all packages in today's build."""
ev = builder.Event()
print "Signing today's build %i." % ev.number()
for fn in os.listdir(ev.path()):
if fn.endswith('.exe') or fn.endswith('.dmg') or fn.endswith('.deb'):
# Make a signature for this.
os.system("gpg --output %s -ba %s" % (ev.file_path(fn) + '.sig', ev.file_path(fn)))
def find_previous_tag(toTag, version):
builds = builder.events_by_time()
#print [(e[1].number(), e[1].timestamp()) for e in builds]
i = 0
while i < len(builds):
ev = builds[i][1]
print ev.tag(), ev.version(), ev.timestamp()
if ev.tag() != toTag and (ev.version() is None or version is None or
ev.version().startswith(version)):
# This is good.
return ev.tag()
i += 1
# Nothing suitable found. Fall back to a more lax search.
return find_previous_tag(toTag, None)
def update_changes(debChanges=False):
"""Generates the list of commits for the latest build."""
git_pull()
toTag = todays_build_tag()
import build_version
build_version.find_version(quiet=True)
# Let's find the previous event of this version.
fromTag = find_previous_tag(toTag, build_version.DOOMSDAY_VERSION_FULL_PLAIN)
if fromTag is None or toTag is None:
# Range not defined.
return
print 'Changes for range', fromTag, '..', toTag
changes = builder.Changes(fromTag, toTag)
if debChanges:
# Only update the Debian changelog.
changes.generate('deb')
# Also update the doomsday-fmod changelog (just version number).
os.chdir(os.path.join(builder.config.DISTRIB_DIR, 'dsfmod'))
fmodVer = build_version.parse_header_for_version('../../doomsday/plugins/fmod/include/version.h')
debVer = "%s.%s.%s-%s" % (fmodVer[0], fmodVer[1], fmodVer[2], todays_build_tag())
print "Marking new FMOD version:", debVer
msg = 'New release: Doomsday Engine build %i.' % builder.Event().number()
os.system('dch --check-dirname-level 0 -v %s -b "%s"' % (debVer, msg))
else:
# Save version information.
print >> file(builder.Event(toTag).file_path('version.txt'), 'wt'), \
build_version.DOOMSDAY_VERSION_FULL
print >> file(builder.Event(toTag).file_path('releaseType.txt'), 'wt'), \
build_version.DOOMSDAY_RELEASE_TYPE
changes.generate('html')
changes.generate('xml')
def update_debian_changelog():
"""Updates the Debian changelog at (distrib)/debian/changelog."""
# Update debian changelog.
update_changes(debChanges=True)
def rebuild_apt_repository():
"""Rebuilds the Apt repository by running apt-ftparchive."""
aptDir = builder.config.APT_REPO_DIR
print 'Rebuilding the apt repository in %s...' % aptDir
os.system("apt-ftparchive generate ~/Dropbox/APT/ftparchive.conf")
os.system("apt-ftparchive -c %s release %s/%s > %s/%s/Release" % (builder.config.APT_CONF_FILE, aptDir, builder.config.APT_DIST, aptDir, builder.config.APT_DIST))
os.chdir("%s/%s" % (aptDir, builder.config.APT_DIST))
try:
os.remove("Release.gpg")
except OSError:
# Never mind.
pass
os.system("gpg --output Release.gpg -ba Release")
os.system("~/Dropbox/Scripts/mirror-tree.py %s %s" % (aptDir, os.path.join(builder.config.EVENT_DIR, 'apt')))
def write_index_html(tag):
ev = builder.Event(tag)
f = file(ev.file_path('index.html'), 'wt')
print >> f, "<html>"
print >> f, "<head><title>Build %i</title></head>" % ev.number()
print >> f, "<body>"
print >> f, "<h1>Build %i</h1>" % ev.number()
print >> f, ev.html_description(False)
print >> f, "</body>"
print >> f, "</html>"
def update_feed():
"""Generate events.rss into the event directory."""
feedName = os.path.join(builder.config.EVENT_DIR, "events.rss")
print "Updating feed in %s..." % feedName
out = file(feedName, 'wt')
print >> out, '<?xml version="1.0" encoding="UTF-8"?>'
print >> out, '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'
print >> out, '<channel>'
print >> out, '<title>Doomsday Engine Builds</title>'
print >> out, '<link>http://dengine.net/</link>'
print >> out, '<atom:link href="%s/events.rss" rel="self" type="application/rss+xml" />' % builder.config.BUILD_URI
print >> out, '<description>Automated binary builds of the Doomsday Engine.</description>'
print >> out, '<language>en-us</language>'
print >> out, '<webMaster>skyjake@users.sourceforge.net (Jaakko Keränen)</webMaster>'
print >> out, '<lastBuildDate>%s</lastBuildDate>' % time.strftime(builder.config.RFC_TIME,
time.gmtime(builder.find_newest_event()['time']))
print >> out, '<generator>autobuild.py</generator>'
print >> out, '<ttl>180</ttl>' # 3 hours
for timestamp, ev in builder.events_by_time():
print >> out, '<item>'
print >> out, '<title>Build %i</title>' % ev.number()
print >> out, '<link>%s/%s/</link>' % ("http://dengine.net", ev.tag())
print >> out, '<author>skyjake@users.sourceforge.net (skyjake)</author>'
print >> out, '<pubDate>%s</pubDate>' % time.strftime(builder.config.RFC_TIME, time.gmtime(timestamp))
print >> out, '<atom:summary>%s</atom:summary>' % ev.text_summary()
print >> out, '<description>%s</description>' % ev.html_description()
print >> out, '<guid isPermaLink="false">%s</guid>' % ev.tag()
print >> out, '</item>'
write_index_html(ev.tag())
# Close.
print >> out, '</channel>'
print >> out, '</rss>'
def update_xml_feed():
"""Generate events.xml into the event directory."""
feedName = os.path.join(builder.config.EVENT_DIR, "events.xml")
print "Updating XML feed in %s..." % feedName
out = file(feedName, 'wt')
print >> out, '<?xml version="1.0" encoding="UTF-8"?>'
print >> out, '<log>'
for timestamp, ev in builder.events_by_time():
print >> out, ev.xml_description()
print >> out, '</log>'
def purge_apt_repository(atLeastSeconds):
for d in ['i386', 'amd64']:
binDir = os.path.join(builder.config.APT_REPO_DIR, builder.config.APT_DIST + '/main/binary-') + d
print 'Pruning binary apt directory', binDir
# Find the old files.
for fn in os.listdir(binDir):
if fn[-4:] != '.deb': continue
debPath = os.path.join(binDir, fn)
ct = os.stat(debPath).st_ctime
if time.time() - ct >= atLeastSeconds:
print 'Deleting', debPath
os.remove(debPath)
def purge_obsolete():
"""Purge old builds from the event directory (old > 12 weeks)."""
threshold = 3600 * 24 * 7 * 12
# Also purge the apt repository if one has been specified.
if builder.config.APT_REPO_DIR:
purge_apt_repository(threshold)
# Purge the old events.
print 'Deleting build events older than 12 weeks...'
for ev in builder.find_old_events(threshold):
print ev.tag()
shutil.rmtree(ev.path())
print 'Purge done.'
def dir_cleanup():
"""Purges empty build directories from the event directory."""
print 'Event directory cleanup starting...'
for emptyEventPath in builder.find_empty_events():
print 'Deleting', emptyEventPath
os.rmdir(emptyEventPath)
print 'Cleanup done.'
def system_command(cmd):
result = subprocess.call(cmd, shell=True)
if result != 0:
raise Exception("Error from " + cmd)
def generate_apidoc():
"""Run Doxygen to generate all API documentation."""
git_pull()
os.chdir(os.path.join(builder.config.DISTRIB_DIR, '../doomsday/libdeng2'))
print >> sys.stderr, "\nPublic API 2.0 docs..."
system_command('doxygen api2.doxy >/dev/null 2>../doxyissues-api2.txt')
system_command('wc -l ../doxyissues-api2.txt')
print >> sys.stderr, "\nPublic API docs..."
os.chdir(os.path.join(builder.config.DISTRIB_DIR, '../doomsday/client'))
system_command('doxygen api.doxy >/dev/null 2>../doxyissues-api.txt')
system_command('wc -l ../doxyissues-api.txt')
print >> sys.stderr, "\nlibshell docs..."
os.chdir(os.path.join(builder.config.DISTRIB_DIR, '../doomsday/libshell'))
system_command('doxygen shell.doxy >/dev/null 2>../doxyissues-shell.txt')
system_command('wc -l ../doxyissues-shell.txt')
print >> sys.stderr, "\nInternal Win32 docs..."
os.chdir(os.path.join(builder.config.DISTRIB_DIR, '../doomsday/client'))
system_command('doxygen client-win32.doxy >/dev/null 2>../doxyissues-win32.txt')
system_command('wc -l ../doxyissues-win32.txt')
print >> sys.stderr, "\nInternal Mac/Unix docs..."
system_command('doxygen client-mac.doxy >/dev/null 2>../doxyissues-mac.txt')
system_command('wc -l ../doxyissues-mac.txt')
print >> sys.stderr, "\nDoom plugin docs..."
os.chdir(os.path.join(builder.config.DISTRIB_DIR, '../doomsday/plugins/doom'))
system_command('doxygen doom.doxy >/dev/null 2>../../doxyissues-doom.txt')
system_command('wc -l ../../doxyissues-doom.txt')
print >> sys.stderr, "\nHeretic plugin docs..."
os.chdir(os.path.join(builder.config.DISTRIB_DIR, '../doomsday/plugins/heretic'))
system_command('doxygen heretic.doxy >/dev/null 2>../../doxyissues-heretic.txt')
system_command('wc -l ../../doxyissues-heretic.txt')
print >> sys.stderr, "\nHexen plugin docs..."
os.chdir(os.path.join(builder.config.DISTRIB_DIR, '../doomsday/plugins/hexen'))
system_command('doxygen hexen.doxy >/dev/null 2>../../doxyissues-hexen.txt')
system_command('wc -l ../../doxyissues-hexen.txt')
def generate_readme():
"""Run Amethyst to generate readme documentation."""
git_pull()
os.chdir(os.path.join(builder.config.DISTRIB_DIR, '../doomsday/doc/output'))
system_command('make clean all')
def generate_wiki():
"""Automatically generate wiki pages."""
git_pull()
sys.path += ['/Users/jaakko/Dropbox/Scripts']
import dew
dew.login()
# Today's event data.
ev = builder.Event()
if ev.release_type() == 'stable':
dew.submitPage('Latest Doomsday release',
'#REDIRECT [[Doomsday version %s]]' % ev.version())
dew.logout()
def web_path():
return os.path.join(builder.config.DISTRIB_DIR, '..', 'web')
def web_manifest_filename():
return os.path.join(builder.config.DISTRIB_DIR, '..', '.web.manifest')
def web_save(state):
pickle.dump(state, file(web_manifest_filename(), 'wb'), pickle.HIGHEST_PROTOCOL)
def web_init():
print 'Initializing web update manifest.'
web_save(DirState(web_path()))
def web_update():
print 'Checking for web file changes...'
git_pull()
oldState = pickle.load(file(web_manifest_filename(), 'rb'))
state = DirState(web_path())
updated = state.list_new_files(oldState)
removed = state.list_removed(oldState)
# Save the updated state.
web_save(state)
# Is there anything to do?
if not updated and not removed[0] and not removed[1]:
print 'Everything up-to-date.'
return
# Compile the update package.
print 'Updated:', updated
print 'Removed:', removed
arcFn = os.path.join(builder.config.DISTRIB_DIR, '..',
'web_update_%s.zip' % time.strftime('%Y%m%d-%H%M%S'))
arc = zipfile.ZipFile(arcFn, 'w')
for up in updated:
arc.write(os.path.join(web_path(), up), 'updated/' + up)
if removed[0] or removed[1]:
tmpFn = '_removed.tmp'
tmp = file(tmpFn, 'wt')
for n in removed[0]:
print >> tmp, 'rm', n
for d in removed[1]:
print >> tmp, 'rmdir', d
tmp.close()
arc.write(tmpFn, 'removed.txt')
os.remove(tmpFn)
arc.close()
# Deliver the update to the website.
print 'Delivering', arcFn
system_command('scp %s dengine@dengine.net:www/incoming/' % arcFn)
# No need to keep a local copy.
os.remove(arcFn)
def show_help():
"""Prints a description of each command."""
for cmd in sorted_commands():
if commands[cmd].__doc__:
print "%-17s " % (cmd + ":") + commands[cmd].__doc__
else:
print cmd
def sorted_commands():
sc = commands.keys()
sc.sort()
return sc
commands = {
'pull': pull_from_branch,
'create': create_build_event,
'platform_release': todays_platform_release,
'sign': sign_packages,
'changes': update_changes,
'debchanges': update_debian_changelog,
'apt': rebuild_apt_repository,
'feed': update_feed,
'xmlfeed': update_xml_feed,
'purge': purge_obsolete,
'cleanup': dir_cleanup,
'apidoc': generate_apidoc,
'readme': generate_readme,
'wiki': generate_wiki,
'web_init': web_init,
'web_update': web_update,
'help': show_help
}
if __name__ == '__main__':
if len(sys.argv) < 2:
print 'The arguments must be: (command) [args]'
print 'Commands:', string.join(sorted_commands())
print 'Arguments:'
print '--branch Branch to use (default: master)'
print '--distrib Doomsday distrib directory'
print '--events Event directory (builds are stored here in subdirs)'
print '--apt Apt repository'
print '--tagmod Additional suffix for build tag for platform_release'
sys.exit(1)
if sys.argv[1] not in commands:
print 'Unknown command:', sys.argv[1]
sys.exit(1)
commands[sys.argv[1]]()