Skip to content

Commit

Permalink
Fix scenario when role has no dependencies section in `meta/main.ym…
Browse files Browse the repository at this point in the history
…l` (#3993)
  • Loading branch information
audgirka authored Jan 29, 2024
1 parent 24ac1cd commit c87060a
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 3 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Adrián
Autobuild
audgirka
CLICOLOR
CODENOTIFY
CODEOWNERS
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
env:
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 851
PYTEST_REQPASS: 852
steps:
- uses: actions/checkout@v4
with:
Expand Down
55 changes: 55 additions & 0 deletions examples/roles/test-no-deps-role/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
galaxy_info:
author: audgirka
description: your role description
company: Red Hat
role_name: test_no_deps_role # if absent directory name hosting role is used instead
namespace: foo # if absent, author is used instead

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: GPL-2.0-or-later

min_ansible_version: "2.1"

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
# Skipping deps for testing scenario when no role deps are present
# dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
18 changes: 17 additions & 1 deletion src/ansiblelint/rules/role_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
return result

if file.kind == "meta":
for role in file.data["dependencies"]:
for role in file.data.get("dependencies", []):
role_name = role["role"]
if "/" in role_name:
result.append(
Expand Down Expand Up @@ -206,3 +206,19 @@ def test_role_deps_path_names(
assert result.tag == expected_errors[idx][0]
assert result.lineno == expected_errors[idx][1]
assert len(results) == failure

@pytest.mark.parametrize(
("test_file", "failure"),
(pytest.param("examples/roles/test-no-deps-role", 0, id="no_deps"),),
)
def test_role_no_deps(
default_rules_collection: RulesCollection,
test_file: str,
failure: int,
) -> None:
"""Test role if no dependencies are present in meta/main.yml."""
results = Runner(
test_file,
rules=default_rules_collection,
).run()
assert len(results) == failure
2 changes: 1 addition & 1 deletion src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/role-arg-spec.json"
},
"rulebook": {
"etag": "8a421671574fa65a57fb0d08e45879bfa005f271aa8c0243982a84b49fb0fe54",
"etag": "baba5774a46fcc2bc8c4a8c2f25b49df64a0856e415dbf601b0559f215e55968",
"url": "https://raw.githubusercontent.com/ansible/ansible-rulebook/main/ansible_rulebook/schema/ruleset_schema.json"
},
"tasks": {
Expand Down
42 changes: 42 additions & 0 deletions src/ansiblelint/schemas/rulebook.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@
},
{
"$ref": "#/$defs/shutdown-action"
},
{
"$ref": "#/$defs/pg-notify-action"
}
]
}
Expand Down Expand Up @@ -244,6 +247,9 @@
},
{
"$ref": "#/$defs/shutdown-action"
},
{
"$ref": "#/$defs/pg-notify-action"
}
]
}
Expand Down Expand Up @@ -510,6 +516,42 @@
],
"additionalProperties": false
},
"pg-notify-action": {
"type": "object",
"properties": {
"pg_notify": {
"type": "object",
"properties": {
"dsn": {
"type": "string"
},
"channel": {
"type": "string"
},
"event": {
"type": [
"string",
"object"
]
},
"remove_meta": {
"type": "boolean",
"default": false
}
},
"required": [
"dsn",
"channel",
"event"
],
"additionalProperties": false
}
},
"required": [
"pg_notify"
],
"additionalProperties": false
},
"post-event-action": {
"type": "object",
"properties": {
Expand Down
1 change: 1 addition & 0 deletions src/ansiblelint/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,5 @@ def run_ansible_lint(
cwd=cwd,
env=_env,
text=True,
encoding="utf-8",
)

0 comments on commit c87060a

Please sign in to comment.