Skip to content

Commit c87060a

Browse files
authored
Fix scenario when role has no dependencies section in meta/main.yml (#3993)
1 parent 24ac1cd commit c87060a

File tree

7 files changed

+118
-3
lines changed

7 files changed

+118
-3
lines changed

.config/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Adrián
22
Autobuild
3+
audgirka
34
CLICOLOR
45
CODENOTIFY
56
CODEOWNERS

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
env:
7070
# Number of expected test passes, safety measure for accidental skip of
7171
# tests. Update value if you add/remove tests.
72-
PYTEST_REQPASS: 851
72+
PYTEST_REQPASS: 852
7373
steps:
7474
- uses: actions/checkout@v4
7575
with:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
galaxy_info:
3+
author: audgirka
4+
description: your role description
5+
company: Red Hat
6+
role_name: test_no_deps_role # if absent directory name hosting role is used instead
7+
namespace: foo # if absent, author is used instead
8+
9+
# If the issue tracker for your role is not on github, uncomment the
10+
# next line and provide a value
11+
# issue_tracker_url: http://example.com/issue/tracker
12+
13+
# Choose a valid license ID from https://spdx.org - some suggested licenses:
14+
# - BSD-3-Clause (default)
15+
# - MIT
16+
# - GPL-2.0-or-later
17+
# - GPL-3.0-only
18+
# - Apache-2.0
19+
# - CC-BY-4.0
20+
license: GPL-2.0-or-later
21+
22+
min_ansible_version: "2.1"
23+
24+
# If this a Container Enabled role, provide the minimum Ansible Container version.
25+
# min_ansible_container_version:
26+
27+
#
28+
# Provide a list of supported platforms, and for each platform a list of versions.
29+
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
30+
# To view available platforms and versions (or releases), visit:
31+
# https://galaxy.ansible.com/api/v1/platforms/
32+
#
33+
# platforms:
34+
# - name: Fedora
35+
# versions:
36+
# - all
37+
# - 25
38+
# - name: SomePlatform
39+
# versions:
40+
# - all
41+
# - 1.0
42+
# - 7
43+
# - 99.99
44+
45+
galaxy_tags: []
46+
# List tags for your role here, one per line. A tag is a keyword that describes
47+
# and categorizes the role. Users find roles by searching for tags. Be sure to
48+
# remove the '[]' above, if you add tags to this list.
49+
#
50+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
51+
# Maximum 20 tags per role.
52+
# Skipping deps for testing scenario when no role deps are present
53+
# dependencies: []
54+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
55+
# if you add dependencies to this list.

src/ansiblelint/rules/role_name.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
9595
return result
9696

9797
if file.kind == "meta":
98-
for role in file.data["dependencies"]:
98+
for role in file.data.get("dependencies", []):
9999
role_name = role["role"]
100100
if "/" in role_name:
101101
result.append(
@@ -206,3 +206,19 @@ def test_role_deps_path_names(
206206
assert result.tag == expected_errors[idx][0]
207207
assert result.lineno == expected_errors[idx][1]
208208
assert len(results) == failure
209+
210+
@pytest.mark.parametrize(
211+
("test_file", "failure"),
212+
(pytest.param("examples/roles/test-no-deps-role", 0, id="no_deps"),),
213+
)
214+
def test_role_no_deps(
215+
default_rules_collection: RulesCollection,
216+
test_file: str,
217+
failure: int,
218+
) -> None:
219+
"""Test role if no dependencies are present in meta/main.yml."""
220+
results = Runner(
221+
test_file,
222+
rules=default_rules_collection,
223+
).run()
224+
assert len(results) == failure

src/ansiblelint/schemas/__store__.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/role-arg-spec.json"
4949
},
5050
"rulebook": {
51-
"etag": "8a421671574fa65a57fb0d08e45879bfa005f271aa8c0243982a84b49fb0fe54",
51+
"etag": "baba5774a46fcc2bc8c4a8c2f25b49df64a0856e415dbf601b0559f215e55968",
5252
"url": "https://raw.githubusercontent.com/ansible/ansible-rulebook/main/ansible_rulebook/schema/ruleset_schema.json"
5353
},
5454
"tasks": {

src/ansiblelint/schemas/rulebook.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@
206206
},
207207
{
208208
"$ref": "#/$defs/shutdown-action"
209+
},
210+
{
211+
"$ref": "#/$defs/pg-notify-action"
209212
}
210213
]
211214
}
@@ -244,6 +247,9 @@
244247
},
245248
{
246249
"$ref": "#/$defs/shutdown-action"
250+
},
251+
{
252+
"$ref": "#/$defs/pg-notify-action"
247253
}
248254
]
249255
}
@@ -510,6 +516,42 @@
510516
],
511517
"additionalProperties": false
512518
},
519+
"pg-notify-action": {
520+
"type": "object",
521+
"properties": {
522+
"pg_notify": {
523+
"type": "object",
524+
"properties": {
525+
"dsn": {
526+
"type": "string"
527+
},
528+
"channel": {
529+
"type": "string"
530+
},
531+
"event": {
532+
"type": [
533+
"string",
534+
"object"
535+
]
536+
},
537+
"remove_meta": {
538+
"type": "boolean",
539+
"default": false
540+
}
541+
},
542+
"required": [
543+
"dsn",
544+
"channel",
545+
"event"
546+
],
547+
"additionalProperties": false
548+
}
549+
},
550+
"required": [
551+
"pg_notify"
552+
],
553+
"additionalProperties": false
554+
},
513555
"post-event-action": {
514556
"type": "object",
515557
"properties": {

src/ansiblelint/testing/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,5 @@ def run_ansible_lint(
155155
cwd=cwd,
156156
env=_env,
157157
text=True,
158+
encoding="utf-8",
158159
)

0 commit comments

Comments
 (0)