How to check the last commit is matched with version
Posted zjbfvfv
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How to check the last commit is matched with version相关的知识,希望对你有一定的参考价值。
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_FolderVERSION
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"""^Releases(.*)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"""^Releases(.*)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的主要内容,如果未能解决你的问题,请参考以下文章
linux: How to Check the glibc (GNU libc) Version
When one check column is selected how to make the user not to select other check columns in EXTJS gr
Inno Script - How to make “I Accept the Agreement” radio button on EULA page selected by Default(代码片
How to check AD Account & Group DN information
[Groovy] How to check if element in groovy array/hash/collection/list?
FreeMarker : How to check if a variable exists in a FreeMarker template