Example #1
0
 def test_invalid_args_append_prerelease_missing(self):
     with self.assertRaises(ValueError):
         examinee.process_version(
         version_str='3.5.4',
         operation='append_prerelease',
         prerelease='foo'
     )
Example #2
0
 def test_set_verbatim_without_verbatim_version(self):
     with self.assertRaises(ValueError):
         examinee.process_version(
             version_str='3.1.4-foo',
             operation='set_verbatim',
             prerelease='baz'
         )
Example #3
0
 def test_invalid_args_build_metadata_len_less_than_zero(self):
     with self.assertRaises(ValueError):
         examinee.process_version(
         version_str='3.5.4',
         operation='set_build_metadata',
         build_metadata='someRandomString',
         build_metadata_length=-1
     )
Example #4
0
def _calculate_next_cycle_dev_version(
    release_version: str,
    version_operation: str,
    prerelease_suffix: str,
):
    # calculate the next version and append the prerelease suffix
    return version.process_version(
        version_str=version.process_version(
            version_str=release_version,
            operation=version_operation,
        ),
        operation='set_prerelease',
        prerelease=prerelease_suffix,
    )
Example #5
0
 def test_set_build_metadata_with_build_metadata(self):
     parsed = examinee.process_version(
         version_str='3.3.3+foo',
         operation='set_build_metadata',
         build_metadata='build'
     )
     self.assertEqual(parsed, '3.3.3+build')
Example #6
0
 def test_set_prerelease_without_suffix(self):
     parsed = examinee.process_version(
         version_str='1.2.3',
         operation='set_prerelease',
         prerelease='dev'
     )
     self.assertEqual(parsed, '1.2.3-dev')
Example #7
0
 def test_set_verbatim_with_verbatim_version(self):
     parsed = examinee.process_version(
         version_str='3.1.4-foo+bar',
         operation='set_verbatim',
         verbatim_version='master',
     )
     self.assertEqual(parsed, 'master')
Example #8
0
 def test_append_prerelease(self):
     parsed = examinee.process_version(
         version_str='4.9.16-foo',
         operation='append_prerelease',
         prerelease='bar',
     )
     self.assertEqual(parsed, '4.9.16-foo-bar')
Example #9
0
 def test_append_prerelease_with_build_metadata(self):
     parsed = examinee.process_version(
         version_str='3.1.4-foo+bar',
         operation='append_prerelease',
         prerelease='baz',
     )
     self.assertEqual(parsed, '3.1.4-foo-baz+bar')
Example #10
0
 def test_set_prerelease_with_build_metadata(self):
     parsed = examinee.process_version(
         version_str='1.2.3+foo',
         operation='set_prerelease',
         prerelease='dev'
     )
     self.assertEqual(parsed, '1.2.3-dev')
Example #11
0
 def test_set_build_metadata_length(self):
     parsed = examinee.process_version(
         version_str='1.3.5',
         operation='set_build_metadata',
         build_metadata='someRandomString',
         build_metadata_length=10
     )
     self.assertEqual(parsed, '1.3.5+someRandom')
Example #12
0
 def test_set_prerelease_and_build_metadata_without_suffix(self):
     parsed = examinee.process_version(
         version_str='6.6.6',
         operation='set_prerelease_and_build',
         prerelease='dev',
         build_metadata='build'
     )
     self.assertEqual(parsed, '6.6.6-dev+build')
Example #13
0
 def test_set_prerelease_and_build_metadata_with_prerelease_and_build(self):
     parsed = examinee.process_version(
         version_str='8.1.5-bar+baz',
         operation='set_prerelease_and_build',
         prerelease='dev',
         build_metadata='build'
     )
     self.assertEqual(parsed, '8.1.5-dev+build')
Example #14
0
 def test_invalid_args_build_metadata_missing(self):
     with self.assertRaises(ValueError):
         examinee.process_version(version_str='1.2.3',
                                  operation='set_build_metadata')
Example #15
0
 def test_invalid_args_prerelease_missing(self):
     with self.assertRaises(ValueError):
         examinee.process_version(version_str='1.2.3',
                                  operation='set_prerelease')
Example #16
0
 def test_invalid_version(self):
     with self.assertRaises(ValueError):
         examinee.process_version(version_str='invalid', operation='noop')
Example #17
0
 def test_bump_patch(self):
     parsed = examinee.process_version(version_str='2.4.6',
                                       operation='bump_patch')
     self.assertEqual(parsed, '2.4.7')
Example #18
0
 def test_bump_minor(self):
     parsed = examinee.process_version(version_str='2.4.6',
                                       operation='bump_minor')
     self.assertEqual(parsed, '2.5.0')
Example #19
0
 def test_noop(self):
     parsed = examinee.process_version(version_str='1.2.3-abc',
                                       operation='noop')
     self.assertEqual(parsed, '1.2.3-abc')
def build_component_descriptor(
    version: str,
    committish: str,
    cicd_cfg_name: str,
    gardenlinux_epoch: str,
    publishing_actions: str,
    ctx_repository_config_name: str,
    branch: str,
    snapshot_ctx_repository_config_name: str = None,
):
    publishing_actions = [
        glci.model.PublishingAction(action.strip())
        for action in publishing_actions.split(',')
    ]
    if glci.model.PublishingAction.COMPONENT_DESCRIPTOR not in publishing_actions:
        print(
            f'publishing action {glci.model.PublishingAction.COMPONENT_DESCRIPTOR} not specified '
            'exiting now')
        sys.exit(0)
    if glci.model.PublishingAction.BUILD_ONLY in publishing_actions:
        print(
            f'publishing action {glci.model.PublishingAction.BUILD_ONLY=} specified - exiting now'
        )
        sys.exit(0)

    cicd_cfg = glci.util.cicd_cfg(cfg_name=cicd_cfg_name)
    flavour_set = glci.util.flavour_set(flavour_set_name='all')

    find_releases = glci.util.preconfigured(
        func=glci.util.find_releases,
        cicd_cfg=cicd_cfg,
    )

    releases = tuple(
        find_releases(
            flavour_set=flavour_set,
            version=version,
            build_committish=committish,
            gardenlinux_epoch=int(gardenlinux_epoch),
            prefix=glci.model.ReleaseManifest.manifest_key_prefix,
        ))

    if glci.model.PublishingAction.RELEASE not in publishing_actions:
        version = version_util.process_version(
            version_str=version,
            operation=version_util.SET_PRERELEASE,
            prerelease=committish,
        )

    base_url = _resolve_ctx_repository_config(ctx_repository_config_name)
    if snapshot_ctx_repository_config_name:
        snapshot_repo_base_url = _resolve_ctx_repository_config(
            snapshot_ctx_repository_config_name)
    else:
        snapshot_repo_base_url = None

    component_descriptor = _base_component_descriptor(
        version=version,
        branch=branch,
        commit=committish,
        ctx_repository_base_url=base_url)

    component_descriptor.component.resources.extend([
        virtual_machine_image_resource(release_manifest, cicd_cfg)
        for release_manifest in releases
    ])

    logger.info('Generated Component-Descriptor:\n'
                f'{pprint.pformat(dataclasses.asdict(component_descriptor))}')

    if glci.model.PublishingAction.RELEASE in publishing_actions:
        product.v2.upload_component_descriptor_v2_to_oci_registry(
            component_descriptor_v2=component_descriptor, )

    if snapshot_repo_base_url:
        if base_url != snapshot_repo_base_url:
            repo_ctx = cm.OciRepositoryContext(
                baseUrl=snapshot_repo_base_url,
                type=cm.AccessType.OCI_REGISTRY,
            )
            component_descriptor.component.repositoryContexts.append(repo_ctx)

        # upload obeys the appended repo_ctx
        product.v2.upload_component_descriptor_v2_to_oci_registry(
            component_descriptor_v2=component_descriptor,
            on_exist=product.v2.UploadMode.OVERWRITE,
        )
Example #21
0
def release_and_prepare_next_dev_cycle(
    github_cfg_name: str,
    github_repository_owner: str,
    github_repository_name: str,
    repository_branch: str,
    repository_version_file_path: str,
    release_version: str,
    release_notes: str,
    version_operation: str="bump_minor",
    prerelease_suffix: str="dev",
    author_name: str="gardener-ci",
    author_email: str="*****@*****.**",
):
    # retrieve github-cfg from secrets-server
    from config import _retrieve_model_element
    github_cfg = _retrieve_model_element(cfg_type='github', cfg_name=github_cfg_name)

    # Do all the version handling upfront to catch errors early
    # Bump release version and add suffix
    next_version = version.process_version(
        version_str=release_version,
        operation=version_operation
    )
    next_version_dev = version.process_version(
        version_str=next_version,
        operation='set_prerelease',
        prerelease=prerelease_suffix
    )

    github = _create_github_api_object(github_cfg=github_cfg)

    helper = GitHubHelper(
        github=github,
        repository_owner=github_repository_owner,
        repository_name=github_repository_name,
    )

    # Persist version change, create release commit
    release_commit_sha = helper.create_or_update_file(
        repository_branch=repository_branch,
        repository_version_file_path=repository_version_file_path,
        file_contents=release_version,
        commit_message="Release " + release_version
    )
    helper.create_tag(
        tag_name=release_version,
        tag_message=release_notes,
        repository_reference=release_commit_sha,
        author_name=author_name,
        author_email=author_email
    )
    helper.repository.create_release(
      tag_name=release_version,
      body=release_notes,
      draft=False,
      prerelease=False
    )

    # Prepare version file for next dev cycle
    helper.create_or_update_file(
        repository_branch=repository_branch,
        repository_version_file_path=repository_version_file_path,
        file_contents=next_version_dev,
        commit_message="Prepare next dev cycle " + next_version_dev
    )