From d424795c6184ebb729e75d70009f777adb1a5ff1 Mon Sep 17 00:00:00 2001
From: Bastien Abadie <abadie@teklia.com>
Date: Fri, 27 Sep 2024 08:37:01 +0000
Subject: [PATCH] Detect system workers version mismatch through pre-commit

---
 .pre-commit-config.yaml    |  9 +++++++++
 Makefile                   |  2 +-
 ci/check_system_workers.py | 28 ++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 ci/check_system_workers.py

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 2048df6649..8066ca8216 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -41,3 +41,12 @@ repos:
         args: ['1000']
         # Only run on Arkindex unit test files
         files: '^arkindex\/[^\/]*\/tests\/(.*\/)?test_.*\.py'
+
+  - repo: local
+    hooks:
+      - id: check-system-workers-version
+        name: Check system workers version matches current Arkindex version
+        entry: python ci/check_system_workers.py
+        language: system
+        pass_filenames: false
+        files: '^(VERSION|arkindex/system_workers.yml)$'
diff --git a/Makefile b/Makefile
index aa9f5bdb7d..f266281fd5 100644
--- a/Makefile
+++ b/Makefile
@@ -47,7 +47,7 @@ schema:
 release:
 	$(eval version:=$(shell cat VERSION))
 	echo $(version)
-	git commit VERSION -m "Version $(version)"
+	git commit VERSION arkindex/system_workers.yml -m "Version $(version)"
 	git tag $(version)
 	git push origin master $(version)
 
diff --git a/ci/check_system_workers.py b/ci/check_system_workers.py
new file mode 100644
index 0000000000..0d5dcef51e
--- /dev/null
+++ b/ci/check_system_workers.py
@@ -0,0 +1,28 @@
+import sys
+from pathlib import Path
+
+import yaml
+
+ROOT = Path(__file__).parent.parent
+
+
+def check_versions_match():
+    system_workers_file = ROOT / "arkindex" / "system_workers.yml"
+    assert system_workers_file.exists(), f"Missing system workers file in {system_workers_file}"
+
+    version_file = ROOT / "VERSION"
+    assert version_file.exists(), f"Missing version file in {version_file}"
+
+    version = version_file.read_text().strip()
+
+    system_workers = yaml.safe_load(system_workers_file.open())
+
+    assert system_workers["version"] == version, f"Version mismatch between VERSION ({version}) and system worker ({system_workers['version']})"
+
+
+if __name__ == "__main__":
+    try:
+        check_versions_match()
+    except AssertionError as e:
+        print(f"[ERROR] {e}")
+        sys.exit(1)
-- 
GitLab