2022-05-26 16:25:15 +02:00
|
|
|
import os
|
2022-05-25 16:43:28 +02:00
|
|
|
import traceback
|
|
|
|
|
2022-12-03 23:42:23 +01:00
|
|
|
from cpl_cli.configuration import ProjectSettings
|
2022-05-26 21:41:42 +02:00
|
|
|
from cpl_core.utils import String
|
|
|
|
|
2022-05-25 18:40:01 +02:00
|
|
|
from cpl_cli.configuration.version_settings_name_enum import VersionSettingsNameEnum
|
|
|
|
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
|
|
|
from cpl_core.application.application_abc import ApplicationABC
|
|
|
|
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
|
|
|
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
|
2022-05-25 16:43:28 +02:00
|
|
|
from set_version.git_service import GitService
|
|
|
|
from set_version.version_setter_service import VersionSetterService
|
2022-05-25 13:43:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Application(ApplicationABC):
|
|
|
|
|
|
|
|
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
|
|
|
ApplicationABC.__init__(self, config, services)
|
|
|
|
|
2022-05-25 16:43:28 +02:00
|
|
|
self._workspace: WorkspaceSettings = config.get_configuration(WorkspaceSettings)
|
|
|
|
|
|
|
|
self._git_service: GitService = self._services.get_service(GitService)
|
|
|
|
self._version_setter: VersionSetterService = self._services.get_service(VersionSetterService)
|
2022-05-25 18:40:01 +02:00
|
|
|
self._version_pipe: VersionPipe = self._services.get_service(VersionPipe)
|
2022-05-25 16:43:28 +02:00
|
|
|
|
2022-05-25 13:43:16 +02:00
|
|
|
def configure(self):
|
2022-05-25 16:43:28 +02:00
|
|
|
self._configuration.parse_console_arguments(self._services)
|
2022-05-25 13:43:16 +02:00
|
|
|
|
|
|
|
def main(self):
|
2022-05-25 16:43:28 +02:00
|
|
|
Console.write_line('Set versions:')
|
2022-05-26 16:25:15 +02:00
|
|
|
|
2022-05-25 16:43:28 +02:00
|
|
|
args = self._configuration.additional_arguments
|
|
|
|
version = {}
|
|
|
|
branch = ""
|
|
|
|
suffix = ""
|
2022-05-26 23:01:23 +02:00
|
|
|
force = False
|
|
|
|
if '--force' in args:
|
|
|
|
args.remove('--force')
|
|
|
|
force = True
|
|
|
|
|
2022-05-25 16:43:28 +02:00
|
|
|
if len(args) > 1:
|
|
|
|
Console.error(f'Unexpected argument(s): {", ".join(args[1:])}')
|
|
|
|
return
|
|
|
|
|
|
|
|
if len(args) == 1:
|
2022-12-03 23:42:23 +01:00
|
|
|
suffix = args[0]
|
2022-05-25 16:43:28 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
branch = self._git_service.get_active_branch_name()
|
|
|
|
Console.write_line(f'Found branch: {branch}')
|
|
|
|
except Exception as e:
|
2022-12-03 23:42:23 +01:00
|
|
|
Console.error('Branch not found', traceback.format_exc())
|
2022-05-25 16:43:28 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2022-12-03 23:42:23 +01:00
|
|
|
if branch.startswith('#'):
|
|
|
|
self._configuration.add_json_file(self._workspace.projects[self._workspace.default_project], optional=False, output=False)
|
|
|
|
ps: ProjectSettings = self._configuration.get_configuration(ProjectSettings)
|
2022-06-27 20:46:01 +02:00
|
|
|
|
2022-12-03 23:42:23 +01:00
|
|
|
version[VersionSettingsNameEnum.major.value] = ps.version.major
|
|
|
|
version[VersionSettingsNameEnum.minor.value] = ps.version.minor
|
|
|
|
version[VersionSettingsNameEnum.micro.value] = f'dev{branch.split("#")[1]}'
|
2022-06-27 20:46:01 +02:00
|
|
|
else:
|
2022-12-03 23:42:23 +01:00
|
|
|
version[VersionSettingsNameEnum.major.value] = branch.split('.')[0]
|
|
|
|
version[VersionSettingsNameEnum.minor.value] = branch.split('.')[1]
|
|
|
|
if len(branch.split('.')) == 2:
|
|
|
|
if suffix == '':
|
|
|
|
suffix = '0'
|
|
|
|
version[VersionSettingsNameEnum.micro.value] = f'{suffix}'
|
|
|
|
else:
|
|
|
|
if not suffix.startswith('.') and suffix != '':
|
|
|
|
suffix = f'.{suffix}'
|
|
|
|
version[VersionSettingsNameEnum.micro.value] = f'{branch.split(".")[2]}{suffix}'
|
2022-05-25 16:43:28 +02:00
|
|
|
except Exception as e:
|
|
|
|
Console.error(f'Branch {branch} does not contain valid version')
|
|
|
|
return
|
|
|
|
|
2022-05-26 16:25:15 +02:00
|
|
|
diff_paths = []
|
|
|
|
for file in self._git_service.get_diff_files():
|
2022-12-03 23:42:23 +01:00
|
|
|
if file.startswith('tools'):
|
|
|
|
continue
|
|
|
|
|
2022-05-26 23:27:20 +02:00
|
|
|
if '/' in file:
|
2022-12-03 23:42:23 +01:00
|
|
|
file = file.split('/')[1]
|
2022-05-26 23:27:20 +02:00
|
|
|
else:
|
2022-12-03 23:42:23 +01:00
|
|
|
file = os.path.basename(os.path.dirname(file))
|
|
|
|
|
|
|
|
if file in diff_paths:
|
|
|
|
continue
|
|
|
|
|
|
|
|
diff_paths.append(file)
|
2022-05-26 16:25:15 +02:00
|
|
|
|
2022-05-25 16:43:28 +02:00
|
|
|
try:
|
2022-05-27 18:17:07 +02:00
|
|
|
skipped = []
|
2022-05-25 16:43:28 +02:00
|
|
|
for project in self._workspace.projects:
|
2022-05-26 23:01:23 +02:00
|
|
|
if project not in diff_paths and String.convert_to_snake_case(project) not in diff_paths and not force:
|
2022-12-03 23:42:23 +01:00
|
|
|
# Console.write_line(f'Skipping {project} due to missing changes')
|
2022-05-27 18:17:07 +02:00
|
|
|
skipped.append(project)
|
2022-05-26 16:25:15 +02:00
|
|
|
continue
|
|
|
|
|
2022-05-25 18:54:21 +02:00
|
|
|
Console.write_line(f'Set dependencies {self._version_pipe.transform(version)} for {project}')
|
2022-07-10 17:23:50 +02:00
|
|
|
self._version_setter.set_dependencies(self._workspace.projects[project], version, 'Dependencies', skipped=skipped)
|
|
|
|
self._version_setter.set_dependencies(self._workspace.projects[project], version, 'DevDependencies', skipped=skipped)
|
2022-05-25 16:43:28 +02:00
|
|
|
|
2022-05-25 18:40:01 +02:00
|
|
|
Console.write_line(f'Set version {self._version_pipe.transform(version)} for {project}')
|
2022-05-25 16:43:28 +02:00
|
|
|
self._version_setter.set_version(self._workspace.projects[project], version)
|
|
|
|
except Exception as e:
|
|
|
|
Console.error('Version could not be set', traceback.format_exc())
|
|
|
|
return
|