def validate(self): existing_dir(self.repo_dir) version.parse_to_semver(self.release_version) if (self.release_commit_callback): existing_file(self.release_commit_callback) existing_file(self.repository_version_file_path)
def validate(self): version.parse_to_semver(self.release_version) # if a tag with the given release version exists, we cannot create another release # pointing to it if self.github_helper.tag_exists(tag_name=self.release_version): raise RuntimeError( f"Cannot create tag '{self.release_version}' for release: Tag already exists" ) if self.component_descriptor_file_path: existing_file(self.component_descriptor_file_path) with open(self.component_descriptor_file_path) as f: # TODO: Proper validation not_empty(f.read().strip())
def validate(self): existing_dir(self.repo_dir) version.parse_to_semver(self.release_version) if self.next_version_callback: existing_file(self.next_version_callback) existing_file(self.repository_version_file_path) # perform version ops once to validate args _calculate_next_cycle_dev_version( release_version=self.release_version, version_operation=self.version_operation, prerelease_suffix=self.prerelease_suffix, )
def test_existing_file(self): import sys existing_file = sys.executable result = examinee.existing_file(existing_file) self.assertEqual(existing_file, result) with capture_out() as (stdout, stderr): with self.assertRaises(Failure): examinee.existing_file('no such file, I hope') self.assertIn('not an existing file', stderr.getvalue().strip()) self.assertTrue(len(stdout.getvalue()) == 0) # should also work with pathlib.Path existing_file = pathlib.Path(existing_file) self.assertEqual(examinee.existing_file(existing_file), existing_file)
def get_kubecfg(self): if self.kubeconfig: return kubernetes.client.ApiClient(configuration=self.kubeconfig) kubeconfig = os.environ.get('KUBECONFIG', None) args = global_ctx().args if args and hasattr(args, 'kubeconfig') and args.kubeconfig: kubeconfig = args.kubeconfig if self.kubeconfig: kubeconfig = self.kubeconfig if not kubeconfig: fail('KUBECONFIG env var must be set') return config.load_kube_config(existing_file(kubeconfig))
def validate(self): version.parse_to_semver(self.release_version) # either cds _OR_ ctf must exist have_ctf = os.path.exists(self.ctf_path) have_cd = os.path.exists(self.component_descriptor_v2_path) if have_ctf and have_cd: ci.util.fail( 'Both CTF and Component Descriptor are defined. Only one may be defined.' ) elif have_cd: existing_file(self.component_descriptor_file_path) with open(self.component_descriptor_file_path) as f: # TODO: Proper validation not_empty(f.read().strip()) component_descriptor_v2 = cm.ComponentDescriptor.from_dict( ci.util.parse_yaml_file(self.component_descriptor_v2_path), ) product.v2.resolve_dependencies( component=component_descriptor_v2.component) # TODO: more validation (e.g. check for uniqueness of names) elif have_ctf: # nothing to do, already uploaded in component_descriptor step. pass
#!/usr/bin/env python3 import os from ci.util import ( check_env, existing_file, ) repo_dir = check_env('REPO_DIR') effective_version = check_env('EFFECTIVE_VERSION') last_tag_file = existing_file( os.path.join(repo_dir, 'concourse', 'resources', 'LAST_RELEASED_TAG')) with open(last_tag_file, 'w') as f: f.write(effective_version)
#!/usr/bin/env python3 import pathlib import fileinput from ci.util import ( check_env, existing_file, ) repo_dir = check_env('REPO_DIR') effective_version = check_env('EFFECTIVE_VERSION') template_file = existing_file( pathlib.Path(repo_dir, 'concourse', 'resources', 'defaults.mako')) lines_replaced = 0 string_to_match = 'tag = ' for line in fileinput.FileInput(str(template_file), inplace=True): if string_to_match in line: if lines_replaced != 0: raise RuntimeError( f'More than one image tag found in template file') leading_spaces = line.index(string_to_match) print(f'{leading_spaces * " "}{string_to_match}"{effective_version}"') lines_replaced = 1 else: print(line, end='')
def enumerate_single_file(self, file_path: str): file_path = existing_file(file_path) with open(file_path) as f: yield from self._filter_codeowners_entries(f.readlines())
def enumerate_codeowners_from_file( file_path: str, ) -> typing.Generator[str, None, None]: file_path = existing_file(file_path) with open(file_path) as f: yield from filter_codeowners_entries(f.readlines())