From 11c386dbe1b3649540bd831c4ed97a4b3048b489 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 7 Mar 2023 19:04:48 -0600 Subject: (#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: --- ci/check_project_version.py | 75 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ci/check_project_version.py (limited to 'ci/check_project_version.py') 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) -- cgit v1.2.1