forked from ModeShape/modeshape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.py
executable file
·441 lines (364 loc) · 16.7 KB
/
release.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
#!/usr/bin/python
import re
import sys
import os
import subprocess
import shutil
from markdown2 import *
from datetime import *
from multiprocessing import Process
from utils import *
from jira import *
from docbook import *
try:
from xml.etree.ElementTree import ElementTree
except:
prettyprint('''
Welcome to the ModeShape Release Script.
This release script requires that you use at least Python 2.5.0. It appears
that you do not thave the ElementTree XML APIs available, which are available
by default in Python 2.5.0.
''', Levels.FATAL)
sys.exit(1)
modules = []
docbooks = []
uploader = None
git = None
jira = None
def get_modules(directory):
'''Analyses the pom.xml file and extracts declared modules'''
tree = ElementTree()
f = directory + "/pom.xml"
if settings['verbose']:
print "Parsing %s to get a list of modules in project" % f
tree.parse(f)
mods = tree.findall(".//{%s}module" % maven_pom_xml_namespace)
for m in mods:
modules.append(m.text)
def help_and_exit():
prettyprint('''
%s ModeShape Release Script%s
This script automates much of the work of releasing a new version of the ModeShape project, and includes
the following tasks:
- create a local branch for the new release;
- change the project-related versions in the POM files and documentation;
- commit those changes locally;
- create a tag for the release;
- generate the release notes in multiple formats;
- generate emails to all the people who have filed, commented on, or worked on issues
fixed in this release;
- run a full assembly build of the software to product all artifacts and documentation;
- place a copy of all artifacts and documentation in the '../archive' folder;
- deploy all artifacts to the JBoss.org Maven repository in a staging area (authorization required)
- upload all artifacts and documentation to JBoss.org (authorization required); and
- push the commit and tag to the official Git repository (authorization required)
Note that the last three steps are not performed during a dry run.
Before this script is executed, be sure to update and commit the 'release_notes.md' file. It also ensures
that the local Git repository is a writable clone of the official ModeShape repository on GitHub.
%s Usage:%s
$ bin/release.py [options] <version> [<branch>]
where:
<version> The name of the new version (e.g., '2.4.0.Final' but without quotes), which must
comply with the format '<major>.<minor>.<patch>.<qualifier>', where the qualifier
must be one of 'Final', 'Alpha', 'Beta', or 'CR'.
branch The name of the existing branch from which the release should be made. This defaults
to 'master'.
and where the options include:
--verbose Show more detailed logging and messages
--dry-run Used for trial runs of the release process. This leaves a temporary branch in the local
git repository that contains the committed changes, but does NOT push to the official
Git repository and it does NOT publish artifacts to JBoss.org.
--skip-tests Do not run the unit or integration tests when building the software
--single-threaded Perform all operations sequentially without using multiple threads
--multi-threaded Perform some operations in parallel to reduce the overall run time.
This option is not available with '--dry-run'
--help|? Display this usage message
%s Examples:%s
$ bin/release.py 3.0.0.Final
This will release '3.0.0.Final' based off of 'master'
$ bin/release.py 2.8.1.Final 2.x
This will release '2.8.1.Final' based off of the existing '2.x' branch
''' % (Colors.yellow(), Colors.end_color(), Colors.yellow(), Colors.end_color(), Colors.yellow(), Colors.end_color()), Levels.INFO)
sys.exit(0)
def validate_version(version):
version_pattern = get_version_pattern()
if version_pattern.match(version):
return version.strip()
else:
prettyprint("Invalid version '"+version+"'!\n", Levels.FATAL)
help_and_exit()
def tag_release(version, branch):
if git.remote_branch_exists():
git.switch_to_branch()
git.create_tag_branch()
else:
prettyprint("Branch %s cannot be found on upstream repository. Aborting!" % branch, Levels.FATAL)
sys.exit(100)
def get_project_version_tag(tree):
return tree.find("./{%s}version" % (maven_pom_xml_namespace))
def get_parent_version_tag(tree):
return tree.find("./{%s}parent/{%s}version" % (maven_pom_xml_namespace, maven_pom_xml_namespace))
def patch_poms(working_dir, version):
patched_poms = list()
walker = GlobDirectoryWalker(working_dir, "pom.xml")
for pom_file in walker:
tree = ElementTree()
tree.parse(pom_file)
# The current version of the POM is what we're looking for ...
current_version_elem = get_project_version_tag(tree)
if current_version_elem == None:
# There is no version for the POM, so get it from the parent ...
current_version_elem = get_parent_version_tag(tree)
current_version = current_version_elem.text
if walker.replace_all_in(pom_file,"<version>%s</version>" % current_version,"<version>%s</version>" % version):
patched_poms.append(pom_file)
return patched_poms
def generate_release_notes(markdown_file,version,output_dir):
f = open(markdown_file)
readme_md = f.read()
# Replace the version entity with the actual version ...
readme_md = re.sub('&version;',version,readme_md)
# Append the JIRA-generated release notes
issues_md = jira.get_release_notes_in_markdown()
readme_md = readme_md + "\n\n" + issues_md
# Convert the lines to HTML using Markdown ...
readme_html = Markdown().convert(readme_md);
# Convert the lines to text by removing the Markdown patterns ...
readme_text = unmarkdown(readme_md)
# Write out the two files in the desired location ...
os.makedirs(output_dir)
path = os.path.join(output_dir,"release.html")
mdf = open(path,'w')
mdf.write(readme_html)
mdf.close()
path = os.path.join(output_dir,"release.txt")
mdt = open(path,'w')
mdt.write(readme_text)
mdt.close()
def generate_contribution_emails(output_dir,bcc_address):
'''Generates an HTML page in the output directory containing mailto links that can be used to create the contribution emails in your mail application'''
html_content = jira.get_contribution_html(bcc_address)
file_path = os.path.join(output_dir,"contributions.html")
f = open(file_path,'w')
f.write(html_content)
f.close()
def copy_artifacts_to_archive_location(archive_path,version):
try:
os.makedirs(archive_path)
except:
pass
# Copy the 'modeshape-distribution' artifacts ...
from_files = ['dist.zip', 'source.zip', 'jbosseap-61-dist.zip']
to_files = ['dist.zip', 'source.zip', 'jbosseap-61-dist.zip']
for fsuffix,tsuffix in zip(from_files,to_files):
shutil.copy("modeshape-distribution/target/modeshape-%s-%s" % (version,fsuffix), "%s/modeshape-%s-%s" % (archive_path,version,tsuffix))
# Make an area for the documentation ...
docs_path = os.path.join(archive_path,version)
if not os.path.exists(docs_path):
os.makedirs(docs_path)
# Copy the Full JavaDoc ...
from_path = os.path.join('modeshape-distribution','target','api')
copy_folder(from_path,os.path.join(docs_path,'api'))
## Copy the API JavaDoc ...
#from_path = os.path.join('modeshape-distribution','target','api')
#copy_folder(from_path,os.path.join(docs_path,'api'))
#
## Copy the XRef ...
#from_path = os.path.join('modeshape-distribution','target','xref')
#if os.path.exists(from_path):
# copy_folder(from_path,os.path.join(docs_path,'xref'))
# Copy the release notes into the archive area...
for readme in ['release.html','release.txt']:
from_path = os.path.join('target',readme)
shutil.copy(from_path,os.path.join(docs_path,readme))
shutil.copy(from_path,os.path.join(archive_path,readme))
def copy_release_notes_to_archive_location(archive_path,version):
try:
os.makedirs(archive_path)
except:
pass
# Copy the release notes into the archive area...
for readme in ['release.html','release.txt']:
from_path = os.path.join('target',readme)
shutil.copy(from_path,os.path.join(archive_path,readme))
def copy_folder( from_path, to_path ):
if os.path.exists(to_path):
shutil.rmtree(to_path)
shutil.copytree(from_path,to_path)
def update_versions(version):
modified_files = []
## Update versions in the POM files ...
for pom in patch_poms('.',version):
modified_files.append(pom)
# Now make sure this goes back into the repository.
git.commit(modified_files)
def get_module_name(pom_file):
tree = ElementTree()
tree.parse(pom_file)
return tree.findtext("./{%s}artifactId" % maven_pom_xml_namespace)
def upload_artifacts(base_dir, version):
"""Downloadable artifacts get rsync'ed to filemgmt.jboss.org, in the downloads_htdocs/modeshape directory"""
# Create an area under 'target' where we can move all the files/folders that we need to upload ...
os.chdir("%s/target/" % (base_dir))
os.makedirs("downloads/%s" % version)
# Copy the 'modeshape-distribution' artifacts ...
from_files = ['dist.zip', 'source.zip', 'jbosseap-61-dist.zip']
to_files = ['dist.zip', 'source.zip', 'jbosseap-61-dist.zip']
for fsuffix,tsuffix in zip(from_files,to_files):
shutil.copy("%s/modeshape-distribution/target/modeshape-%s-%s" % (base_dir,version,fsuffix), "downloads/%s/modeshape-%s-%s" % (version,version,tsuffix))
# Copy the readme files ...
for readme in ['release.html','release.txt']:
from_path = os.path.join(base_dir,'target',readme)
to_path = os.path.join('downloads',version,readme)
shutil.copy(from_path,to_path)
# rsync this stuff to filemgmt.jboss.org
os.chdir("%s/target/downloads" % (base_dir))
uploader.upload_rsync(version, "[email protected]:/downloads_htdocs/modeshape", flags = ['--protocol=28'])
# We're done, so go back to where we were ...
os.chdir(base_dir)
def upload_documentation(base_dir, version):
"""Javadocs get rsync'ed to filemgmt.jboss.org, in the docs_htdocs/modeshape directory"""
# Create an area under 'target' where we can move all the files/folders that we need to upload ...
os.chdir("%s/target/" % (base_dir))
os.makedirs("docs/%s" % version)
# Move the 'api' folder into the 'docs/<version>/' folder so we can rsync that '<version>' folder
os.rename("%s/modeshape-distribution/target/api" % base_dir, "docs/%s/api" % version)
# Copy the readme files ...
for readme in ['release.html','release.txt']:
from_path = os.path.join(base_dir,'target',readme)
to_path = os.path.join('docs',version,readme)
shutil.copy(from_path,to_path)
# rsync this stuff to filemgmt.jboss.org
os.chdir("%s/target/docs" % (base_dir))
uploader.upload_rsync(version, "[email protected]:/docs_htdocs/modeshape", flags = ['--protocol=28'])
# We're done, so go back to where we were ...
os.chdir(base_dir)
def do_task(target, args, async_processes):
if settings['multi_threaded']:
async_processes.append(Process(target = target, args = args))
else:
target(*args)
### This is the starting place for this script.
def release():
global settings
global uploader
global git
global jira
assert_python_minimum_version(2, 5)
base_dir = os.getcwd()
# Process the arguments ...
version = None
branch = 'master'
if len(sys.argv) > 1:
for arg in sys.argv[1:len(sys.argv)]:
if arg == '--verbose':
settings['verbose'] = True
elif arg == '--dry-run':
settings['dry_run'] = True
elif arg == '--multi-threaded':
settings['multi_threaded'] = True
elif arg == '--single-threaded':
settings['multi_threaded'] = False
elif arg == '--help' or arg == '?':
help_and_exit()
else:
if version == None:
# The first non-option is the version
print "validating version '%s'" % arg
version = validate_version(arg)
else:
branch = arg
## Set up network interactive tools
if settings['dry_run']:
# Use stubs
prettyprint("***", Levels.DEBUG)
prettyprint("*** This is a DRY RUN. No changes will be committed and no files will be published. Used to test this release script only. ***", Levels.DEBUG)
prettyprint("***", Levels.DEBUG)
prettyprint("Your settings are %s" % settings, Levels.DEBUG)
uploader = DryRunUploader()
else:
uploader = Uploader()
# Make sure they want to continue ...
sure = input_with_default("\nDid you update and commit the 'release_notes.md' file?", "N")
if not sure.upper().startswith("Y"):
prettyprint("... Please do this now and rerun this script.", Levels.WARNING)
print ""
sys.exit(1)
prettyprint("", Levels.INFO)
prettyprint("Releasing ModeShape version %s from branch '%s'" % (version, branch), Levels.INFO)
sure = input_with_default("Are you sure you want to continue?", "N")
if not sure.upper().startswith("Y"):
prettyprint("... User Abort!", Levels.WARNING)
sys.exit(1)
prettyprint("OK, releasing! Please stand by ...", Levels.INFO)
tag_name = "modeshape-%s" % version
git = Git(branch, tag_name)
if not git.is_upstream_clone():
proceed = input_with_default('This is not a clone of an %supstream%s ModeShape repository! Are you sure you want to proceed?' % (Colors.UNDERLINE, Colors.END), 'N')
if not proceed.upper().startswith('Y'):
prettyprint("... User Abort!", Levels.WARNING)
sys.exit(1)
# Haven't yet done anything ...
## Release order:
# Step 1: Tag in Git
prettyprint("Step 1: Tagging %s in git as %s" % (branch, version), Levels.INFO)
tag_release(version, branch)
prettyprint("Step 1: Complete", Levels.INFO)
# Step 2: Update version in tagged files
prettyprint("Step 2: Updating version number in source files", Levels.INFO)
maven_clean()
update_versions(version)
prettyprint("Step 2: Complete", Levels.INFO)
# Step 3: Build and test in Maven2
prettyprint("Step 3: Build and test in Maven3", Levels.INFO)
maven_build_distribution(version)
prettyprint("Step 3: Complete", Levels.INFO)
# Step 4: Generate release notes and place into the 'target' folder
jira_url = "https://issues.jboss.org/"
project_key = 'MODE'
project_name = 'ModeShape'
project_id = '12310930'
prettyprint("Step 4: Generating release notes using JIRA and placing in './target'", Levels.INFO)
jira = Jira(jira_url,project_key,project_id,project_name,version)
generate_release_notes('release_notes.md',version,"target")
prettyprint("Step 4: Complete", Levels.INFO)
# # Step 5: Copy files into archive
archive_path = os.path.join("..","archive",version);
if not os.path.exists(archive_path):
os.makedirs(archive_path)
print "archive_path = '%s'" % archive_path
prettyprint("Step 5: Copying build artifacts and documentation to archive '%s'" % (archive_path), Levels.INFO)
copy_artifacts_to_archive_location(archive_path,version)
copy_release_notes_to_archive_location(archive_path,version);
prettyprint("Step 5: Complete", Levels.INFO)
# Step 6: Generate contribution emails
prettyprint("Step 6: Generating contribution emails using JIRA and placing in '%s'" % (archive_path), Levels.INFO)
generate_contribution_emails(archive_path,'[email protected]')
prettyprint("Step 6: Complete", Levels.INFO)
# Nothing else should modify any files locally ...
## Clean up in git
prettyprint("Step 7: Committing changes to Git, creating release tag, and pushing to 'origin'", Levels.INFO)
git.tag_for_release()
if not settings['dry_run']:
git.push_to_origin()
git.cleanup()
else:
prettyprint("In dry-run mode. Not pushing tag to remote origin and not removing temp release branch '%s'." % git.working_branch, Levels.DEBUG)
prettyprint("Step 7: Complete", Levels.INFO)
async_processes = []
# Step 8: Upload javadocs to JBoss.org
prettyprint("Step 8: Uploading documentation to JBoss.org", Levels.INFO)
do_task(upload_documentation, [base_dir, version], async_processes)
prettyprint("Step 8: Complete", Levels.INFO)
# Step 9: Upload downloads to JBoss.org
prettyprint("Step 9: Uploading downloads to JBoss.org", Levels.INFO)
do_task(upload_artifacts, [base_dir, version], async_processes)
prettyprint("Step 9: Complete", Levels.INFO)
## Wait for processes to finish
for p in async_processes:
p.start()
for p in async_processes:
p.join()
prettyprint("\n\n\nDone! Now all you need to do is the remaining post-release tasks as outlined in https://docspace.corp.redhat.com/docs/DOC-28594", Levels.INFO)
if __name__ == "__main__":
release()