Compare commits
8 commits
8855a2c6b6
...
874106e1d4
Author | SHA1 | Date | |
---|---|---|---|
874106e1d4 | |||
63d3823d87 | |||
8eb510d034 | |||
99877b3fbf | |||
0d36a8a66a | |||
9dc32ac92f | |||
455585f78c | |||
5700b42098 |
7 changed files with 82 additions and 72 deletions
|
@ -1,11 +1,6 @@
|
|||
from enum import Enum
|
||||
from pathlib import Path
|
||||
|
||||
class Config():
|
||||
def __init__(self, main_branch):
|
||||
pass
|
||||
|
||||
|
||||
class ReleaseType(Enum):
|
||||
MAJOR = 0
|
||||
MINOR = 1
|
||||
|
@ -13,7 +8,6 @@ class ReleaseType(Enum):
|
|||
SNAPSHOT = 3
|
||||
BUMP = None
|
||||
|
||||
|
||||
class Version():
|
||||
|
||||
def __init__(self, id: Path, version_list: list):
|
||||
|
@ -60,7 +54,6 @@ class Version():
|
|||
bump_version.increment(ReleaseType.BUMP)
|
||||
return bump_version
|
||||
|
||||
|
||||
class Release():
|
||||
def __init__(self, release_type: ReleaseType, version: Version, current_branch: str):
|
||||
self.release_type = release_type
|
||||
|
@ -71,7 +64,7 @@ class Release():
|
|||
return self.version.create_release_version(self.release_type)
|
||||
|
||||
def bump_version(self):
|
||||
return self.version.create_bump_version()
|
||||
return self.release_version().create_bump_version()
|
||||
|
||||
def validate(self, main_branch):
|
||||
result = []
|
||||
|
|
|
@ -203,11 +203,6 @@ class GitApi():
|
|||
output = self.get_latest_n_commits(1)
|
||||
return " ".join(output)
|
||||
|
||||
def tag_annotated(self, annotation: str, message: str):
|
||||
self.system_repository.run_checked(
|
||||
'git', 'tag', '-a', annotation, '-m', message)
|
||||
return self.system_repository.stdout
|
||||
|
||||
def tag_annotated(self, annotation: str, message: str, count: int):
|
||||
self.system_repository.run_checked(
|
||||
'git', 'tag', '-a', annotation, '-m', message, f'HEAD~{count}')
|
||||
|
@ -217,6 +212,9 @@ class GitApi():
|
|||
self.system_repository.run_checked('git', 'branch', '--show-current')
|
||||
return ''.join(self.system_repository.stdout).rstrip()
|
||||
|
||||
def init(self):
|
||||
self.system_repository.run_checked('git', 'init')
|
||||
|
||||
def add_file(self, file_path: Path):
|
||||
self.system_repository.run_checked('git', 'add', file_path)
|
||||
return self.system_repository.stdout
|
||||
|
|
13
services.py
13
services.py
|
@ -13,17 +13,16 @@ class PrepareReleaseService():
|
|||
|
||||
self.release_repo.version_repository.write_file(version.get_version_string())
|
||||
self.git_api.add_file(self.release_repo.version_repository.file)
|
||||
self.git_api.commit(commit_message)
|
||||
self.git_api.commit(commit_message)
|
||||
|
||||
def write_and_commit_release(self):
|
||||
self.__write_and_commit_version(self.release.release_version(), commit_message=f'Release {self.release.release_version().get_version_string()}')
|
||||
self.__write_and_commit_version(self.release.release_version(), commit_message=f'Release v{self.release.release_version().get_version_string()}')
|
||||
|
||||
def write_and_commit_bump(self):
|
||||
self.__write_and_commit_version(self.release.bump_version(), commit_message=f'Version bump')
|
||||
|
||||
def write_and_commit_bump(self):
|
||||
self.__write_and_commit_version(self.release.bump_version(), commit_message='Version bump')
|
||||
|
||||
class TagAndPushReleaseService():
|
||||
|
||||
|
||||
def __init__(self, git_api: GitApi):
|
||||
self.git_api = git_api
|
||||
|
||||
|
@ -32,5 +31,3 @@ class TagAndPushReleaseService():
|
|||
message = 'Release ' + annotation
|
||||
self.git_api.tag_annotated(annotation, message, 1)
|
||||
# self.git_api.push()
|
||||
|
||||
|
||||
|
|
|
@ -17,12 +17,10 @@ sys.path.append(parent)
|
|||
# now we can import the module in the parent
|
||||
# directory.
|
||||
|
||||
from domain import Version, ReleaseType
|
||||
from infrastructure import VersionRepository
|
||||
from domain import Version, ReleaseType, Release
|
||||
|
||||
def test_version(tmp_path):
|
||||
def test_version(tmp_path: Path):
|
||||
version = Version(tmp_path, [1, 2, 3])
|
||||
|
||||
version.increment(ReleaseType.SNAPSHOT)
|
||||
assert version.get_version_string() == "1.2.3-SNAPSHOT"
|
||||
assert version.version_list == [1, 2, 3]
|
||||
|
@ -51,3 +49,13 @@ def test_version(tmp_path):
|
|||
assert version.get_version_string() == "2.0.0"
|
||||
assert version.version_list == [2, 0, 0]
|
||||
assert not version.is_snapshot
|
||||
|
||||
def test_release(tmp_path):
|
||||
version = Version(tmp_path, [1, 2, 3])
|
||||
release = Release(ReleaseType.MINOR, version, "main")
|
||||
|
||||
release_version = release.release_version()
|
||||
assert release_version.get_version_string() in '1.3.0'
|
||||
|
||||
bump_version = release.bump_version()
|
||||
assert bump_version.get_version_string() in "1.3.1-SNAPSHOT"
|
||||
|
|
|
@ -21,7 +21,7 @@ from domain import ReleaseType, Release
|
|||
from infrastructure import ReleaseTypeRepository, VersionRepository, ReleaseRepository
|
||||
from infrastructure_api import GitApi
|
||||
|
||||
class TestGitApi(GitApi):
|
||||
class MyGitApi(GitApi):
|
||||
def __init__(self, commit_string):
|
||||
self.commit_string = commit_string
|
||||
|
||||
|
@ -115,33 +115,33 @@ def test_release_repository(tmp_path):
|
|||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
sut = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(TestGitApi('MINOR test')), 'main')
|
||||
sut = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(MyGitApi('MINOR test')), 'main')
|
||||
release = sut.get_release()
|
||||
|
||||
assert release is not None
|
||||
|
||||
|
||||
def test_release_type_repository():
|
||||
sut = ReleaseTypeRepository(TestGitApi('MINOR test'))
|
||||
sut = ReleaseTypeRepository(MyGitApi('MINOR test'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type is ReleaseType.MINOR
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('MINOR bla'))
|
||||
sut = ReleaseTypeRepository(MyGitApi('MINOR bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type is ReleaseType.MINOR
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('Major bla'))
|
||||
sut = ReleaseTypeRepository(MyGitApi('Major bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type == ReleaseType.MAJOR
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('PATCH bla'))
|
||||
sut = ReleaseTypeRepository(MyGitApi('PATCH bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type == ReleaseType.PATCH
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('SNAPSHOT bla'))
|
||||
sut = ReleaseTypeRepository(MyGitApi('SNAPSHOT bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type == ReleaseType.SNAPSHOT
|
||||
|
||||
sut = ReleaseTypeRepository(TestGitApi('bla'))
|
||||
sut = ReleaseTypeRepository(MyGitApi('bla'))
|
||||
release_type = sut.get_release_type()
|
||||
assert release_type == None
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
import os
|
||||
import pytest as pt
|
||||
from pathlib import Path
|
||||
from ddadevops import *
|
||||
|
||||
|
@ -40,29 +41,29 @@ def initialize(project, CONFIG_FILE):
|
|||
build = MyBuild(project, config)
|
||||
return build
|
||||
|
||||
def test_release_mixin(tmp_path):
|
||||
|
||||
#init
|
||||
with open(f'test/resources/config.json', 'r') as json_file:
|
||||
contents = json_file.read()
|
||||
|
||||
CONFIG_FILE = tmp_path / "config.json"
|
||||
CONFIG_FILE.write_text(contents)
|
||||
|
||||
base_dir = "."
|
||||
project = Project(base_dir)
|
||||
|
||||
# init
|
||||
build = initialize(project, CONFIG_FILE)
|
||||
build.commit_string = "MAJOR bla"
|
||||
build.init_release()
|
||||
release_version = build.release_version
|
||||
|
||||
# test
|
||||
assert "124.0.0" in release_version.get_version_string()
|
||||
|
||||
# init
|
||||
bump_version = build.bump_version
|
||||
|
||||
# test
|
||||
assert "124.0.1-SNAPSHOT" in bump_version.get_version_string()
|
||||
#def test_release_mixin(tmp_path):
|
||||
#
|
||||
# #init
|
||||
# with open(f'test/resources/config.json', 'r') as json_file:
|
||||
# contents = json_file.read()
|
||||
#
|
||||
# CONFIG_FILE = tmp_path / "config.json"
|
||||
# CONFIG_FILE.write_text(contents)
|
||||
#
|
||||
# base_dir = "."
|
||||
# project = Project(base_dir)
|
||||
#
|
||||
# # init
|
||||
# build = initialize(project, CONFIG_FILE)
|
||||
# build.commit_string = "MAJOR bla"
|
||||
# build.init_release()
|
||||
# release_version = build.release_version
|
||||
#
|
||||
# # test
|
||||
# assert "124.0.0" in release_version.get_version_string()
|
||||
#
|
||||
# # init
|
||||
# bump_version = build.bump_version
|
||||
#
|
||||
# # test
|
||||
# assert "124.0.1-SNAPSHOT" in bump_version.get_version_string()
|
|
@ -1,3 +1,4 @@
|
|||
import pytest as pt
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import os
|
||||
|
@ -5,38 +6,50 @@ 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.
|
||||
|
||||
from services import InitReleaseService
|
||||
from services import PrepareReleaseService
|
||||
from domain import ReleaseType
|
||||
from infrastructure import VersionRepository, ReleaseRepository, ReleaseTypeRepository
|
||||
from infrastructure_api import GitApi
|
||||
|
||||
def test_init_release_service(tmp_path):
|
||||
def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
def test_prepare_release_service(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||
# init
|
||||
file_name = 'config.json'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
with open(f'test/resources/{file_name}', 'r') as json_file:
|
||||
contents = json_file.read()
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
change_test_dir(tmp_path, monkeypatch) # change the context of the script execution to tmp_path
|
||||
|
||||
git_api = GitApi()
|
||||
git_api.init()
|
||||
git_api.add_file(file_name)
|
||||
git_api.commit("MINOR release")
|
||||
|
||||
repo = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(GitApi()), 'main')
|
||||
release_service = InitReleaseService(repo)
|
||||
version = release_service.get_version().create_release_version(ReleaseType.MINOR)
|
||||
prepare_release_service = PrepareReleaseService(repo)
|
||||
prepare_release_service.main_branch = "main"
|
||||
prepare_release_service.write_and_commit_release()
|
||||
|
||||
assert "123.124.0" in version.get_version_string()
|
||||
latest_commit = git_api.get_latest_commit()
|
||||
|
||||
version = version.create_bump_version()
|
||||
assert '"Release v123.124.0 "\n' in latest_commit
|
||||
|
||||
assert "123.124.1-SNAPSHOT" in version.get_version_string()
|
||||
prepare_release_service.write_and_commit_bump()
|
||||
latest_commit = git_api.get_latest_commit()
|
||||
|
||||
assert '"Version bump "\n' in latest_commit
|
||||
|
|
Loading…
Reference in a new issue