From def92c78c8bb7688c44c943bf8cd6d305236559a Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 26 May 2022 16:25:15 +0200 Subject: [PATCH] Added logic to change version only for projects with changes --- src/cpl_cli/cpl-cli.json | 4 ++-- src/cpl_core/cpl-core.json | 2 +- src/cpl_query/cpl-query.json | 2 +- tools/set_pip_urls/set-pip-urls.json | 2 +- tools/set_version/application.py | 9 +++++++++ tools/set_version/git_service.py | 13 ++++++------- tools/set_version/set-version.json | 2 +- tools/set_version/startup.py | 2 +- unittests/unittests/unittests.json | 4 ++-- unittests/unittests_cli/unittests_cli.json | 6 +++--- unittests/unittests_core/unittests_core.json | 4 ++-- unittests/unittests_query/unittests_query.json | 6 +++--- unittests/unittests_shared/unittests_shared.json | 4 ++-- 13 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/cpl_cli/cpl-cli.json b/src/cpl_cli/cpl-cli.json index e43fa127..b5a709e3 100644 --- a/src/cpl_cli/cpl-cli.json +++ b/src/cpl_cli/cpl-cli.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "17.dev5" + "Micro": "17" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", @@ -16,7 +16,7 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.6.17.dev5" + "cpl-core>=2022.6.17" ], "PythonVersion": ">=3.10", "PythonPath": {}, diff --git a/src/cpl_core/cpl-core.json b/src/cpl_core/cpl-core.json index 7a8a6fbc..7ac905aa 100644 --- a/src/cpl_core/cpl-core.json +++ b/src/cpl_core/cpl-core.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "17.dev5" + "Micro": "17" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/cpl_query/cpl-query.json b/src/cpl_query/cpl-query.json index b4bb2e73..876fc3f2 100644 --- a/src/cpl_query/cpl-query.json +++ b/src/cpl_query/cpl-query.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "17.dev5" + "Micro": "17" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/tools/set_pip_urls/set-pip-urls.json b/tools/set_pip_urls/set-pip-urls.json index 96156cfa..a3c936e3 100644 --- a/tools/set_pip_urls/set-pip-urls.json +++ b/tools/set_pip_urls/set-pip-urls.json @@ -16,7 +16,7 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.6.17.dev5" + "cpl-core>=2022.6.17" ], "PythonVersion": ">=3.10.4", "PythonPath": {}, diff --git a/tools/set_version/application.py b/tools/set_version/application.py index 5acf6e50..0f139550 100644 --- a/tools/set_version/application.py +++ b/tools/set_version/application.py @@ -1,3 +1,4 @@ +import os import traceback from cpl_cli.configuration.version_settings_name_enum import VersionSettingsNameEnum @@ -27,6 +28,7 @@ class Application(ApplicationABC): def main(self): Console.write_line('Set versions:') + args = self._configuration.additional_arguments version = {} branch = "" @@ -53,8 +55,15 @@ class Application(ApplicationABC): Console.error(f'Branch {branch} does not contain valid version') return + diff_paths = [] + for file in self._git_service.get_diff_files(): + diff_paths.append(os.path.basename(os.path.dirname(file))) + try: for project in self._workspace.projects: + if project not in diff_paths: + continue + Console.write_line(f'Set dependencies {self._version_pipe.transform(version)} for {project}') self._version_setter.set_dependencies(self._workspace.projects[project], version) if not project.startswith('cpl') and not project.startswith('unittest'): diff --git a/tools/set_version/git_service.py b/tools/set_version/git_service.py index 263cde5b..0e43b226 100644 --- a/tools/set_version/git_service.py +++ b/tools/set_version/git_service.py @@ -1,4 +1,4 @@ -import os +from git import Repo, DiffIndex from cpl_core.environment import ApplicationEnvironmentABC @@ -7,12 +7,11 @@ class GitService: def __init__(self, env: ApplicationEnvironmentABC): self._env = env + self._repo = Repo(env.working_directory) def get_active_branch_name(self) -> str: - head_dir = os.path.join(self._env.working_directory, '.git/HEAD') - with open(head_dir, 'r') as f: - content = f.read().splitlines() + branch = self._repo.active_branch + return branch.name - for line in content: - if line[0:4] == "ref:": - return line.partition("refs/heads/")[2] + def get_diff_files(self) -> list[str]: + return [item.a_path for item in self._repo.index.diff(None)] diff --git a/tools/set_version/set-version.json b/tools/set_version/set-version.json index 2c076df7..ae872c29 100644 --- a/tools/set_version/set-version.json +++ b/tools/set_version/set-version.json @@ -16,7 +16,7 @@ "LicenseName": "MIT", "LicenseDescription": "MIT, see LICENSE for more details.", "Dependencies": [ - "cpl-core>=2022.6.17.dev5", + "cpl-core>=2022.6.17", "gitpython==3.1.27" ], "PythonVersion": ">=3.10.4", diff --git a/tools/set_version/startup.py b/tools/set_version/startup.py index 31c8a268..609ef337 100644 --- a/tools/set_version/startup.py +++ b/tools/set_version/startup.py @@ -25,7 +25,7 @@ class Startup(StartupABC): def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: services.add_pipes() - services.add_transient(GitService) + services.add_singleton(GitService) services.add_transient(VersionSetterService) return services.build_service_provider() diff --git a/unittests/unittests/unittests.json b/unittests/unittests/unittests.json index 890f9782..be802510 100644 --- a/unittests/unittests/unittests.json +++ b/unittests/unittests/unittests.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "17.dev5" + "Micro": "17.dev6" }, "Author": "", "AuthorEmail": "", @@ -16,7 +16,7 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.6.17.dev5" + "cpl-core>=2022.6.17.dev6" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/unittests/unittests_cli/unittests_cli.json b/unittests/unittests_cli/unittests_cli.json index df178f97..bd09248a 100644 --- a/unittests/unittests_cli/unittests_cli.json +++ b/unittests/unittests_cli/unittests_cli.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "17.dev5" + "Micro": "17.dev6" }, "Author": "", "AuthorEmail": "", @@ -16,8 +16,8 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.6.17.dev5", - "cpl-cli>=2022.6.17.dev5" + "cpl-core>=2022.6.17.dev6", + "cpl-cli>=2022.6.17.dev6" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/unittests/unittests_core/unittests_core.json b/unittests/unittests_core/unittests_core.json index 176f837a..fdf7b69a 100644 --- a/unittests/unittests_core/unittests_core.json +++ b/unittests/unittests_core/unittests_core.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "17.dev5" + "Micro": "17.dev6" }, "Author": "", "AuthorEmail": "", @@ -16,7 +16,7 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.6.17.dev5" + "cpl-core>=2022.6.17.dev6" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/unittests/unittests_query/unittests_query.json b/unittests/unittests_query/unittests_query.json index 81421fe8..326c72d1 100644 --- a/unittests/unittests_query/unittests_query.json +++ b/unittests/unittests_query/unittests_query.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "17.dev5" + "Micro": "17.dev6" }, "Author": "", "AuthorEmail": "", @@ -16,8 +16,8 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.6.17.dev5", - "cpl-query>=2022.6.17.dev5" + "cpl-core>=2022.6.17.dev6", + "cpl-query>=2022.6.17.dev6" ], "PythonVersion": ">=3.10.4", "PythonPath": { diff --git a/unittests/unittests_shared/unittests_shared.json b/unittests/unittests_shared/unittests_shared.json index 76f369a2..cab18497 100644 --- a/unittests/unittests_shared/unittests_shared.json +++ b/unittests/unittests_shared/unittests_shared.json @@ -4,7 +4,7 @@ "Version": { "Major": "2022", "Minor": "6", - "Micro": "17.dev5" + "Micro": "17.dev6" }, "Author": "", "AuthorEmail": "", @@ -16,7 +16,7 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "cpl-core>=2022.6.17.dev5" + "cpl-core>=2022.6.17.dev6" ], "PythonVersion": ">=3.10.4", "PythonPath": {