Skip to content

Commit 5a74f30

Browse files
rivv0ssbarneaalisonlhartpre-commit-ci[bot]
authored
fix: make repository key optional in galaxy.yml (#4798)
Co-authored-by: Sorin Sbarnea <[email protected]> Co-authored-by: Alison Hart <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4129a65 commit 5a74f30

File tree

9 files changed

+60
-2
lines changed

9 files changed

+60
-2
lines changed

examples/collections/broken_no_license/CHANGELOG.md

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: broken_no_license
3+
namespace: fixtures
4+
version: 1.2.3
5+
authors:
6+
- John
7+
readme: ../README.md
8+
tags: ["tools"]
9+
description: Lorem ipsum
10+
repository: https://www.github.com/my_org/my_collection
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
requires_ansible: ">=2.20"

examples/collections/broken_no_repo/CHANGELOG.md

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: broken_no_repo
3+
namespace: fixtures
4+
version: 1.2.3
5+
authors:
6+
- John
7+
readme: ../README.md
8+
tags: ["tools"]
9+
description: Lorem ipsum
10+
license:
11+
- MIT
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
requires_ansible: ">=2.20"

examples/collections/broken_no_runtime/galaxy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ readme: ../README.md
88
tags: ["tools"]
99
description: Lorem ipsum
1010
repository: https://www.github.com/my_org/my_collection
11+
license:
12+
- MIT

src/ansiblelint/rules/galaxy.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class GalaxyRule(AnsibleLintRule):
3636
"galaxy[version-missing]": "galaxy.yaml should have version tag.",
3737
"galaxy[no-runtime]": "meta/runtime.yml file not found.",
3838
"galaxy[invalid-dependency-version]": "Invalid collection metadata. Dependency version spec range is invalid",
39+
"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",
40+
"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",
3941
}
4042

4143
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]:
179181
),
180182
)
181183

184+
# Check for repository key - recommended for Galaxy publication
185+
if "repository" not in data:
186+
results.append(
187+
self.create_matcherror(
188+
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",
189+
tag="galaxy[no-repository]",
190+
filename=file,
191+
),
192+
)
193+
194+
# Check for license or license_file key - recommended for Galaxy publication
195+
if "license" not in data and "license_file" not in data:
196+
results.append(
197+
self.create_matcherror(
198+
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",
199+
tag="galaxy[no-license]",
200+
filename=file,
201+
),
202+
)
203+
182204
return results
183205

184206

@@ -253,6 +275,16 @@ def test_galaxy_no_collection_version() -> None:
253275
["galaxy[no-runtime]"],
254276
id="broken_no_runtime",
255277
),
278+
pytest.param(
279+
"examples/collections/broken_no_license/galaxy.yml",
280+
["galaxy[no-license]"],
281+
id="broken_no_license",
282+
),
283+
pytest.param(
284+
"examples/collections/broken_no_repo/galaxy.yml",
285+
["galaxy[no-repository]"],
286+
id="broken_no_repo",
287+
),
256288
),
257289
)
258290
def test_galaxy_rule(

src/ansiblelint/schemas/galaxy.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,7 @@
876876
"version",
877877
"readme",
878878
"authors",
879-
"description",
880-
"repository"
879+
"description"
881880
],
882881
"title": "Ansible galaxy.yml Schema",
883882
"type": "object"

0 commit comments

Comments
 (0)