summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarge Bot <marge-bot@gnome.org>2023-03-08 01:45:35 +0000
committerMarge Bot <marge-bot@gnome.org>2023-03-08 01:45:35 +0000
commitce0bf9cc2b9e7d35500c5ac8f964d1d9e1e8f2e3 (patch)
tree85d948599b5cfb2c0c15889d037eff1991775040
parent3ea3f83dd721a9f504e56c8105b95407e105e7da (diff)
parent11c386dbe1b3649540bd831c4ed97a4b3048b489 (diff)
downloadlibrsvg-ce0bf9cc2b9e7d35500c5ac8f964d1d9e1e8f2e3.tar.gz
Merge branch 'check-project-version' into 'main'
(#933): ci/check_project_version.py: New script to check the project's version number across several files Closes #933 See merge request GNOME/librsvg!805
-rw-r--r--.gitlab-ci.yml3
-rw-r--r--ci/check_project_version.py75
2 files changed, 77 insertions, 1 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 66511053..10a1ad48 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -314,12 +314,13 @@ deny:
script:
- cargo deny check
-check_rust_versions:
+check_versions:
extends:
- '.container.opensuse@x86_64.stable'
- '.fdo.distribution-image@opensuse'
stage: lint
script:
+ - python3 ci/check_project_version.py
- python3 ci/check_rust_versions.py
coverage:
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)