From 42c1fc3e7d3b833fe484f01e70b608b1aa90109d Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Mon, 6 Mar 2023 14:45:47 +0100 Subject: [PATCH] ci/collect-repo-info: Make plugin VERSION reading more robust The zeek-kafak plugin's VERSION file contains a commented license header followed by an empty line, followed by the actual version. Attempt to deal with this by using the first non-commented non-empty line. --- ci/collect-repo-info.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ci/collect-repo-info.py b/ci/collect-repo-info.py index 01d9c563db..8aa6a49cf5 100755 --- a/ci/collect-repo-info.py +++ b/ci/collect-repo-info.py @@ -116,6 +116,19 @@ def collect_git_info(zeek_dir: pathlib.Path): return info +def read_plugin_version(plugin_dir: pathlib.Path): + """ + Open the VERSION file, look for the first non empty + non comment line and return it. + """ + with (plugin_dir / "VERSION").open() as f: + for line in f: + line = line.strip() + if line and not line.startswith("#"): + return line + return "" + + def collect_plugin_info(plugin_dir: pathlib.Path): """ """ # A plugin's name is not part of it's metadata/information, use @@ -125,7 +138,7 @@ def collect_plugin_info(plugin_dir: pathlib.Path): } try: - result["version"] = (plugin_dir / "VERSION").read_text().strip() + result["version"] = read_plugin_version(plugin_dir) except FileNotFoundError: logger.warning("No VERSION found in %s", plugin_dir)