Added version pipe

This commit is contained in:
Sven Heidemann 2022-05-25 18:40:01 +02:00
parent a1a3ad6fb5
commit 15f200df3a
7 changed files with 34 additions and 15 deletions

View File

@ -4,7 +4,7 @@
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "6", "Minor": "6",
"Micro": "15.dev4" "Micro": "15"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",
@ -16,7 +16,7 @@
"LicenseName": "MIT", "LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.", "LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.6.15.dev4" "cpl-core>=2022.6.15"
], ],
"PythonVersion": ">=3.10", "PythonVersion": ">=3.10",
"PythonPath": {}, "PythonPath": {},

View File

@ -4,7 +4,7 @@
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "6", "Minor": "6",
"Micro": "15.dev4" "Micro": "15"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -0,0 +1,14 @@
from cpl_cli.configuration import VersionSettingsNameEnum
from cpl_core.pipes.pipe_abc import PipeABC
class VersionPipe(PipeABC):
def __init__(self): pass
def transform(self, value: dict, *args):
for atr in VersionSettingsNameEnum:
if atr.value not in value:
raise KeyError(atr.value)
return f'{value[VersionSettingsNameEnum.major.value]}.{value[VersionSettingsNameEnum.minor.value]}.{value[VersionSettingsNameEnum.micro.value]}'

View File

@ -4,7 +4,7 @@
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "6", "Minor": "6",
"Micro": "15.dev4" "Micro": "15"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",
@ -16,7 +16,7 @@
"LicenseName": "MIT", "LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.", "LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.6.15.dev4" "cpl-core>=2022.6.15"
], ],
"PythonVersion": ">=3.10", "PythonVersion": ">=3.10",
"PythonPath": {}, "PythonPath": {},

View File

@ -1,10 +1,12 @@
import traceback import traceback
from cpl_cli.configuration import WorkspaceSettings from cpl_cli.configuration.version_settings_name_enum import VersionSettingsNameEnum
from cpl_core.application import ApplicationABC from cpl_cli.configuration.workspace_settings import WorkspaceSettings
from cpl_core.configuration import ConfigurationABC from cpl_core.application.application_abc import ApplicationABC
from cpl_core.console import Console from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.console.console import Console
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl_core.pipes.version_pipe import VersionPipe
from set_version.git_service import GitService from set_version.git_service import GitService
from set_version.version_setter_service import VersionSetterService from set_version.version_setter_service import VersionSetterService
@ -18,6 +20,7 @@ class Application(ApplicationABC):
self._git_service: GitService = self._services.get_service(GitService) self._git_service: GitService = self._services.get_service(GitService)
self._version_setter: VersionSetterService = self._services.get_service(VersionSetterService) self._version_setter: VersionSetterService = self._services.get_service(VersionSetterService)
self._version_pipe: VersionPipe = self._services.get_service(VersionPipe)
def configure(self): def configure(self):
self._configuration.parse_console_arguments(self._services) self._configuration.parse_console_arguments(self._services)
@ -43,9 +46,9 @@ class Application(ApplicationABC):
return return
try: try:
version['Major'] = branch.split('.')[0] version[VersionSettingsNameEnum.major.value] = branch.split('.')[0]
version['Minor'] = branch.split('.')[1] version[VersionSettingsNameEnum.minor.value] = branch.split('.')[1]
version['Micro'] = f'{branch.split(".")[2]}{suffix}' version[VersionSettingsNameEnum.micro.value] = f'{branch.split(".")[2]}{suffix}'
except Exception as e: except Exception as e:
Console.error(f'Branch {branch} does not contain valid version') Console.error(f'Branch {branch} does not contain valid version')
return return
@ -55,7 +58,7 @@ class Application(ApplicationABC):
if not project.startswith('cpl'): if not project.startswith('cpl'):
continue continue
Console.write_line(f'Set version {version["Major"]}.{version["Minor"]}.{version["Micro"]} for {project}') Console.write_line(f'Set version {self._version_pipe.transform(version)} for {project}')
self._version_setter.set_version(self._workspace.projects[project], version) self._version_setter.set_version(self._workspace.projects[project], version)
except Exception as e: except Exception as e:
Console.error('Version could not be set', traceback.format_exc()) Console.error('Version could not be set', traceback.format_exc())

View File

@ -16,7 +16,7 @@
"LicenseName": "", "LicenseName": "",
"LicenseDescription": "", "LicenseDescription": "",
"Dependencies": [ "Dependencies": [
"sh_cpl-core>=2022.6.1.dev4" "sh_cpl-core>=2022.6.15.dev4"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": { "PythonPath": {

View File

@ -5,6 +5,7 @@ from cpl_core.application import StartupABC
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironment from cpl_core.environment import ApplicationEnvironment
from cpl_core.pipes.version_pipe import VersionPipe
from set_version.git_service import GitService from set_version.git_service import GitService
from set_version.version_setter_service import VersionSetterService from set_version.version_setter_service import VersionSetterService
@ -25,5 +26,6 @@ class Startup(StartupABC):
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
services.add_transient(GitService) services.add_transient(GitService)
services.add_transient(VersionSetterService) services.add_transient(VersionSetterService)
services.add_transient(VersionPipe)
return services.build_service_provider() return services.build_service_provider()