[Pkg-mozext-commits] [adblock-plus] 152/464: Added release automation to build.py
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:12 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit 1d957934e3e8c84c56687d60f5a917fbc343ead0
Author: Wladimir Palant <trev at adblockplus.org>
Date: Mon May 16 20:03:23 2011 +0200
Added release automation to build.py
---
build.py | 58 +++++++++++++++++++++++++++++++++++++++-
releaseAutomation.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 131 insertions(+), 1 deletion(-)
diff --git a/build.py b/build.py
index f349237..7d3bd80 100644
--- a/build.py
+++ b/build.py
@@ -5,9 +5,10 @@
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
-import os, sys
+import os, sys, re, buildtools
from getopt import getopt, GetoptError
import buildtools.packager as packager
+import buildtools.releaseAutomation as releaseAutomation
def usage_build(scriptName):
print '''%(name)s build [options] [output_file]
@@ -150,6 +151,58 @@ def showDescriptions(baseDir, scriptName, args):
locale['description.long'] if 'description.long' in locale else 'None',
)).encode('utf-8')
+def usage_release(scriptName):
+ print '''%(name)s release [options] <version>
+
+Note: If you are not the project owner then you probably don't want to run this!
+
+Runs release automation: creates downloads for the new version, tags source code
+repository as well as downloads and buildtools repository.
+
+Options
+ -h --help Show this message and exit
+ -k file --key=file File containing private key and certificates
+ required to sign the release
+ -d dir --downloads=dir Directory containing downloads repository
+ (if omitted ../downloads is assumed)
+''' % {"name": scriptName}
+
+def runReleaseAutomation(baseDir, scriptName, args):
+ try:
+ opts, args = getopt(args, 'hk:d:', ['help', 'key=', 'downloads='])
+ except GetoptError, e:
+ print str(e)
+ usage_release(scriptName)
+ sys.exit(2)
+
+ buildtoolsRepo = buildtools.__path__[0]
+ keyFile = None
+ downloadsRepo = os.path.join(baseDir, '..', 'downloads')
+ for option, value in opts:
+ if option in ('-h', '--help'):
+ usage_release(scriptName)
+ return
+ elif option in ('-k', '--key'):
+ keyFile = value
+ elif option in ('-d', '--downloads'):
+ downloadsRepo = value
+
+ if len(args) == 0:
+ print 'No version number specified for the release'
+ usage_release(scriptName)
+ return
+ version = args[0]
+ if re.search(r'[^\w\.]', version):
+ print 'Wrong version number format'
+ usage_release(scriptName)
+ return
+
+ if keyFile == None:
+ print 'Warning: no key file specified, creating an unsigned release build\n'
+
+ releaseAutomation.run(baseDir, version, keyFile, downloadsRepo, buildtoolsRepo)
+
+
def usage(scriptName):
print '''Usage:
@@ -158,6 +211,7 @@ def usage(scriptName):
%(name)s testenv [options] [profile_dir] ... Set up test environment
%(name)s showdesc [options] Print description strings for
all locales
+ %(name)s release [options] <version> Run release automation
For details on a command run:
@@ -184,6 +238,8 @@ No command given, assuming "build". For a list of commands run:
setupTestEnvironment(baseDir, scriptName, args[1:])
elif command == 'showdesc':
showDescriptions(baseDir, scriptName, args[1:])
+ elif command == 'release':
+ runReleaseAutomation(baseDir, scriptName, args[1:])
else:
print 'Command %s is unrecognized' % command
usage(scriptName)
diff --git a/releaseAutomation.py b/releaseAutomation.py
new file mode 100644
index 0000000..2ba9934
--- /dev/null
+++ b/releaseAutomation.py
@@ -0,0 +1,74 @@
+# coding: utf-8
+
+# The contents of this file are subject to the Mozilla Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+
+import os, re, subprocess, tarfile
+from StringIO import StringIO
+import buildtools.packager as packager
+
+def run(baseDir, version, keyFile, downloadsRepo, buildtoolsRepo):
+ # Replace version number in metadata file "manually", ConfigParser will mess
+ # up the order of lines.
+ handle = open(packager.getMetadataPath(baseDir), 'rb')
+ rawMetadata = handle.read()
+ handle.close()
+ versionRegExp = re.compile(r'^(\s*version\s*=\s*).*', re.I | re.M)
+ rawMetadata = re.sub(versionRegExp, r'\g<1>%s' % version, rawMetadata)
+ handle = open(packager.getMetadataPath(baseDir), 'wb')
+ handle.write(rawMetadata)
+ handle.close()
+
+ # Read extension name and branch name
+ locales = packager.readLocaleMetadata(baseDir, [packager.defaultLocale])
+ extensionName = locales[packager.defaultLocale]['name']
+
+ metadata = packager.readMetadata(baseDir)
+ branchName = metadata.get('general', 'branchname')
+
+ # Now commit the change and tag it
+ subprocess.Popen(['hg', 'commit', '-R', baseDir, '-m', 'Releasing %s %s' % (extensionName, version)]).communicate()
+ subprocess.Popen(['hg', 'tag', '-R', baseDir, '-f', version]).communicate()
+
+ # Create a release build
+ buildPath = os.path.join(downloadsRepo, packager.getDefaultFileName(baseDir, metadata, version))
+ packager.createBuild(baseDir, outFile=buildPath, releaseBuild=True, keyFile=keyFile)
+
+ # Create source archive
+ archivePath = os.path.splitext(buildPath)[0] + '-source.tgz'
+
+ archiveHandle = open(archivePath, 'wb')
+ archive = tarfile.open(fileobj=archiveHandle, name=os.path.basename(archivePath), mode='w:gz')
+ (data, dummy) = subprocess.Popen(['hg', 'archive', '-R', baseDir, '-t', 'tar', '-X', os.path.join(baseDir, '.hgtags'), '-'], stdout=subprocess.PIPE).communicate()
+ repoArchive = tarfile.open(fileobj=StringIO(data), mode='r:')
+ for fileInfo in repoArchive:
+ fileData = repoArchive.extractfile(fileInfo)
+ fileInfo.name = re.sub(r'^[^/]+/', '', fileInfo.name)
+ archive.addfile(fileInfo, fileData)
+ repoArchive.close()
+ (data, dummy) = subprocess.Popen(['hg', 'archive', '-R', buildtoolsRepo, '-t', 'tar', '-X', os.path.join(buildtoolsRepo, '.hgtags'), '-'], stdout=subprocess.PIPE).communicate()
+ repoArchive = tarfile.open(fileobj=StringIO(data), mode='r:')
+ for fileInfo in repoArchive:
+ fileData = repoArchive.extractfile(fileInfo)
+ fileInfo.name = re.sub(r'^[^/]+/', 'buildtools/', fileInfo.name)
+ archive.addfile(fileInfo, fileData)
+ repoArchive.close()
+ archive.close()
+ archiveHandle.close()
+
+ # Now add the downloads, commit and tag the downloads repo
+ tagName = '%s_%s_RELEASE' % (branchName, version.replace('.', '_'))
+ subprocess.Popen(['hg', 'add', '-R', downloadsRepo, buildPath, archivePath]).communicate()
+ subprocess.Popen(['hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version)]).communicate()
+ subprocess.Popen(['hg', 'tag', '-R', downloadsRepo, '-f', tagName]).communicate()
+
+ # Tag buildtools repository as well
+ subprocess.Popen(['hg', 'tag', '-R', buildtoolsRepo, '-f', tagName]).communicate()
+
+ return
+ # Push all changes
+ subprocess.Popen(['hg', 'push', '-R', baseDir]).communicate()
+ subprocess.Popen(['hg', 'push', '-R', downloadsRepo]).communicate()
+ subprocess.Popen(['hg', 'push', '-R', buildtoolsRepo]).communicate()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list