def need_push(self, push_mode): tag_template_args = template_args.tag_template_args() return { 'always': True, 'never': False, 'on_tag': tag_template_args.get('git_tag', False), 'on_branch:{0}'.format(tag_template_args.get('git_branch', '9x43d83')): True }.get(push_mode, False)
def test_tag_template_args(self, mocked__template_args): self.assertIsNone(template_args._tag_template_args) ret = template_args.tag_template_args() self.assertEqual(ret, {}) self.assertEqual(template_args._tag_template_args, {}) ta = template_args generator_classes = [ta.GitCommitGenerator, ta.GitCommitMsgGenerator, ta.GitBranchGenerator, ta.GitTagGenerator, ta.GitDescribeGenerator, ta.DateGenerator] for obj, cls in zip(mocked__template_args.call_args[0][0], generator_classes): self.assertIsInstance(obj, cls)
def need_push(self, push_mode): tag_template_args = template_args.tag_template_args() return { 'always': True, 'never': False, 'on_tag': tag_template_args.get('git_tag', False), 'on_branch:{0}'.format( tag_template_args.get('git_branch', '9x43d83')): True }.get(push_mode, False)
def test_tag_template_args(self, mocked__template_args): self.assertIsNone(template_args._tag_template_args) ret = template_args.tag_template_args() self.assertEqual(ret, {}) self.assertEqual(template_args._tag_template_args, {}) ta = template_args generator_classes = [ ta.GitCommitGenerator, ta.GitCommitMsgGenerator, ta.GitBranchGenerator, ta.GitTagGenerator, ta.GitDescribeGenerator, ta.DateGenerator ] for obj, cls in zip(mocked__template_args.call_args[0][0], generator_classes): self.assertIsInstance(obj, cls)
def push(self): template_kwargs = template_args.tag_template_args() for push_mode, repo, tag_template in self.pushes: need_push = self.need_push(push_mode) try: tag_name = tag_template.format(**template_kwargs) except KeyError: if need_push: raise PushFailed("can not get tag name for" "tag_template: %s" % tag_template) continue self._update_progress("pushing to %s:%s" % (repo, tag_name)) self._do_push(repo, tag_name) self._update_progress("pushed to %s:%s" % (repo, tag_name))
def tag(self): template_kwargs = template_args.tag_template_args() for push_mode, repo, tag_template in self.pushes: need_push = self.need_push(push_mode) try: tag_name = tag_template.format(**template_kwargs) kwargs = {} if docker_utils.compare_version('1.22', self.docker._version) < 0: kwargs['force'] = True self.docker.tag(self.final_image, repo, tag_name, **kwargs) self._update_progress("tag added: %s:%s" % (repo, tag_name)) except KeyError as e: if need_push: LOG.warn('invalid tag_template for this build: %s', e.message)