diff --git a/examples/collections/broken_no_license/CHANGELOG.md b/examples/collections/broken_no_license/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/collections/broken_no_license/galaxy.yml b/examples/collections/broken_no_license/galaxy.yml new file mode 100644 index 0000000000..c8750781cd --- /dev/null +++ b/examples/collections/broken_no_license/galaxy.yml @@ -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 diff --git a/examples/collections/broken_no_license/meta/runtime.yml b/examples/collections/broken_no_license/meta/runtime.yml new file mode 100644 index 0000000000..874333938d --- /dev/null +++ b/examples/collections/broken_no_license/meta/runtime.yml @@ -0,0 +1,2 @@ +--- +requires_ansible: ">=2.20" diff --git a/examples/collections/broken_no_repo/CHANGELOG.md b/examples/collections/broken_no_repo/CHANGELOG.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/collections/broken_no_repo/galaxy.yml b/examples/collections/broken_no_repo/galaxy.yml new file mode 100644 index 0000000000..3dc2a47ed6 --- /dev/null +++ b/examples/collections/broken_no_repo/galaxy.yml @@ -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 diff --git a/examples/collections/broken_no_repo/meta/runtime.yml b/examples/collections/broken_no_repo/meta/runtime.yml new file mode 100644 index 0000000000..874333938d --- /dev/null +++ b/examples/collections/broken_no_repo/meta/runtime.yml @@ -0,0 +1,2 @@ +--- +requires_ansible: ">=2.20" diff --git a/examples/collections/broken_no_runtime/galaxy.yml b/examples/collections/broken_no_runtime/galaxy.yml index f9ffb9dc30..be7ee93839 100644 --- a/examples/collections/broken_no_runtime/galaxy.yml +++ b/examples/collections/broken_no_runtime/galaxy.yml @@ -8,3 +8,5 @@ readme: ../README.md tags: ["tools"] description: Lorem ipsum repository: https://www.github.com/my_org/my_collection +license: + - MIT diff --git a/src/ansiblelint/rules/galaxy.py b/src/ansiblelint/rules/galaxy.py index 0d1c775e85..452900154c 100644 --- a/src/ansiblelint/rules/galaxy.py +++ b/src/ansiblelint/rules/galaxy.py @@ -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]: @@ -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 @@ -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( diff --git a/src/ansiblelint/schemas/galaxy.json b/src/ansiblelint/schemas/galaxy.json index 7774ec29cf..e006c8ea4c 100644 --- a/src/ansiblelint/schemas/galaxy.json +++ b/src/ansiblelint/schemas/galaxy.json @@ -876,8 +876,7 @@ "version", "readme", "authors", - "description", - "repository" + "description" ], "title": "Ansible galaxy.yml Schema", "type": "object"