Skip to content
Merged
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
Empty file.
10 changes: 10 additions & 0 deletions examples/collections/broken_no_license/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: broken_no_license
namespace: fixtures
version: 1.2.3
authors:
- John
readme: ../README.md
tags: ["tools"]
description: Lorem ipsum
repository: https://www.github.com/my_org/my_collection
2 changes: 2 additions & 0 deletions examples/collections/broken_no_license/meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
requires_ansible: ">=2.20"
Empty file.
11 changes: 11 additions & 0 deletions examples/collections/broken_no_repo/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: broken_no_repo
namespace: fixtures
version: 1.2.3
authors:
- John
readme: ../README.md
tags: ["tools"]
description: Lorem ipsum
license:
- MIT
2 changes: 2 additions & 0 deletions examples/collections/broken_no_repo/meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
requires_ansible: ">=2.20"
2 changes: 2 additions & 0 deletions examples/collections/broken_no_runtime/galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ readme: ../README.md
tags: ["tools"]
description: Lorem ipsum
repository: https://www.github.com/my_org/my_collection
license:
- MIT
32 changes: 32 additions & 0 deletions src/ansiblelint/rules/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class GalaxyRule(AnsibleLintRule):
"galaxy[version-missing]": "galaxy.yaml should have version tag.",
"galaxy[no-runtime]": "meta/runtime.yml file not found.",
"galaxy[invalid-dependency-version]": "Invalid collection metadata. Dependency version spec range is invalid",
"galaxy[no-repository]": "galaxy.yaml should have a repository key for publication to Galaxy. See https://docs.ansible.com/ansible/latest/dev_guide/collections_galaxy_meta.html",
"galaxy[no-license]": "galaxy.yaml should have a license or license_file key for publication to Galaxy. See https://docs.ansible.com/ansible/latest/dev_guide/collections_galaxy_meta.html",
}

def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]:
Expand Down Expand Up @@ -179,6 +181,26 @@ def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]:
),
)

# Check for repository key - recommended for Galaxy publication
if "repository" not in data:
results.append(
self.create_matcherror(
message="galaxy.yaml should have a repository key for publication to Galaxy. See https://docs.ansible.com/ansible/latest/dev_guide/collections_galaxy_meta.html",
tag="galaxy[no-repository]",
filename=file,
),
)

# Check for license or license_file key - recommended for Galaxy publication
if "license" not in data and "license_file" not in data:
results.append(
self.create_matcherror(
message="galaxy.yaml should have a license or license_file key for publication to Galaxy. See https://docs.ansible.com/ansible/latest/dev_guide/collections_galaxy_meta.html",
tag="galaxy[no-license]",
filename=file,
),
)

return results


Expand Down Expand Up @@ -253,6 +275,16 @@ def test_galaxy_no_collection_version() -> None:
["galaxy[no-runtime]"],
id="broken_no_runtime",
),
pytest.param(
"examples/collections/broken_no_license/galaxy.yml",
["galaxy[no-license]"],
id="broken_no_license",
),
pytest.param(
"examples/collections/broken_no_repo/galaxy.yml",
["galaxy[no-repository]"],
id="broken_no_repo",
),
),
)
def test_galaxy_rule(
Expand Down
3 changes: 1 addition & 2 deletions src/ansiblelint/schemas/galaxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,7 @@
"version",
"readme",
"authors",
"description",
"repository"
"description"
],
"title": "Ansible galaxy.yml Schema",
"type": "object"
Expand Down