def new_from_source_descriptor( descriptor: cm.ComponentDescriptor, context_url: str, external_resources: list, local_resources: list, ): return ComponentTool.new_from_descriptor( descriptor=cm.ComponentDescriptor( meta=descriptor.meta, component=cm.Component( name=descriptor.component.name, version=descriptor.component.version, repositoryContexts=[ cm.RepositoryContext( baseUrl=context_url, type=cm.AccessType.OCI_REGISTRY, ), ], provider=descriptor.component.provider, sources=descriptor.component.sources, componentReferences=descriptor.component.componentReferences, externalResources=external_resources, localResources=local_resources, ) ) )
def base_component_descriptor_v2( component_name_v2: str, component_labels: typing.Iterable[cm.Label], effective_version: str, source_labels: tuple, ctx_repository_base_url: str, commit: str, ): import gci.componentmodel as cm import version as version_util parsed_version = version_util.parse_to_semver(effective_version) if parsed_version.finalize_version() == parsed_version: # "final" version --> there will be a tag, later (XXX hardcoded hack) src_ref = f'refs/tags/{effective_version}' else: # let's hope the version contains something committish if parsed_version.build: src_ref = f'{parsed_version.prerelease}{parsed_version.build}' else: src_ref = f'{parsed_version.prerelease}' # logical names must not contain slashes or dots logical_name = component_name_v2.replace('/', '_').replace('.', '_') base_descriptor_v2 = cm.ComponentDescriptor( meta=cm.Metadata(schemaVersion=cm.SchemaVersion.V2), component=cm.Component( name=component_name_v2, version=effective_version, repositoryContexts=[ cm.RepositoryContext( baseUrl=ctx_repository_base_url, type=cm.AccessType.OCI_REGISTRY, ) ], provider=cm.Provider.INTERNAL, sources=[ cm.ComponentSource( name=logical_name, type=cm.SourceType.GIT, access=cm.GithubAccess( type=cm.AccessType.GITHUB, repoUrl=component_name_v2, ref=src_ref, commit=commit, ), version=effective_version, labels=source_labels, ) ], componentReferences=[], # added later resources=[], # added later labels=list(component_labels), ), ) return base_descriptor_v2
def test_is_obsolete(): examinee = create_upgrade_pr( from_ref=cm.ComponentReference( name='c1', componentName='c1', version='1.2.3', ), to_ref=cm.ComponentReference( name='c1', componentName='c1', version='2.0.0', ), ) cref = cm.ComponentReference( name='c1', componentName='c1', version='6.0.0', ) reference_component = cm.Component(name='c1', version='6.6.6', repositoryContexts=(), provider=None, sources=(), resources=(), componentReferences=()) # test with reference component not declaring this dependency assert not examinee.is_obsolete(reference_component=reference_component) # add differently-named dependency with greater version reference_component.componentReferences = (dataclasses.replace( cref, name='other-name'), ) assert not examinee.is_obsolete(reference_component=reference_component) # add same-named web dependency with lesser version reference_component.componentReferences = (dataclasses.replace( cref, version='0.0.1'), ) assert not examinee.is_obsolete(reference_component=reference_component) # add same-named resource of greater version but different type # todo: we should actually also test dependencies towards resources of two different types reference_component.resources = (cm.Resource( name='c1', version='6.0.0', type=cm.ResourceType.GENERIC, access=None, ), ) assert not examinee.is_obsolete(reference_component=reference_component) # finally, add greater dependency of matching type and name reference_component.componentReferences = (dataclasses.replace( cref, version='9.9.9'), ) assert examinee.is_obsolete(reference_component=reference_component)
def examinee(self, tmp_path): # prepare test component descriptor file and fill it with test content component_descriptor_file = tmp_path.joinpath( 'test_descriptor').resolve() component_descriptor_file.write_text( 'component descriptor test content') component_descriptor_v2 = os.path.join(tmp_path, 'component_descriptor_v2') ctf_path = os.path.join(tmp_path, product.v2.CTF_OUT_DIR_NAME) cd_v2 = cm.ComponentDescriptor( component=cm.Component( name='a_name', version='1.2.3', repositoryContexts=[], provider=cm.Provider.INTERNAL, sources=[], componentReferences=[], resources=[], ), meta=cm.Metadata(), ) with open(component_descriptor_v2, 'w') as f: yaml.dump( data=dataclasses.asdict(cd_v2), stream=f, Dumper=cm.EnumValueYamlDumper, ) def _examinee( githubrepobranch=GitHubRepoBranch( github_config='test_config', repo_owner='test_owner', repo_name='test_name', branch='master', ), repo_dir=str(tmp_path), release_version='1.0.0', tag_helper_return_value=False, component_descriptor_file_path=str(component_descriptor_file), ): # Create a github_helper mock that always reports a tag as existing/not existing, # depending on the passed value github_helper_mock = MagicMock(spec=GitHubRepositoryHelper) return concourse.steps.release.GitHubReleaseStep( github_helper=github_helper_mock, githubrepobranch=githubrepobranch, repo_dir=repo_dir, release_version=release_version, component_descriptor_file_path=component_descriptor_file_path, component_descriptor_v2_path=component_descriptor_v2, ctf_path=ctf_path, ) return _examinee
def comp(name, version) -> cm.Component: return cm.Component( name=name, version=version, provider=cm.Provider.INTERNAL, repositoryContexts=[], componentReferences=[], sources=[], resources=[], labels=[], )
def _comp(name=name, version=version): return cm.Component( name=name, version=version, repositoryContexts=[ cm.RepositoryContext( baseUrl='example.com/context', type=cm.AccessType.OCI_REGISTRY, ), ], provider=cm.Provider, sources=cm.ComponentSource, componentReferences=cm.ComponentReference, resources=cm.Resource, )
def examinee(self, tmp_path): component_descriptor_v2 = os.path.join(tmp_path, 'component_descriptor_v2') ctf_path = os.path.join(tmp_path, product.v2.CTF_OUT_DIR_NAME) cd_v2 = cm.ComponentDescriptor( component=cm.Component( name='example.com/a_name', version='1.2.3', repositoryContexts=[], provider=cm.Provider.INTERNAL, sources=[], componentReferences=[], resources=[], ), meta=cm.Metadata(), ) with open(component_descriptor_v2, 'w') as f: yaml.dump( data=dataclasses.asdict(cd_v2), stream=f, Dumper=cm.EnumValueYamlDumper, ) def _examinee( github_helper=MagicMock(), githubrepobranch=GitHubRepoBranch( github_config='test_config', repo_owner='test_owner', repo_name='test_name', branch='master', ), repository_hostname="example.com", repository_path="a_name", repo_dir=str(tmp_path), release_version='1.0.0', ): return concourse.steps.release.PublishReleaseNotesStep( github_helper=github_helper, githubrepobranch=githubrepobranch, repository_hostname=repository_hostname, repository_path=repository_path, repo_dir=repo_dir, release_version=release_version, component_descriptor_v2_path=component_descriptor_v2, ctf_path=ctf_path, ) return _examinee
def test_component(): component = cm.Component( name='component-name', version='1.2.3', repositoryContexts=[ cm.RepositoryContext(baseUrl='old-ctx-url'), cm.RepositoryContext(baseUrl='current-ctx-url'), ], provider=None, sources=(), componentReferences=(), resources=(), labels=(), ) assert component.current_repository_ctx().baseUrl == 'current-ctx-url'
def _base_component_descriptor( version: str, ctx_repository_base_url: str, commit: str, branch: str, component_name: str = 'github.com/gardenlinux/gardenlinux', ): parsed_version = version_util.parse_to_semver(version) if parsed_version.finalize_version() == parsed_version: # "final" version --> there will be a tag, later src_ref = f'refs/tags/{version}' else: src_ref = f'refs/heads/{branch}' # logical names must not contain slashes or dots logical_name = component_name.replace('/', '_').replace('.', '_') base_descriptor_v2 = cm.ComponentDescriptor( meta=cm.Metadata(schemaVersion=cm.SchemaVersion.V2), component=cm.Component( name=component_name, version=version, repositoryContexts=[ cm.OciRepositoryContext( baseUrl=ctx_repository_base_url, type=cm.AccessType.OCI_REGISTRY, ) ], provider=cm.Provider.INTERNAL, sources=[ cm.ComponentSource( name=logical_name, type=cm.SourceType.GIT, access=cm.GithubAccess( type=cm.AccessType.GITHUB, repoUrl=component_name, ref=src_ref, commit=commit, ), version=version, ) ], componentReferences=[], resources=[], # added later ), ) return base_descriptor_v2
def test_label_usage(): component_name = 'c' component_version = '1.2.3' sources = [ cm.ComponentSource( name='repo_aux_source', access=cm.GithubAccess(type=cm.AccessType.GITHUB, ref='refs/heads/master', repoUrl='github.com/otherOrg/otherRepo'), labels=[ cm.Label( name='cloud.gardener/cicd/source', value={'repository-classification': 'auxiliary'}, ), ], ), cm.ComponentSource( name='repo_main_source', access=cm.GithubAccess(type=cm.AccessType.GITHUB, ref='refs/heads/master', repoUrl='github.com/org/repo'), labels=[ cm.Label( name='cloud.gardener/cicd/source', value={'repository-classification': 'main'}, ), ], ), ] component_with_source_label = cm.Component( name=component_name, version=component_version, sources=sources, componentReferences=[], labels=[], repositoryContexts=[ cm.RepositoryContext( baseUrl= 'eu.gcr.io/sap-se-gcr-k8s-private/cnudie/gardener/landscapes', type='ociRegistry', ), ], resources=[], provider=[], ) main_source = cnudie.util.determine_main_source_for_component( component_with_source_label, ) assert main_source.labels[0].value == {'repository-classification': 'main'} assert main_source.name == 'repo_main_source' component_without_source_label = cm.Component( name=component_name, version=component_version, sources=[ cm.ComponentSource( name='repo_main_source', access=cm.GithubAccess(type=cm.AccessType.GITHUB, ref='refs/heads/master', repoUrl='github.com/org/repo'), ), cm.ComponentSource( name='repo_aux_source', access=cm.GithubAccess( type=cm.AccessType.GITHUB, ref='refs/heads/master', repoUrl='github.com/otherOrg/otherRepo'), ), ], componentReferences=[], labels=[], repositoryContexts=[ cm.RepositoryContext( baseUrl= 'eu.gcr.io/sap-se-gcr-k8s-private/cnudie/gardener/landscapes', type='ociRegistry', ), ], resources=[], provider=[], ) main_source = cnudie.util.determine_main_source_for_component( component_without_source_label) assert main_source.name == 'repo_main_source'
def comp(name, version) -> cm.Component: return cm.Component(name, version, [], [], [], [], [], [])