Improved set-version tool & set version

This commit is contained in:
Sven Heidemann 2022-12-03 23:42:23 +01:00
parent 099a51ed93
commit b02aebef35
15 changed files with 65 additions and 50 deletions

View File

@ -3,8 +3,8 @@
"Name": "cpl-cli", "Name": "cpl-cli",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "1.post1" "Micro": "0"
}, },
"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.10.0" "cpl-core>=2022.12.0"
], ],
"DevDependencies": [], "DevDependencies": [],
"PythonVersion": ">=3.10", "PythonVersion": ">=3.10",

View File

@ -3,8 +3,8 @@
"Name": "cpl-core", "Name": "cpl-core",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "0.post9" "Micro": "0"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -16,12 +16,12 @@
"LicenseName": "MIT", "LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.", "LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.10.0", "cpl-core>=2022.12.0",
"discord.py==2.0.1", "discord.py==2.1.0",
"cpl-query>=2022.10.0" "cpl-query>=2022.12.0"
], ],
"DevDependencies": [ "DevDependencies": [
"cpl-cli>=2022.10.0" "cpl-cli>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},

View File

@ -3,8 +3,8 @@
"Name": "cpl-query", "Name": "cpl-query",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "0.post2" "Micro": "0"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -16,10 +16,10 @@
"LicenseName": "MIT", "LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.", "LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.10.0" "cpl-core>=2022.12.0"
], ],
"DevDependencies": [ "DevDependencies": [
"cpl-cli>=2022.10.0" "cpl-cli>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": { "PythonPath": {

View File

@ -3,7 +3,7 @@
"Name": "set-pip-urls", "Name": "set-pip-urls",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "6", "Minor": "12",
"Micro": "0" "Micro": "0"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
@ -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.10.0" "cpl-core>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},

View File

@ -1,6 +1,7 @@
import os import os
import traceback import traceback
from cpl_cli.configuration import ProjectSettings
from cpl_core.utils import String from cpl_core.utils import String
from cpl_cli.configuration.version_settings_name_enum import VersionSettingsNameEnum from cpl_cli.configuration.version_settings_name_enum import VersionSettingsNameEnum
@ -45,51 +46,64 @@ class Application(ApplicationABC):
return return
if len(args) == 1: if len(args) == 1:
suffix = f'.{args[0]}' suffix = args[0]
try: try:
branch = self._git_service.get_active_branch_name() branch = self._git_service.get_active_branch_name()
Console.write_line(f'Found branch: {branch}') Console.write_line(f'Found branch: {branch}')
except Exception as e: except Exception as e:
Console.error('Branch could not be found', traceback.format_exc()) Console.error('Branch not found', traceback.format_exc())
return return
try: try:
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)
version[VersionSettingsNameEnum.major.value] = ps.version.major
version[VersionSettingsNameEnum.minor.value] = ps.version.minor
version[VersionSettingsNameEnum.micro.value] = f'dev{branch.split("#")[1]}'
else:
version[VersionSettingsNameEnum.major.value] = branch.split('.')[0] version[VersionSettingsNameEnum.major.value] = branch.split('.')[0]
version[VersionSettingsNameEnum.minor.value] = branch.split('.')[1] version[VersionSettingsNameEnum.minor.value] = branch.split('.')[1]
if len(branch.split('.')) == 2: if len(branch.split('.')) == 2:
version[VersionSettingsNameEnum.micro.value] = f'0{suffix}' if suffix == '':
suffix = '0'
version[VersionSettingsNameEnum.micro.value] = f'{suffix}'
else: else:
branch_version = branch.split(".")[2] if not suffix.startswith('.') and suffix != '':
if '-#' in branch_version: suffix = f'.{suffix}'
branch_version = branch_version.split('-#')[0] version[VersionSettingsNameEnum.micro.value] = f'{branch.split(".")[2]}{suffix}'
version[VersionSettingsNameEnum.micro.value] = f'{branch_version}{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
diff_paths = [] diff_paths = []
for file in self._git_service.get_diff_files(): for file in self._git_service.get_diff_files():
if file.startswith('tools'):
continue
if '/' in file: if '/' in file:
diff_paths.append(file.split('/')[1]) file = file.split('/')[1]
else: else:
diff_paths.append(os.path.basename(os.path.dirname(file))) file = os.path.basename(os.path.dirname(file))
if file in diff_paths:
continue
diff_paths.append(file)
try: try:
skipped = [] skipped = []
for project in self._workspace.projects: for project in self._workspace.projects:
if project not in diff_paths and String.convert_to_snake_case(project) not in diff_paths and not force: if project not in diff_paths and String.convert_to_snake_case(project) not in diff_paths and not force:
Console.write_line(f'Skipping {project} due to missing changes') # Console.write_line(f'Skipping {project} due to missing changes')
skipped.append(project) skipped.append(project)
continue continue
Console.write_line(f'Set dependencies {self._version_pipe.transform(version)} for {project}') Console.write_line(f'Set dependencies {self._version_pipe.transform(version)} for {project}')
self._version_setter.set_dependencies(self._workspace.projects[project], version, 'Dependencies', skipped=skipped) 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) self._version_setter.set_dependencies(self._workspace.projects[project], version, 'DevDependencies', skipped=skipped)
if not project.startswith('cpl') and not project.startswith('unittest'):
Console.write_line(f'Skipping {project}')
continue
Console.write_line(f'Set version {self._version_pipe.transform(version)} 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)

View File

@ -1,6 +1,7 @@
from git import Repo, DiffIndex import os
from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.environment import ApplicationEnvironmentABC
from git import Repo
class GitService: class GitService:

View File

@ -3,7 +3,7 @@
"Name": "set-version", "Name": "set-version",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "7", "Minor": "12",
"Micro": "0" "Micro": "0"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
@ -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.10.0", "cpl-core>=2022.12.0",
"gitpython==3.1.27" "gitpython==3.1.27"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",

View File

@ -3,7 +3,7 @@
"Name": "unittests", "Name": "unittests",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "0" "Micro": "0"
}, },
"Author": "", "Author": "",
@ -16,7 +16,7 @@
"LicenseName": "", "LicenseName": "",
"LicenseDescription": "", "LicenseDescription": "",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.10.0" "cpl-core>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},

View File

@ -3,7 +3,7 @@
"Name": "unittest_cli", "Name": "unittest_cli",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "0" "Micro": "0"
}, },
"Author": "", "Author": "",
@ -16,8 +16,8 @@
"LicenseName": "", "LicenseName": "",
"LicenseDescription": "", "LicenseDescription": "",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.10.0", "cpl-core>=2022.12.0",
"cpl-cli>=2022.10.0" "cpl-cli>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},

View File

@ -3,7 +3,7 @@
"Name": "unittest_core", "Name": "unittest_core",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "0" "Micro": "0"
}, },
"Author": "", "Author": "",
@ -16,7 +16,7 @@
"LicenseName": "", "LicenseName": "",
"LicenseDescription": "", "LicenseDescription": "",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.10.0" "cpl-core>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},

View File

@ -3,7 +3,7 @@
"Name": "unittest_query", "Name": "unittest_query",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "0" "Micro": "0"
}, },
"Author": "", "Author": "",
@ -16,8 +16,8 @@
"LicenseName": "", "LicenseName": "",
"LicenseDescription": "", "LicenseDescription": "",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.10.0", "cpl-core>=2022.12.0",
"cpl-query>=2022.10.0" "cpl-query>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},

View File

@ -3,7 +3,7 @@
"Name": "unittest_shared", "Name": "unittest_shared",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "0" "Micro": "0"
}, },
"Author": "", "Author": "",
@ -16,7 +16,7 @@
"LicenseName": "", "LicenseName": "",
"LicenseDescription": "", "LicenseDescription": "",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.10.0" "cpl-core>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},

View File

@ -3,7 +3,7 @@
"Name": "unittests_translation", "Name": "unittests_translation",
"Version": { "Version": {
"Major": "2022", "Major": "2022",
"Minor": "10", "Minor": "12",
"Micro": "0" "Micro": "0"
}, },
"Author": "", "Author": "",
@ -16,11 +16,11 @@
"LicenseName": "", "LicenseName": "",
"LicenseDescription": "", "LicenseDescription": "",
"Dependencies": [ "Dependencies": [
"cpl-core>=2022.10.0", "cpl-core>=2022.12.0",
"cpl-translation>=2022.10.0" "cpl-translation>=2022.12.0"
], ],
"DevDependencies": [ "DevDependencies": [
"cpl-cli>=2022.10.0" "cpl-cli>=2022.12.0"
], ],
"PythonVersion": ">=3.10.4", "PythonVersion": ">=3.10.4",
"PythonPath": {}, "PythonPath": {},