Fix CI: Remove whitespaces, add newlines

This commit is contained in:
erik 2023-04-20 16:50:31 +02:00
parent 83a7c7ad7d
commit 580bf81c15
19 changed files with 40 additions and 43 deletions

View file

@ -1,2 +1,2 @@
from .image_build_service import ImageBuildService from .image_build_service import ImageBuildService
from .release_mixin_services import TagAndPushReleaseService, PrepareReleaseService from .release_mixin_services import TagAndPushReleaseService, PrepareReleaseService

View file

@ -21,7 +21,7 @@ def get_devops_build(project):
@deprecation.deprecated(deprecated_in="3.2") @deprecation.deprecated(deprecated_in="3.2")
# TODO: Remove from here! # TODO: Remove from here! # pylint: disable=W0511
def get_tag_from_latest_commit(): def get_tag_from_latest_commit():
try: try:
value = run( value = run(

View file

@ -1,4 +1,4 @@
from .common import Validateable, DnsRecord, Devops from .common import Validateable, DnsRecord, Devops
from .image import Image from .image import Image
from .c4k import C4k from .c4k import C4k
from .release import Release, ReleaseConfig, ReleaseType, Version, EnvironmentKeys from .release import Release, ReleaseConfig, ReleaseType, Version, EnvironmentKeys

View file

@ -69,13 +69,13 @@ class ReleaseConfig(Validateable):
main_branch: str, main_branch: str,
config_file: str, config_file: str,
devops: Devops, devops: Devops,
release_version: Optional[str | None] = None, release_version: Optional[str | None] = None,
bump_version: Optional[str | None] = None bump_version: Optional[str | None] = None
): ):
self.main_branch = main_branch self.main_branch = main_branch
self.config_file = config_file self.config_file = config_file
self.release_version = release_version self.release_version = release_version
self.bump_version = bump_version self.bump_version = bump_version
self.devops = devops self.devops = devops
class Release(): class Release():

View file

@ -1 +1 @@
from .infrastructure import FileApi, ImageApi, ResourceApi, ExecutionApi, ProjectRepository from .infrastructure import FileApi, ImageApi, ResourceApi, ExecutionApi, ProjectRepository

View file

@ -32,7 +32,7 @@ class ProjectRepository:
def get_release(self, project) -> ReleaseConfig: def get_release(self, project) -> ReleaseConfig:
return project.get_property("release_build") return project.get_property("release_build")
def set_release(self, project, build: ReleaseConfig): def set_release(self, project, build: ReleaseConfig):
project.set_property("release_build", build) project.set_property("release_build", build)

View file

@ -1,2 +1,2 @@
from .infrastructure_api import FileHandler, SystemApi, EnvironmentApi, GitApi, JsonFileHandler, GradleFileHandler, PythonFileHandler, ClojureFileHandler from .infrastructure_api import FileHandler, SystemApi, EnvironmentApi, GitApi, JsonFileHandler, GradleFileHandler, PythonFileHandler, ClojureFileHandler
from .repo import VersionRepository, ReleaseRepository, ReleaseTypeRepository from .repo import VersionRepository, ReleaseRepository, ReleaseTypeRepository

View file

@ -197,11 +197,11 @@ class SystemApi():
stderr=sub.PIPE, stderr=sub.PIPE,
text=True, text=True,
encoding="UTF-8") encoding="UTF-8")
if stream.stdout is not None: if stream.stdout is not None:
self.stdout = stream.stdout.readlines() self.stdout = stream.stdout.readlines()
else: else:
self.stdout = None self.stdout = None
if stream.stderr is not None: if stream.stderr is not None:
self.stderr = stream.stderr.readlines() self.stderr = stream.stderr.readlines()
else: else:
self.stderr = None self.stderr = None
@ -246,7 +246,7 @@ class GitApi():
def init(self, default_branch: str = "main"): def init(self, default_branch: str = "main"):
self.system_api.run_checked('git', 'init', '-b', default_branch) self.system_api.run_checked('git', 'init', '-b', default_branch)
def set_user_config(self, email: str, name: str): def set_user_config(self, email: str, name: str):
self.system_api.run_checked('git', 'config', 'user.email', email) self.system_api.run_checked('git', 'config', 'user.email', email)
self.system_api.run_checked('git', 'config', 'user.name', name) self.system_api.run_checked('git', 'config', 'user.name', name)
@ -279,6 +279,6 @@ class EnvironmentApi():
def get(self, key): def get(self, key):
return self.environ.get(key) return self.environ.get(key)
def set(self, key, value): def set(self, key, value):
self.environ[key] = value self.environ[key] = value

View file

@ -8,28 +8,28 @@ class VersionRepository():
def __init__(self, file): def __init__(self, file):
self.file = file self.file = file
self.file_handler = None self.file_handler = None
def load_file(self): def load_file(self):
self.file_handler = FileHandler.from_file_path(self.file) self.file_handler = FileHandler.from_file_path(self.file)
return self.file_handler return self.file_handler
def write_file(self, version_string): def write_file(self, version_string):
if self.file_handler is None: if self.file_handler is None:
raise Exception('Version was not created by load_file method.') raise Exception('Version was not created by load_file method.')
else: else:
self.file_handler.write(version_string) self.file_handler.write(version_string)
def parse_file(self): def parse_file(self):
version_list, is_snapshot = self.file_handler.parse() version_list, is_snapshot = self.file_handler.parse()
return version_list, is_snapshot return version_list, is_snapshot
def get_version(self) -> Version: def get_version(self) -> Version:
self.file_handler = self.load_file() self.file_handler = self.load_file()
version_list, is_snapshot = self.parse_file() version_list, is_snapshot = self.parse_file()
version = Version(self.file, version_list) version = Version(self.file, version_list)
version.is_snapshot = is_snapshot version.is_snapshot = is_snapshot
return version return version
class ReleaseTypeRepository(): class ReleaseTypeRepository():
@ -50,7 +50,7 @@ class ReleaseTypeRepository():
releaseTypeRepo = cls(environment_api=environment_api) releaseTypeRepo = cls(environment_api=environment_api)
releaseTypeRepo.get_from_env = True releaseTypeRepo.get_from_env = True
return releaseTypeRepo return releaseTypeRepo
def __get_release_type_git(self) -> ReleaseType | None: def __get_release_type_git(self) -> ReleaseType | None:
latest_commit = self.git_api.get_latest_commit() latest_commit = self.git_api.get_latest_commit()
@ -87,7 +87,7 @@ class ReleaseTypeRepository():
elif self.get_from_env: elif self.get_from_env:
return self.__get_release_type_environment() return self.__get_release_type_environment()
else: else:
raise ValueError('No valid api passed to ReleaseTypeRepository') raise ValueError('No valid api passed to ReleaseTypeRepository')
class ReleaseRepository(): class ReleaseRepository():
def __init__(self, version_repository: VersionRepository, release_type_repository: ReleaseTypeRepository, main_branch: str): def __init__(self, version_repository: VersionRepository, release_type_repository: ReleaseTypeRepository, main_branch: str):

View file

@ -1,2 +1,2 @@
from .mock_infrastructure import MockReleaseRepository, MockReleaseTypeRepository, MockVersionRepository from .mock_infrastructure import MockReleaseRepository, MockReleaseTypeRepository, MockVersionRepository
from .mock_infrastructure_api import MockGitApi from .mock_infrastructure_api import MockGitApi

View file

@ -6,8 +6,8 @@ class Helper():
def __init__(self, file_name = 'config.json'): def __init__(self, file_name = 'config.json'):
self.TEST_FILE_NAME = file_name self.TEST_FILE_NAME = file_name
self.TEST_FILE_ROOT = Path('src/test/resources/') self.TEST_FILE_ROOT = Path('src/test/resources/')
self.TEST_FILE_PATH = self.TEST_FILE_ROOT / self.TEST_FILE_NAME self.TEST_FILE_PATH = self.TEST_FILE_ROOT / self.TEST_FILE_NAME
def copy_files(self, source: Path, target: Path): def copy_files(self, source: Path, target: Path):
api = SystemApi() api = SystemApi()
api.run_checked('cp', source, target) api.run_checked('cp', source, target)

View file

@ -39,4 +39,3 @@ class MockRelease():
def is_valid(self, main_branch): def is_valid(self, main_branch):
return len(self.validate(main_branch)) < 1 return len(self.validate(main_branch)) < 1

View file

@ -9,14 +9,14 @@ class MockVersionRepository():
self.file = None self.file = None
self.file_handler = None self.file_handler = None
self.write_file_count = 0 self.write_file_count = 0
def load_file(self): def load_file(self):
pass pass
def write_file(self, version_string): def write_file(self, version_string):
self.write_file_count += 1 self.write_file_count += 1
pass pass
def parse_file(self): def parse_file(self):
pass pass
@ -39,4 +39,4 @@ class MockReleaseRepository():
def get_release(self) -> MockRelease: def get_release(self) -> MockRelease:
self.get_release_count += 1 self.get_release_count += 1
return MockRelease(self.release_type_repository.get_release_type(), self.version_repository.get_version(), self.main_branch) return MockRelease(self.release_type_repository.get_release_type(), self.version_repository.get_version(), self.main_branch)

View file

@ -17,7 +17,7 @@ class MockGitApi():
self.system_api = MockSystemApi() self.system_api = MockSystemApi()
self.get_latest_commit_count = 0 self.get_latest_commit_count = 0
self.commit_string = commit_string self.commit_string = commit_string
self.tag_annotated_count = 0 self.tag_annotated_count = 0
self.add_file_count = 0 self.add_file_count = 0
self.commit_count = 0 self.commit_count = 0
self.push_count = 0 self.push_count = 0
@ -30,9 +30,9 @@ class MockGitApi():
return self.commit_string return self.commit_string
def tag_annotated(self, annotation: str, message: str, count: int): def tag_annotated(self, annotation: str, message: str, count: int):
self.tag_annotated_count += 1 self.tag_annotated_count += 1
return " " return " "
def tag_annotated_second_last(self, annotation: str, message: str): def tag_annotated_second_last(self, annotation: str, message: str):
self.tag_annotated(annotation, message, 1) self.tag_annotated(annotation, message, 1)
return " " return " "
@ -70,4 +70,4 @@ class MockEnvironmentApi():
return self.environ.get(name) return self.environ.get(name)
def set(self, name, value): def set(self, name, value):
self.environ[name] = value self.environ[name] = value

View file

@ -15,7 +15,7 @@ def test_version_repository(tmp_path):
def test_release_repository(tmp_path): def test_release_repository(tmp_path):
# init # init
th = Helper() th = Helper()
th.copy_files( th.TEST_FILE_PATH, tmp_path) th.copy_files( th.TEST_FILE_PATH, tmp_path)
version_repo = VersionRepository(th.TEST_FILE_PATH) version_repo = VersionRepository(th.TEST_FILE_PATH)
@ -83,4 +83,3 @@ def test_release_type_repository_env():
release_type = sut.get_release_type() release_type = sut.get_release_type()
except: except:
assert release_type == None assert release_type == None

View file

@ -11,13 +11,13 @@ def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch):
monkeypatch.chdir(tmp_path) monkeypatch.chdir(tmp_path)
def test_environment_api(): def test_environment_api():
# init # init
env_api = EnvironmentApi() env_api = EnvironmentApi()
key = "TEST_ENV_KEY" key = "TEST_ENV_KEY"
value = "data" value = "data"
env_api.set(key, value) env_api.set(key, value)
#test #test
assert env_api.get(key) == value assert env_api.get(key) == value
def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch): def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
@ -26,7 +26,7 @@ def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
th.copy_files(th.TEST_FILE_PATH, tmp_path) th.copy_files(th.TEST_FILE_PATH, tmp_path)
# change the context of the script execution to tmp_path # change the context of the script execution to tmp_path
change_test_dir(tmp_path, monkeypatch) change_test_dir(tmp_path, monkeypatch)
git_api = GitApi() git_api = GitApi()
git_api.init() git_api.init()

View file

@ -25,7 +25,7 @@ def initialize_with_object(project, CONFIG_FILE):
devops = Devops(STAGE, PROJECT_ROOT_PATH, MODULE, "release_test", BUILD_DIR_NAME) devops = Devops(STAGE, PROJECT_ROOT_PATH, MODULE, "release_test", BUILD_DIR_NAME)
release_config = ReleaseConfig(MAIN_BRANCH, CONFIG_FILE, devops) release_config = ReleaseConfig(MAIN_BRANCH, CONFIG_FILE, devops)
build = MyBuild(project, release_config=release_config) build = MyBuild(project, release_config=release_config)
return build return build
def test_release_mixin_git(tmp_path: Path, monkeypatch: pt.MonkeyPatch): def test_release_mixin_git(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
@ -34,7 +34,7 @@ def test_release_mixin_git(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
th.copy_files(th.TEST_FILE_PATH, tmp_path) th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
change_test_dir(tmp_path, monkeypatch) change_test_dir(tmp_path, monkeypatch)
project = Project(tmp_path) project = Project(tmp_path)
git_api = GitApi() git_api = GitApi()
@ -57,7 +57,7 @@ def test_release_mixin_environment(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
th.copy_files(th.TEST_FILE_PATH, tmp_path) th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
change_test_dir(tmp_path, monkeypatch) change_test_dir(tmp_path, monkeypatch)
project = Project(tmp_path) project = Project(tmp_path)
git_api = GitApi() git_api = GitApi()
@ -68,7 +68,7 @@ def test_release_mixin_environment(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
environment_api = EnvironmentApi() environment_api = EnvironmentApi()
environment_api.set("DDADEVOPS_RELEASE_TYPE", "MAJOR") environment_api.set("DDADEVOPS_RELEASE_TYPE", "MAJOR")
build = initialize_with_object(project, th.TEST_FILE_PATH) build = initialize_with_object(project, th.TEST_FILE_PATH)
build.prepare_release() build.prepare_release()
release_version = build.prepare_release_service.release_repo.version_repository.get_version() release_version = build.prepare_release_service.release_repo.version_repository.get_version()

View file

@ -25,7 +25,7 @@ def test_prepare_release_service():
assert prepare_release_service.release_repo.version_repository.write_file_count == 2 assert prepare_release_service.release_repo.version_repository.write_file_count == 2
assert prepare_release_service.git_api.add_file_count == 2 assert prepare_release_service.git_api.add_file_count == 2
assert prepare_release_service.git_api.commit_count == 2 assert prepare_release_service.git_api.commit_count == 2
def test_tag_and_push_release_service(): def test_tag_and_push_release_service():
# init # init
mock_release_repo = MockReleaseRepository(MockVersionRepository(), MockReleaseTypeRepository(MockGitApi()), 'main') mock_release_repo = MockReleaseRepository(MockVersionRepository(), MockReleaseTypeRepository(MockGitApi()), 'main')

View file

@ -28,7 +28,7 @@ def test_c4k_mixin(tmp_path):
add_c4k_mixin_config(project_config, config, auth, grafana_cloud_user='user', grafana_cloud_password='password') add_c4k_mixin_config(project_config, config, auth, grafana_cloud_user='user', grafana_cloud_password='password')
assert project_config.get('C4kMixin') is not None assert project_config.get('C4kMixin') is not None
mixin = MyC4kMixin(project, project_config) mixin = MyC4kMixin(project, project_config)
mixin.initialize_build_dir() mixin.initialize_build_dir()
assert mixin.build_path() == f'{tmp_path_str}/{build_dir}/{project_name}/{module_name}' assert mixin.build_path() == f'{tmp_path_str}/{build_dir}/{project_name}/{module_name}'
@ -44,4 +44,3 @@ def test_c4k_mixin(tmp_path):
mixin.write_c4k_auth() mixin.write_c4k_auth()
assert os.path.exists(f'{mixin.build_path()}/out_c4k_auth.yaml') assert os.path.exists(f'{mixin.build_path()}/out_c4k_auth.yaml')