def pre_release(self): # test that the release path exists release_path = self.package.config.release_packages_path if not os.path.exists(release_path): raise ReleaseError("Release path does not exist: %r" % release_path) # test that the repo is in a state to release assert self.vcs self._print("Checking state of repository...") self.vcs.validate_repostate() it = iter_packages(self.package.name, paths=[release_path]) packages = sorted(it, key=lambda x: x.version, reverse=True) # check UUID. This stops unrelated packages that happen to have the same # name, being released as though they are the same package if self.package.uuid and packages: latest_package = packages[0] if latest_package.uuid and latest_package.uuid != self.package.uuid: raise ReleaseError( "Cannot release - the packages are not the same (UUID mismatch)" ) # test that a newer package version hasn't already been released if self.ensure_latest: for package in packages: if package.version > self.package.version: raise ReleaseError( "Cannot release - a newer package version already " "exists (%s)" % package.uri) else: break
def pre_release(self): release_settings = self.package.config.plugins.release_vcs # test that the release path exists release_path = self.package.config.release_packages_path if not os.path.exists(release_path): raise ReleaseError("Release path does not exist: %r" % release_path) # test that the repo is in a state to release if self.vcs: self._print("Checking state of repository...") with self.repo_operation(): self.vcs.validate_repostate() # check if the repo is already tagged at the current version if release_settings.check_tag and not self.ignore_existing_tag: tag_name = self.get_current_tag_name() tag_exists = False with self.repo_operation(): tag_exists = self.vcs.tag_exists(tag_name) if tag_exists: raise ReleaseError( "Cannot release - the current package version '%s' is " "already tagged in the repository. Use --ignore-existing-tag " "to force the release" % self.package.version) it = iter_packages(self.package.name, paths=[release_path]) packages = sorted(it, key=lambda x: x.version, reverse=True) # check UUID. This stops unrelated packages that happen to have the same # name, being released as though they are the same package if self.package.uuid and packages: latest_package = packages[0] if latest_package.uuid and latest_package.uuid != self.package.uuid: raise ReleaseError( "Cannot release - the packages are not the same (UUID mismatch)" ) # test that a newer package version hasn't already been released if self.ensure_latest: for package in packages: if package.version > self.package.version: raise ReleaseError( "Cannot release - a newer package version already " "exists (%s)" % package.uri) else: break
def get_current_tag_name(self): release_settings = self.package.config.plugins.release_vcs try: tag_name = self.package.format(release_settings.tag_name) except Exception as e: raise ReleaseError("Error formatting release tag name: %s" % str(e)) if not tag_name: tag_name = "unversioned" return tag_name
def post_release(self, release_message=None): # format tag release_settings = self.package.config.plugins.release_vcs try: tag_name = self.package.format(release_settings.tag_name) except Exception as e: raise ReleaseError("Error formatting release tag name: %s" % str(e)) if not tag_name: tag_name = "unversioned" # write a tag for the new release into the vcs assert self.vcs self.vcs.create_release_tag(tag_name=tag_name, message=release_message)
def run_hooks(self, hook_event, **kwargs): for hook in self.hooks: self.debug_print("Running %s hook '%s'...", hook_event.label, hook.name()) try: func = getattr(hook, hook_event.func_name) func(user=getpass.getuser(), **kwargs) except ReleaseHookCancellingError as e: raise ReleaseError("%s cancelled by %s hook '%s': %s:\n%s" % (hook_event.noun, hook_event.label, hook.name(), e.__class__.__name__, str(e))) except RezError: self.debug_print("Error in %s hook '%s': %s:\n%s" % (hook_event.label, hook.name(), e.__class__.__name__, str(e)))
def run_hooks(self, hook_event, **kwargs): hook_names = self.package.config.release_hooks or [] hooks = create_release_hooks(hook_names, self.working_dir) for hook in hooks: debug_print("Running %s hook '%s'...", hook_event.label, hook.name()) try: func = getattr(hook, hook_event.__name__) func(user=getpass.getuser(), **kwargs) except ReleaseHookCancellingError as e: raise ReleaseError("%s cancelled by %s hook '%s': %s:\n%s" % (hook_event.noun, hook_event.label, hook.name(), e.__class__.__name__, str(e))) except RezError: debug_print("Error in %s hook '%s': %s:\n%s" % (hook_event.label, hook.name(), e.__class__.__name__, str(e)))