Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] rule to check changelog most recent version with galaxy version in galaxy.yml #3872

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ansiblelint/data/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ safety:
extends: moderate
rules:
avoid-implicit:
changelog-galaxy-version:
latest:
package-latest:
risky-file-permissions:
Expand Down
20 changes: 20 additions & 0 deletions src/ansiblelint/rules/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fond of this implementation, reusing the file object to read changelog data and compare it to galaxy is a better implementation.

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",
Expand Down Expand Up @@ -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(
Expand Down
Loading