-
Notifications
You must be signed in to change notification settings - Fork 8
/
update_version.py
36 lines (25 loc) · 957 Bytes
/
update_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the SLS Detector Package
"""
Script to update VERSION file with semantic versioning if provided as an argument, or with 0.0.0 if no argument is provided.
"""
import sys
import re
def get_version():
# Check at least one argument is passed
if len(sys.argv) < 2:
return "0.0.0"
version = sys.argv[1]
# Validate that the version argument matches semantic versioning format (X.Y.Z)
if not re.match(r'^\d+\.\d+\.\d+$', version):
print("Error: Version argument must be in semantic versioning format (X.Y.Z)")
sys.exit(1)
return version
def write_version_to_file(version):
with open("VERSION", "w") as version_file:
version_file.write(version)
print(f"Version {version} written to VERSION file.")
# Main script
if __name__ == "__main__":
version = get_version()
write_version_to_file(version)