Compare commits

...

5 commits

Author SHA1 Message Date
1e2593e358 No settings in repo 2023-02-22 14:12:54 +01:00
0d0bde4b9e Remove whitespaces 2023-02-22 14:12:03 +01:00
7d7347653e Update release_mixin methods 2023-02-22 14:11:39 +01:00
a07c23434e Implement tag_annotated and bugfix 2023-02-22 14:10:53 +01:00
03f8507968 Setup build.py 2023-02-22 14:10:19 +01:00
6 changed files with 81 additions and 66 deletions

5
.gitignore vendored
View file

@ -24,4 +24,7 @@ go.work
__pycache__
.clj-kondo/
.lsp/
.lsp/
# vs code settings
.vscode

View file

@ -4,40 +4,42 @@ from version import *
from release_mixin import *
CONFIG_FILE = ''
COMMIT_ID = ''
MAIN_BRANCH = 'main'
class MyBuild(ReleaseMixin):
pass
def main():
init_project()
@init
def initialize(project):
project.build_depends_on('ddadevops>=3.1.2')
if COMMIT_ID == '':
COMMIT_ID = 'HEAD'
config = create_release_mixin_config(CONFIG_FILE, COMMIT_ID)
build = MyBuild(project, config)
release_version, bump_version = build.init()
build.prepare()
build.tag_and_push()
config = create_release_mixin_config(CONFIG_FILE, MAIN_BRANCH)
build = MyBuild(project, config)
build.init()
@task
def prepare(project):
def release(project):
build = get_devops_build(project)
build.prepare_release()
@task
def tag_and_push(project):
build = get_devops_build(project)
build.tag_and_push()
prepare_release(build)
tag_and_push_release(build)
prepare_version_bump(build)
tag_and_push_version_bump(build)
def prepare_release(build):
release_version = build.release_version
build.prepare(release_version)
def tag_and_push_release(build):
release_version = build.release_version
build.tag_and_push(release_version)
def prepare_version_bump(build):
bump_version = build.bump_version
build.prepare(bump_version)
def tag_and_push_version_bump(build):
bump_version = build.bump_version
build.tag_and_push(bump_version)

View file

@ -17,7 +17,8 @@ class GitRepository():
return inst
def get_latest_commit(self):
self.latest_commit = self.system_repository.run_checked('git', 'log', '--oneline', '--format="%s %b"', '-n' + '1')
self.system_repository.run_checked('git', 'log', '--oneline', '--format="%s %b"', '-n' + '1')
self.latest_commit = self.system_repository.stdout
def get_release_type_from_latest_commit(self):
if self.latest_commit is None:
@ -34,6 +35,9 @@ class GitRepository():
else:
return None
def tag_annotated(self, annotation: str, message: str):
self.system_repository.run_checked('git', 'tag', '-a', annotation, '-m', message)
def get_current_branch(self):
self.system_repository.run_checked('git', 'branch', '--show-current')
@ -48,4 +52,3 @@ class GitRepository():
def checkout(self, branch: str):
self.system_repository.run_checked('git', 'checkout', branch)

View file

@ -6,12 +6,19 @@ from version_repository import VersionRepository
from services import InitReleaseService, PrepareReleaseService, TagAndPushReleaseService
from git_repository import GitRepository
def create_release_mixin_config(config, release_type, config_file, main_branch):
config.update({'ReleaseMixin':
{'main_branch': main_branch,
'file': config_file}})
def create_release_mixin_config(config_file, main_branch) -> dict:
config = {}
config.update(
{'ReleaseMixin':
{'main_branch': main_branch,
'file': config_file}})
return config
def add_versions(config, release_version, bump_version) -> dict:
config['ReleaseMixin'].update(
{'release_version': release_version,
'bump_version': bump_version})
return config
class ReleaseMixin(DevopsBuild):
@ -21,40 +28,40 @@ class ReleaseMixin(DevopsBuild):
self.file = release_mixin_config['file']
self.main_branch = release_mixin_config['main_branch']
self.version_repo = VersionRepository(self.file)
self.release_version = None
self.bump_version = None
def init(self): # returns versions
def init(self):
init_service = InitReleaseService(self.version_repo)
release_version = init_service.create_release_version()
bump_version = release_version.create_bump_version()
return release_version, bump_version
self.release_version = init_service.create_release_version()
self.bump_version = self.release_version.create_bump_version()
return self.release_version, self.bump_version
def prepare(self, release_version: Version, bump_version: Version): # writes into files, add. commit
def prepare(self, version):
git_repository = GitRepository()
if self.main_branch not in git_repository.get_current_branch():
raise Exception('Trying to release while not on main branch')
self.version_repo.write_file(release_version.get_version_string())
git_repository.add_file(self.file)
git_repository.commit(f'Release {release_version.get_version_string()}')
self.version_repo.write_file(bump_version.get_version_string())
git_repository.add_file(self.file)
git_repository.commit(f'Version bump {bump_version.get_version_string()}')
self.version_repo.write_file(version.get_version_string())
git_repository.add_file(self.file)
match version.release_type:
case None:
raise Exception('Release type not set but trying to commit.')
case ReleaseType.BUMP:
git_repository.commit(f'Version bump')
case _:
git_repository.commit(f'Release {version.get_version_string()}')
def tag_and_push(): # correct tag and do push
pass
def tag_and_push(self, version):
git_repository = GitRepository()
match version.release_type:
case None:
raise Exception('Release type not set but trying to tag and push.')
case ReleaseType.BUMP:
annotation = 'v' + version.get_version_string()
message = 'Version bump'
case _:
annotation = 'v' + self.release_version.get_version_string()
message = 'Release' + annotation
git_repository.tag_annotated(annotation, message)
git_repository.push()

View file

@ -5,7 +5,7 @@ class SystemRepository():
def __init__(self):
self.stdout = [""]
self.stderr = [""]
def run(self, *args):
stream = sub.Popen(args,
stdout=sub.PIPE,

View file

@ -5,15 +5,15 @@ import os
# getting the name of the directory
# where the this file is present.
current = os.path.dirname(os.path.realpath(__file__))
# Getting the parent directory name
# where the current directory is present.
parent = os.path.dirname(current)
# adding the parent directory to
# the sys.path.
sys.path.append(parent)
# now we can import the module in the parent
# directory.