Unit Test Workflow, Dockerfile, and Other Improvements
This commit is contained in:
		@ -1,7 +1,7 @@
 | 
			
		||||
import re
 | 
			
		||||
import subprocess
 | 
			
		||||
from typing import Union, List
 | 
			
		||||
from functools import cache
 | 
			
		||||
from functools import lru_cache
 | 
			
		||||
 | 
			
		||||
import toml
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ class Git(SCM):
 | 
			
		||||
 | 
			
		||||
    def _run_command(
 | 
			
		||||
        self, *args: str, throwExceptions: bool = True
 | 
			
		||||
    ) -> subprocess.CompletedProcess[str]:
 | 
			
		||||
    ) -> subprocess.CompletedProcess:
 | 
			
		||||
        return subprocess.run(
 | 
			
		||||
            args,
 | 
			
		||||
            capture_output=True,
 | 
			
		||||
@ -82,13 +82,17 @@ class Git(SCM):
 | 
			
		||||
                f"Error getting latest tagged git version: {str(e.stderr).rstrip()}"
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        if len(tagged_versions) > 0 and tagged_versions[-1] != "":
 | 
			
		||||
        if (
 | 
			
		||||
            tagged_versions is not None
 | 
			
		||||
            and len(tagged_versions) > 0
 | 
			
		||||
            and tagged_versions[-1] != ""
 | 
			
		||||
        ):
 | 
			
		||||
            version = tagged_versions[-1]
 | 
			
		||||
 | 
			
		||||
        logger.debug(f"Tag Version: {version}")
 | 
			
		||||
        return version
 | 
			
		||||
 | 
			
		||||
    @cache
 | 
			
		||||
    @lru_cache(maxsize=None)
 | 
			
		||||
    def get_branch(self) -> str:
 | 
			
		||||
        """
 | 
			
		||||
        Get the main branch
 | 
			
		||||
@ -97,7 +101,7 @@ class Git(SCM):
 | 
			
		||||
        proc = self._run_command(self.git_bin, "rev-parse", "--abbrev-ref", "HEAD")
 | 
			
		||||
        return proc.stdout.rstrip()
 | 
			
		||||
 | 
			
		||||
    @cache
 | 
			
		||||
    @lru_cache(maxsize=None)
 | 
			
		||||
    def get_merge_branch(self) -> Union[str, None]:
 | 
			
		||||
        """
 | 
			
		||||
        Get the branches involved in the merge
 | 
			
		||||
 | 
			
		||||
@ -1,49 +0,0 @@
 | 
			
		||||
import subprocess
 | 
			
		||||
from typing import Union, List
 | 
			
		||||
 | 
			
		||||
import toml
 | 
			
		||||
 | 
			
		||||
from semver.scm import SCM
 | 
			
		||||
from semver.logger import logger
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Perforce(SCM):
 | 
			
		||||
    def __init__(self) -> None:
 | 
			
		||||
        super().__init__()
 | 
			
		||||
 | 
			
		||||
    def get_tag_version(self) -> str:
 | 
			
		||||
        """
 | 
			
		||||
        Get the latest tagged version from Perforce labels
 | 
			
		||||
        :return: The latest tagged version
 | 
			
		||||
        """
 | 
			
		||||
        config: dict = toml.load("./.bumpversion.cfg")
 | 
			
		||||
 | 
			
		||||
        tag_expression: str = config["bumpversion"]["tag_name"].replace(
 | 
			
		||||
            "{new_version}", "[0-9]*.[0-9]*.[0-9]*"
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        logger.debug("Tag expression: " + str(tag_expression))
 | 
			
		||||
 | 
			
		||||
        # Default version is `0.0.0` or what is found in
 | 
			
		||||
        version = self.get_file_version(config)
 | 
			
		||||
 | 
			
		||||
        # If a version is found in Perforce labels, use that the latest labeled version
 | 
			
		||||
        labeled_versions: Union[List[str], None] = None
 | 
			
		||||
        try:
 | 
			
		||||
            proc = subprocess.run(
 | 
			
		||||
                ["p4", "labels", "-e", tag_expression, "-m1"],
 | 
			
		||||
                capture_output=True,
 | 
			
		||||
                text=True,
 | 
			
		||||
                check=True,
 | 
			
		||||
            )
 | 
			
		||||
            labeled_versions = proc.stdout.rstrip().split("\n")
 | 
			
		||||
        except subprocess.CalledProcessError as e:
 | 
			
		||||
            raise RuntimeError(
 | 
			
		||||
                f"Error getting latest labeled Perforce version: {str(e.stderr).rstrip()}"
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        if len(labeled_versions) > 0 and labeled_versions[-1] != "":
 | 
			
		||||
            version = labeled_versions[-1]
 | 
			
		||||
 | 
			
		||||
        logger.debug("Label Version: " + str(version))
 | 
			
		||||
        return version
 | 
			
		||||
		Reference in New Issue
	
	Block a user