-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from stfc/re-configure_features
Refactor features
- Loading branch information
Showing
15 changed files
with
188 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
.idea | ||
main_version | ||
branch_version | ||
src/__pycache__/* | ||
tests/__pycache__/* | ||
src/features/__pycache__/* | ||
tests/__pycache__/* | ||
.coverage | ||
.coveragerc | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
services: | ||
self-test: | ||
image: some/test:1.1.0 | ||
image: some/test:1.2.0 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Compare app version.txt on main to the branch.""" | ||
|
||
from pathlib import Path | ||
|
||
from packaging.version import Version | ||
|
||
|
||
class CompareAppVersion: | ||
"""This class compares the app versions""" | ||
|
||
def run(self, path1: Path, path2: Path) -> bool: | ||
""" | ||
Entry point to compare app versions. | ||
:param path1: Path to main version | ||
:param path2: Path to branch version | ||
:return: true if success, error if fail | ||
""" | ||
main_content, branch_content = self.read_files(path1, path2) | ||
main_ver = self.get_version(main_content) | ||
branch_ver = self.get_version(branch_content) | ||
comparison = self.compare(main_ver, branch_ver) | ||
if not comparison: | ||
raise RuntimeError( | ||
f"The version in {('/'.join(str(path2).split('/')[4:]))[0:]} has not been updated correctly." | ||
) | ||
return True | ||
|
||
@staticmethod | ||
def read_files(path1: Path, path2: Path) -> (str, str): | ||
""" | ||
Read both version files and return the contents | ||
:param path1: Path to main version | ||
:param path2: Path to branched version | ||
:return: main_ver, branch_ver | ||
""" | ||
with open(path1, "r", encoding="utf-8") as file1: | ||
content1 = file1.read() | ||
with open(path2, "r", encoding="utf-8") as file2: | ||
content2 = file2.read() | ||
return content1, content2 | ||
|
||
@staticmethod | ||
def get_version(content: str) -> Version: | ||
""" | ||
This method returns the version from the file as an object | ||
For app versions we expect nothing else in the file than the version. | ||
:param content: app version string | ||
:return: app version object | ||
""" | ||
return Version(content) | ||
|
||
@staticmethod | ||
def compare(main: Version, branch: Version) -> bool: | ||
""" | ||
Returns if the branch version is larger than the main version | ||
:param main: Version on main | ||
:param branch: Version on branch | ||
:return: If the version update is correct return true, else return error | ||
""" | ||
return branch > main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""Compare Docker compose image version to the version.txt.""" | ||
|
||
from pathlib import Path | ||
from typing import List | ||
|
||
from packaging.version import Version | ||
|
||
|
||
class CompareComposeVersion: | ||
"""This class compares the docker compose image version to the app version.""" | ||
|
||
def run(self, app: Path, compose: Path) -> bool: | ||
""" | ||
Entry point to compare docker compose and app versions. | ||
:param app: Path to app version | ||
:param compose: Path to compose image version | ||
:return: true if success, error if fail | ||
""" | ||
app_content, compose_content = self.read_files(app, compose) | ||
app_ver = Version(app_content) | ||
compose_ver = self.get_version(compose_content) | ||
comparison = self.compare(app_ver, compose_ver) | ||
if not comparison: | ||
raise RuntimeError( | ||
f"The version in {('/'.join(str(compose).split('/')[4:]))[0:]}" | ||
f" does not match {('/'.join(str(app).split('/')[4:]))[0:]}." | ||
) | ||
return True | ||
|
||
@staticmethod | ||
def read_files(app: Path, compose: Path) -> (str, List): | ||
""" | ||
Read both version files and return the contents | ||
:param app: Path to app version | ||
:param compose: Path to compose version | ||
:return: main_ver, branch_ver | ||
""" | ||
with open(app, "r", encoding="utf-8") as file1: | ||
content1 = file1.read() | ||
with open(compose, "r", encoding="utf-8") as file2: | ||
content2 = file2.readlines() | ||
return content1, content2 | ||
|
||
@staticmethod | ||
def get_version(content: List[str]) -> Version: | ||
""" | ||
This method returns the version from the file as an object | ||
For compose versions we have to do some data handling. | ||
:param content: Compose version string | ||
:return: Compose version object | ||
""" | ||
version_str = "" | ||
for line in content: | ||
if "image" in line: | ||
version_str = line.strip("\n").split(":")[-1] | ||
break | ||
return Version(version_str) | ||
|
||
@staticmethod | ||
def compare(app: Version, compose: Version) -> bool: | ||
""" | ||
Returns if the app version and docker compose version are equal. | ||
:param app: App version | ||
:param compose: Compose version | ||
:return: If the version update is correct return true, else return error | ||
""" | ||
return app == compose |
Oops, something went wrong.