summaryrefslogtreecommitdiffstats
path: root/src/ansiblelint/rules/galaxy.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ansiblelint/rules/galaxy.py')
-rw-r--r--src/ansiblelint/rules/galaxy.py44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/ansiblelint/rules/galaxy.py b/src/ansiblelint/rules/galaxy.py
index 2f627f5..e9b21d3 100644
--- a/src/ansiblelint/rules/galaxy.py
+++ b/src/ansiblelint/rules/galaxy.py
@@ -1,11 +1,12 @@
"""Implementation of GalaxyRule."""
+
from __future__ import annotations
import sys
from functools import total_ordering
from typing import TYPE_CHECKING, Any
-from ansiblelint.constants import LINE_NUMBER_KEY
+from ansiblelint.constants import FILENAME_KEY, LINE_NUMBER_KEY
from ansiblelint.rules import AnsibleLintRule
if TYPE_CHECKING:
@@ -27,6 +28,7 @@ class GalaxyRule(AnsibleLintRule):
"galaxy[version-missing]": "galaxy.yaml should have version tag.",
"galaxy[version-incorrect]": "collection version should be greater than or equal to 1.0.0",
"galaxy[no-runtime]": "meta/runtime.yml file not found.",
+ "galaxy[invalid-dependency-version]": "Invalid collection metadata. Dependency version spec range is invalid",
}
def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]:
@@ -39,6 +41,7 @@ class GalaxyRule(AnsibleLintRule):
"application",
"cloud",
"database",
+ "eda",
"infrastructure",
"linux",
"monitoring",
@@ -55,6 +58,7 @@ class GalaxyRule(AnsibleLintRule):
changelog_found = 0
changelog_paths = [
base_path / "changelogs" / "changelog.yaml",
+ base_path / "changelogs" / "changelog.yml",
base_path / "CHANGELOG.rst",
base_path / "CHANGELOG.md",
]
@@ -62,8 +66,21 @@ class GalaxyRule(AnsibleLintRule):
for path in changelog_paths:
if path.is_file():
changelog_found = 1
-
- galaxy_tag_list = data.get("tags", None)
+ galaxy_tag_list = data.get("tags")
+ collection_deps = data.get("dependencies")
+ if collection_deps:
+ for dep, ver in collection_deps.items():
+ if (
+ dep not in [LINE_NUMBER_KEY, FILENAME_KEY]
+ and len(str(ver).strip()) == 0
+ ):
+ results.append(
+ self.create_matcherror(
+ message=f"Invalid collection metadata. Dependency version spec range is invalid for '{dep}'.",
+ tag="galaxy[invalid-dependency-version]",
+ filename=file,
+ ),
+ )
# Changelog Check - building off Galaxy rule as there is no current way to check
# for a nonexistent file
@@ -108,7 +125,6 @@ class GalaxyRule(AnsibleLintRule):
results.append(
self.create_matcherror(
message="collection version should be greater than or equal to 1.0.0",
- # pylint: disable=protected-access
lineno=version._line_number, # noqa: SLF001
tag="galaxy[version-incorrect]",
filename=file,
@@ -154,7 +170,7 @@ class Version:
def _coerce(other: object) -> Version:
if isinstance(other, str):
other = Version(other)
- if isinstance(other, (int, float)):
+ if isinstance(other, int | float):
other = Version(str(other))
if isinstance(other, Version):
return other
@@ -172,7 +188,7 @@ if "pytest" in sys.modules:
"""Positive test for collection version in galaxy."""
collection = RulesCollection()
collection.register(GalaxyRule())
- success = "examples/collection/galaxy.yml"
+ success = "examples/.collection/galaxy.yml"
good_runner = Runner(success, rules=collection)
assert [] == good_runner.run()
@@ -189,7 +205,7 @@ if "pytest" in sys.modules:
"""Test for no collection version in galaxy."""
collection = RulesCollection()
collection.register(GalaxyRule())
- failure = "examples/no_collection_version/galaxy.yml"
+ failure = "examples/.no_collection_version/galaxy.yml"
bad_runner = Runner(failure, rules=collection)
errs = bad_runner.run()
assert len(errs) == 1
@@ -222,17 +238,25 @@ if "pytest" in sys.modules:
id="pass",
),
pytest.param(
- "examples/collection/galaxy.yml",
+ "examples/.collection/galaxy.yml",
["schema[galaxy]"],
id="schema",
),
pytest.param(
- "examples/no_changelog/galaxy.yml",
+ "examples/.invalid_dependencies/galaxy.yml",
+ [
+ "galaxy[invalid-dependency-version]",
+ "galaxy[invalid-dependency-version]",
+ ],
+ id="invalid-dependency-version",
+ ),
+ pytest.param(
+ "examples/.no_changelog/galaxy.yml",
["galaxy[no-changelog]"],
id="no-changelog",
),
pytest.param(
- "examples/no_collection_version/galaxy.yml",
+ "examples/.no_collection_version/galaxy.yml",
["schema[galaxy]", "galaxy[version-missing]"],
id="no-collection-version",
),