diff --git a/src/ansiblelint/data/profiles.yml b/src/ansiblelint/data/profiles.yml index 0749ad5030..61331fbd79 100644 --- a/src/ansiblelint/data/profiles.yml +++ b/src/ansiblelint/data/profiles.yml @@ -58,6 +58,7 @@ safety: extends: moderate rules: avoid-implicit: + changelog-galaxy-version: latest: package-latest: risky-file-permissions: diff --git a/src/ansiblelint/rules/galaxy.py b/src/ansiblelint/rules/galaxy.py index 28f35437ae..5cf8426020 100644 --- a/src/ansiblelint/rules/galaxy.py +++ b/src/ansiblelint/rules/galaxy.py @@ -13,6 +13,8 @@ from ansiblelint.errors import MatchError from ansiblelint.file_utils import Lintable +CHANGELOG_FILE = None + class GalaxyRule(AnsibleLintRule): """Rule for checking collection version is greater than 1.0.0 and checking for changelog.""" @@ -29,13 +31,22 @@ class GalaxyRule(AnsibleLintRule): "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", + "galaxy[version-no-sync-changelog-latest]": "Checks if version in galaxy.yaml is in sync with latest version in changelog yaml", } def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]: """Return matches found for a specific play (entry in playbook).""" + changelog_file_data = [] + global CHANGELOG_FILE + if file.kind == "changelog": + CHANGELOG_FILE = list(file.data.get("releases", None).keys()) + if file.kind != "galaxy": # type: ignore[comparison-overlap] return [] + if CHANGELOG_FILE: + changelog_file_data = CHANGELOG_FILE + # Defined by Automation Hub Team and Partner Engineering required_tag_list = [ "application", @@ -90,6 +101,15 @@ def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]: filename=file, ), ) + else: + if Version(data.get("version")) != Version(changelog_file_data[-3]): + results.append( + self.create_matcherror( + message="Version in galaxy.yaml and the latest version in changelog should be same.", + tag="galaxy[version-no-sync-changelog-latest]", + filename=file, + ), + ) # Checking if galaxy.yml contains one or more required tags for certification if not galaxy_tag_list or not any(