InvenTree/ci/check_version_number.py

96 lines
2.7 KiB
Python
Raw Normal View History

"""
On release, ensure that the release tag matches the InvenTree version number!
"""
import sys
import re
import os
import argparse
if __name__ == '__main__':
here = os.path.abspath(os.path.dirname(__file__))
version_file = os.path.join(here, '..', 'InvenTree', 'InvenTree', 'version.py')
version = None
with open(version_file, 'r') as f:
text = f.read()
# Extract the InvenTree software version
results = re.findall(r'INVENTREE_SW_VERSION = "(.*)"', text)
2022-05-15 15:52:23 +00:00
if len(results) != 1:
print(f"Could not find INVENTREE_SW_VERSION in {version_file}")
sys.exit(1)
version = results[0]
print(f"InvenTree Version: '{version}'")
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--tag', help='Compare against specified version tag', action='store')
parser.add_argument('-r', '--release', help='Check that this is a release version', action='store_true')
parser.add_argument('-d', '--dev', help='Check that this is a development version', action='store_true')
2021-09-12 11:36:14 +00:00
parser.add_argument('-b', '--branch', help='Check against a particular branch', action='store')
args = parser.parse_args()
2021-09-12 11:36:14 +00:00
if args.branch:
"""
Version number requirement depends on format of branch
'master': development branch
'stable': release branch
"""
print(f"Checking version number for branch '{args.branch}'")
if args.branch == 'master':
2021-09-12 12:08:51 +00:00
print("- This is a development branch")
2021-09-12 11:36:14 +00:00
args.dev = True
elif args.branch == 'stable':
2021-09-12 12:08:51 +00:00
print("- This is a stable release branch")
2021-09-12 11:36:14 +00:00
args.release = True
if args.dev:
"""
Check that the current verrsion number matches the "development" format
e.g. "0.5 dev"
"""
2021-11-19 20:50:41 +00:00
print("Checking development branch")
pattern = r"^\d+(\.\d+)+ dev$"
result = re.match(pattern, version)
if result is None:
print(f"Version number '{version}' does not match required pattern for development branch")
sys.exit(1)
elif args.release:
"""
Check that the current version number matches the "release" format
e.g. "0.5.1"
"""
2021-11-19 20:50:41 +00:00
print("Checking release branch")
pattern = r"^\d+(\.\d+)+$"
result = re.match(pattern, version)
if result is None:
print(f"Version number '{version}' does not match required pattern for stable branch")
2021-09-12 11:36:14 +00:00
sys.exit(1)
if args.tag:
2022-05-15 15:52:23 +00:00
if args.tag != version:
print(f"Release tag '{args.tag}' does not match INVENTREE_SW_VERSION '{version}'")
sys.exit(1)
2021-10-10 23:21:36 +00:00
sys.exit(0)