2021-08-07 11:21:09 +00:00
|
|
|
"""
|
2022-05-28 23:40:37 +00:00
|
|
|
Ensure that the release tag matches the InvenTree version number:
|
|
|
|
|
|
|
|
master / main branch:
|
|
|
|
- version number must end with 'dev'
|
|
|
|
|
|
|
|
stable branch:
|
|
|
|
- version number must *not* end with 'dev'
|
|
|
|
- version number cannot already exist as a release tag
|
|
|
|
|
|
|
|
tagged branch:
|
|
|
|
- version number must match tag being built
|
|
|
|
- version number cannot already exist as a release tag
|
|
|
|
|
2021-08-07 11:21:09 +00:00
|
|
|
"""
|
|
|
|
|
2022-05-20 15:24:51 +00:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
2021-08-07 11:21:09 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# GITHUB_REF_TYPE may be either 'branch' or 'tag'
|
|
|
|
GITHUB_REF_TYPE = os.environ['GITHUB_REF_TYPE']
|
|
|
|
|
|
|
|
# GITHUB_REF may be either 'refs/heads/<branch>' or 'refs/heads/<tag>'
|
|
|
|
GITHUB_REF = os.environ['GITHUB_REF']
|
|
|
|
|
2021-08-07 11:21:09 +00:00
|
|
|
version_file = os.path.join(here, '..', 'InvenTree', 'InvenTree', 'version.py')
|
|
|
|
|
2021-10-10 23:19:59 +00:00
|
|
|
version = None
|
|
|
|
|
2021-08-07 11:21:09 +00:00
|
|
|
with open(version_file, 'r') as f:
|
|
|
|
|
2021-10-10 23:19:59 +00:00
|
|
|
text = f.read()
|
|
|
|
|
|
|
|
# Extract the InvenTree software version
|
|
|
|
results = re.findall(r'INVENTREE_SW_VERSION = "(.*)"', text)
|
2021-08-07 11:21:09 +00:00
|
|
|
|
2022-05-15 15:52:23 +00:00
|
|
|
if len(results) != 1:
|
2021-08-07 11:21:09 +00:00
|
|
|
print(f"Could not find INVENTREE_SW_VERSION in {version_file}")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
version = results[0]
|
|
|
|
|
2021-10-10 23:19:59 +00:00
|
|
|
print(f"InvenTree Version: '{version}'")
|
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# Determine which docker tag we are going to use
|
|
|
|
docker_tag = None
|
2021-09-12 11:36:14 +00:00
|
|
|
|
2022-05-28 23:49:32 +00:00
|
|
|
if GITHUB_REF_TYPE == 'branch' and 'stable' in GITHUB_REF:
|
2022-05-28 23:40:37 +00:00
|
|
|
print("Checking requirements for 'stable' release")
|
2021-09-12 11:36:14 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
pattern = r"^\d+(\.\d+)+$"
|
|
|
|
result = re.match(pattern, version)
|
2021-09-12 11:36:14 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
if result is None:
|
|
|
|
print(f"Version number '{version}' does not match required pattern for stable branch")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print(f"Version number '{version}' matches stable branch")
|
2021-09-12 11:36:14 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
docker_tag = 'stable'
|
2021-09-12 11:17:56 +00:00
|
|
|
|
2022-05-28 23:49:32 +00:00
|
|
|
elif GITHUB_REF_TYPE == 'branch' and ('master' in GITHUB_REF or 'main' in GITHUB_REF):
|
2022-05-28 23:40:37 +00:00
|
|
|
print("Checking requirements for main development branch:")
|
2021-10-10 23:19:59 +00:00
|
|
|
|
2022-05-01 19:53:12 +00:00
|
|
|
pattern = r"^\d+(\.\d+)+ dev$"
|
2021-09-12 11:17:56 +00:00
|
|
|
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)
|
2022-05-28 23:40:37 +00:00
|
|
|
else:
|
|
|
|
print(f"Version number '{version}' matches development branch")
|
2021-09-12 11:17:56 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
docker_tag = 'latest'
|
2021-09-12 11:17:56 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
elif GITHUB_REF_TYPE == 'tag':
|
|
|
|
# GITHUB_REF should be of th eform /refs/heads/<tag>
|
|
|
|
version_tag = GITHUB_REF.split('/')[-1]
|
|
|
|
print(f"Checking requirements for tagged release - '{version_tag}'")
|
2021-10-10 23:19:59 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
if version_tag != version:
|
|
|
|
print(f"Version number '{version}' does not match tag '{version_tag}'")
|
|
|
|
sys.exit
|
2021-09-12 11:17:56 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# TODO: Check if there is already a release with this tag!
|
2021-09-12 11:17:56 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
docker_tag = version_tag
|
2021-09-12 11:17:56 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
else:
|
|
|
|
print("Unsupported branch / version combination:")
|
|
|
|
print(f"InvenTree Version: {version}")
|
|
|
|
print("GITHUB_REF_TYPE:", GITHUB_REF_TYPE)
|
|
|
|
print("GITHUB_REF:", GITHUB_REF)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if docker_tag is None:
|
|
|
|
print("Docker tag could not be determined")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print(f"Version check passed for '{version}'!")
|
|
|
|
print(f"Docker tag: '{docker_tag}'")
|
2021-08-07 11:21:09 +00:00
|
|
|
|
2022-05-28 23:40:37 +00:00
|
|
|
# Ref: https://getridbug.com/python/how-to-set-environment-variables-in-github-actions-using-python/
|
|
|
|
with open(os.getenv('GITHUB_ENV'), 'a') as env_file:
|
|
|
|
env_file.write(f"docker_tag={docker_tag}\n")
|