From 6a3edfed930b8b72c13554489835fd0d201d8a86 Mon Sep 17 00:00:00 2001 From: Roger Ineichen Date: Wed, 26 Dec 2012 23:46:35 +0000 Subject: [PATCH] - merge new-product-generation-in-branch-release into trunk - feature: added -i --independent-branches option. This option will force to check if the last release was made from the same branch we are releasing from. This is required if you develop a new software generation in a branch which is independent from the trunk. Previous version of keas.build where only able to handle branch releases as bug fix releases and didn't make sure that we don't mix trunk and branch releases. Now with the -i option we force that all released packages will be made or reused based on the current trunk or branch (-b trunk,branch) - added more logging infos for find or skip next version which makes is simpler to see what's going on - prepare 0.3.0 release --- CHANGES.txt | 14 +++++- setup.py | 2 +- src/keas/build/base.py | 5 +++ src/keas/build/index.txt | 2 + src/keas/build/package.py | 94 +++++++++++++++++++++++++++++++-------- 5 files changed, 95 insertions(+), 22 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 36c4e6d..a4ab5a6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,10 +1,20 @@ CHANGES ======= -0.2.3 (unreleased) +0.3.0 (2012-12-27) ------------------ -- Nothing changed yet. +- feature: added -i --independent-branches option. This option will force + to check if the last release was made from the same branch we are + releasing from. This is required if you develop a new software generation + in a branch which is independent from the trunk. Previous version of + keas.build where only able to handle branch releases as bug fix releases + and didn't make sure that we don't mix trunk and branch releases. Now with + the -i option we force that all released packages will be made or reused + based on the current trunk or branch (-b trunk,branch) + +- added more logging infos for find or skip next version which makes is simpler + to see what's going on 0.2.2 (2011-08-29) diff --git a/setup.py b/setup.py index fb9ccf0..c80ee7e 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def read(*rnames): setup( name='keas.build', - version='0.2.3dev', + version='0.3.0', author = "Stephan Richter and the Zope Community", author_email = "zope-dev@zope.org", description='A Build System', diff --git a/src/keas/build/base.py b/src/keas/build/base.py index 656d20d..e24591d 100644 --- a/src/keas/build/base.py +++ b/src/keas/build/base.py @@ -323,6 +323,11 @@ def optionxform(self, optionstr): dest="branch", metavar="BRANCH", default=None, help="When specified, this branch will be always used.") +parser.add_option( + "-i", "--independent-branches", action="store_true", + dest="independent", metavar="INDEPENDENT", default=False, + help="When specified, the system makes sure the last release is based on the given branch.") + parser.add_option( "--no-upload", action="store_true", dest="noUpload", default=False, diff --git a/src/keas/build/index.txt b/src/keas/build/index.txt index 3657706..07ce282 100644 --- a/src/keas/build/index.txt +++ b/src/keas/build/index.txt @@ -87,6 +87,8 @@ installations):: -n, --next-version When set, the system guesses the next version to generate. -b BRANCH, --use-branch=BRANCH When specified, this branch will be always used. + -i BRANCHES --independent-branches=BRANCH1 BRANCH2, + When specified, the system guesses the next version from all this branches. --no-upload When set, the generated configuration files are not uploaded. --no-branch-update When set, the branch is not updated with a new version after a release is created. diff --git a/src/keas/build/package.py b/src/keas/build/package.py index af4037b..74fb348 100644 --- a/src/keas/build/package.py +++ b/src/keas/build/package.py @@ -222,9 +222,11 @@ def getBranches(self): return branches def hasChangedSince(self, version, branch): - # setup.py gets changed on the branch after the tag is created, so - # that the branch always has a later revision. So let's check the - # source directory instead. + # check if svn revision gets changed on the branch after the tag + # was created, so that the branch always has a later revision. Note + # that our last release was updating the version in setup.py which also + # forces a change after adding the tag. So let's check the source + # directory instead. branchUrl = self.getBranchURL(branch) + '/src' tagUrl = self.getTagURL(version) changed = self.getRevision(branchUrl)[1] > self.getRevision(tagUrl)[1] @@ -234,6 +236,36 @@ def hasChangedSince(self, version, branch): branch, version)) return changed + def isLastReleaseFromBranch(self, version, branch): + # check if the dev marked version in setup.py from the given branch + # compares with our version we will guess. If so, this means no + # other branch was used for release this package. + branchURL = self.getBranchURL(branch) + if branchURL.endswith('/'): + branchURL = branchURL[:-1] + pyURL = '%s/setup.py' % branchURL + req = urllib2.Request(pyURL) + if self.packageIndexUsername: + base64string = base64.encodestring( + '%s:%s' % (self.packageIndexUsername, + self.packageIndexPassword))[:-1] + req.add_header("Authorization", "Basic %s" % base64string) + setuppy = urllib2.urlopen(req).read() + nextVersion = re.search("version ?= ?'(.*)',", setuppy) + if not nextVersion: + logger.error("No version = found in setup.py, cannot update!") + # prevent mess up, force ensure new release + return False + else: + nextVersion = nextVersion.groups()[0] + setupVersion = '%sdev' % base.guessNextVersion(version) + if setupVersion == nextVersion: + return True + else: + logger.info("Last release %s wasn't released from branch %r " % ( + version, branch)) + return False + def createRelease(self, version, branch): logger.info('Creating release %r for %r from branch %r' %( version, self.pkg, branch)) @@ -299,7 +331,7 @@ def createRelease(self, version, branch): else: logger.warn('Unknown uploadType: ' + self.uploadType) - # 5. Update the start branch to the next devel version + # 5. Update the start branch to the next development (dev) version if not self.options.noBranchUpdate: logger.info("Updating branch version metadata") # 5.1. Check out the branch. @@ -328,6 +360,9 @@ def createRelease(self, version, branch): rmtree(buildDir) def runCLI(self, configFile, askToCreateRelease=False, forceSvnAuth=False): + logger.info('-' * 79) + logger.info(self.pkg) + logger.info('-' * 79) logger.info('Start releasing new version of ' + self.pkg) # 1. Read the configuration file. logger.info('Loading configuration file: ' + configFile) @@ -391,23 +426,44 @@ def runCLI(self, configFile, askToCreateRelease=False, forceSvnAuth=False): defaultVersion = forceVersion if versions and not defaultVersion: - # 3.2. If the branch was specified, check whether it changed since - # the last release. - changed = False - if self.options.branch: - logger.info('Checking for changes since version %s; please wait...', versions[-1]) - changed = self.hasChangedSince( - versions[-1], self.options.branch) - if not changed: - logger.info("No changes detected.") - else: - logger.info("Not checking for changes since version %s because no branch was specified.", versions[-1]) - # 3.3. If the branch changed and the next version should be - # suggested, let's find the next version. - if self.options.nextVersion and changed: - defaultVersion = base.guessNextVersion(versions[-1]) + if self.options.nextVersion: + # 3.2. If the branch was specified, check whether it changed + # since the last release or if independent is set, if the last + # release is based on the current branch + changed = False + if self.options.branch: + logger.info("Checking for changes since version %s; please " + "wait...", versions[-1]) + changed = self.hasChangedSince(versions[-1], + self.options.branch) + if self.options.independent and not changed: + # only check if not already marked as changed + logger.info("Checking if last release is based on " + "branch %s; please wait...", + self.options.branch) + if not self.isLastReleaseFromBranch(versions[-1], + self.options.branch): + changed = True + if not changed: + logger.info("No changes detected.") + else: + logger.info("Not checking for changes since version %s " + "because no -b or --use-branch was specified.", + versions[-1]) + # 3.3. If the branch changed and the next version should be + # suggested, let's find the next version. + if changed: + defaultVersion = base.guessNextVersion(versions[-1]) + else: + defaultVersion = versions[-1] else: + logger.info("Not checking for changes because -n or " + "--next-version was not used") defaultVersion = versions[-1] + else: + logger.info( + "Not checking for changes because --force-version was used") + branch = self.options.branch while True: version = base.getInput(