summaryrefslogtreecommitdiff
path: root/ci/check_project_version.py
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2023-03-07 19:04:48 -0600
committerFederico Mena Quintero <federico@gnome.org>2023-03-07 19:06:32 -0600
commit11c386dbe1b3649540bd831c4ed97a4b3048b489 (patch)
tree85d948599b5cfb2c0c15889d037eff1991775040 /ci/check_project_version.py
parent3ea3f83dd721a9f504e56c8105b95407e105e7da (diff)
downloadlibrsvg-11c386dbe1b3649540bd831c4ed97a4b3048b489.tar.gz
(#933): ci/check_project_version.py: New script to check the project's version number across several files
Fixes https://gitlab.gnome.org/GNOME/librsvg/-/issues/933 Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/805>
Diffstat (limited to 'ci/check_project_version.py')
-rw-r--r--ci/check_project_version.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/ci/check_project_version.py b/ci/check_project_version.py
new file mode 100644
index 00000000..8c49c3b1
--- /dev/null
+++ b/ci/check_project_version.py
@@ -0,0 +1,75 @@
+# This script checks that the project's version is the same in a few files where it must appear.
+
+import re
+import sys
+
+def get_first_group(regex, line):
+ matches = regex.search(line)
+ if matches is None:
+ return None
+ else:
+ return matches.group(1)
+
+def get_configure_ac_version():
+ major_regex = re.compile(r'^m4_define\(\[rsvg_major_version\],\[(\d+)\]\)')
+ minor_regex = re.compile(r'^m4_define\(\[rsvg_minor_version\],\[(\d+)\]\)')
+ micro_regex = re.compile(r'^m4_define\(\[rsvg_micro_version\],\[(\d+)\]\)')
+
+ major = None
+ micro = None
+ minor = None
+
+ with open("configure.ac") as f:
+ for line in f.readlines():
+ if major is None:
+ major = get_first_group(major_regex, line)
+
+ if minor is None:
+ minor = get_first_group(minor_regex, line)
+
+ if micro is None:
+ micro = get_first_group(micro_regex, line)
+
+ if not (major and minor and micro):
+ raise Exception('configure.ac does not have all the necessary version numbers')
+
+ return f'{major}.{minor}.{micro}'
+
+# Assumes a line like 'version = "1.2.3"'
+def get_version_from_toml(filename):
+ regex = re.compile(r'^version = "(\d+\.\d+\.\d+)"')
+
+ with open(filename) as f:
+ for line in f.readlines():
+ version = get_first_group(regex, line)
+ if version is not None:
+ return version
+
+ raise Exception(f'{filename} does not have a version number')
+
+def get_cargo_toml_version():
+ return get_version_from_toml('Cargo.toml')
+
+def get_doc_version():
+ return get_version_from_toml('doc/librsvg.toml')
+
+versions = [
+ ['configure.ac', get_configure_ac_version()],
+ ['Cargo.toml', get_cargo_toml_version()],
+ ['doc/librsvg.toml', get_doc_version()],
+]
+
+all_the_same = True
+
+for filename, version in versions[1:]:
+ if version != versions[0][1]:
+ all_the_same = False
+
+if not all_the_same:
+ print(f'Version numbers do not match, please fix them!\n', file=sys.stderr)
+ for filename, version in versions:
+ print(f'{filename}: {version}', file=sys.stderr)
+
+ sys.exit(1)
+
+print(f'Versions number match. All good!', file=sys.stderr)