码迷,mamicode.com
首页 > 其他好文 > 详细

How to check the last commit is matched with version

时间:2020-06-11 13:37:42      阅读:53      评论:0      收藏:0      [点我收藏+]

标签:create   ram   ast   nta   efi   art   false   code   lse   

When release a version, we want to check the version number whether match. so we define some rules to follow to avoid mistakes.

1. VERSION file locates at Component_Folder\VERSION

The file records the version of component.

e.g. 2.01.10

The VERSION information shall be compiled into the source code.

2. The last commit message shall be follow "Release component name  v xx.xx[.xx]  any content"

 The git tool is used.

 

A python program created to do this checking, follows are the example code.

RELEASE_COMMIT_PATTERN = re.compile(r"""^Release\s(.*)\s# Start with the word Release followed by whitespace,
                                                        # any characters can be the component name and another single whitespace character
                                        (v|V)           # The version number starts with lowercase v or V
                                        (\d+)           # The major version number can be any number 
                                                        #
                                                        #
                                                        # each version number component is delimited with a dot (.)
                                        (.\d+)          # The minor version number can be any number
                                                        # each version number component is delimited with a dot (.)
                                                        #
                                                        #
                                        *(.\d+)         # The patch version number can be any number or without the patch version
                                                        #
                                                        #
                                        (\s.*)*         # any characters followed a space after version
                                        """             
                                                        
                                        , re.VERBOSE)
VERSION_NUMBER_PATTERN = re.compile(r"""^Release\s(.*)\s(v|V)(?P<version_number>(\d+)(.\d+)*(.\d+))(\s.*)*""", re.VERBOSE)

 

def get_version_number_from_commit(component, root_directory):
    """Get component (project) version number for commit message

    :param component: The tuple contains component name and component path
    :param root_directory: Repository root directory

    :returns: True if the commmit is a release commit, False if it is not.
    :returns: Real version number if the commmit is a release commit, invalid version number if it is not.
    """
    # Get latest commit message
    commit_message = subprocess.check_output([git, log, --oneline, -n, 1, --pretty=%s, --,
                                             str(root_directory.joinpath(component.component_path))]).strip().decode()

    # check if the commit is a release commit
    if is_release_commit(commit_message):
        commit_message_match = VERSION_NUMBER_PATTERN.match(commit_message)
        version_number = commit_message_match.group("version_number")
        logger.debug("Version number from commit is: " + version_number)
        return True, version_number
    else:
        logger.error("The latest commit on " + component.component_name + " is not a release commit:" + commit_message)
        return False, "Invalid version number from commit"
def is_release_commit(commit_message):
    """check if a commit is release commit

    """
    if RELEASE_COMMIT_PATTERN.match(commit_message):
        return True
    else:
        return False

 

How to check the last commit is matched with version

标签:create   ram   ast   nta   efi   art   false   code   lse   

原文地址:https://www.cnblogs.com/zjbfvfv/p/13092436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!