From 8411a2d0a0f816328d47cdb21662c030b0019889 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 20 Dec 2023 14:24:56 +0000 Subject: [PATCH 1/3] Correct requires_ansible error message Related: #3950 --- .vscode/settings.json | 6 +++--- src/ansiblelint/rules/meta_runtime.md | 15 ++++----------- src/ansiblelint/rules/meta_runtime.py | 5 +++-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 93d2172075..efe4f21238 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -37,8 +37,8 @@ "evenBetterToml.formatter.alignComments": false, "[python]": { "editor.codeActionsOnSave": { - "source.organizeImports": true, - "source.fixAll": true - } + "source.organizeImports": "explicit", + "source.fixAll": "explicit" + } } } diff --git a/src/ansiblelint/rules/meta_runtime.md b/src/ansiblelint/rules/meta_runtime.md index c9284773b8..506d8b5b26 100644 --- a/src/ansiblelint/rules/meta_runtime.md +++ b/src/ansiblelint/rules/meta_runtime.md @@ -2,21 +2,14 @@ This rule checks the meta/runtime.yml `requires_ansible` key against the list of currently supported versions of ansible-core. -This rule can produce messages such: - -- `requires_ansible` key must be set to a supported version. - -Currently supported versions of ansible-core are: - -- `2.13.x` -- `2.14.x` -- `2.15.x` - This rule can produce messages such as: -- `meta-runtime[unsupported-version]` - `requires_ansible` key must contain a supported version - 2.13.x, 2.14.x, 2.15.x. +- `meta-runtime[unsupported-version]` - `requires_ansible` key must refer to a currently supported version such: >=2.14.0, >=2.15.0, >=2.16.0 - `meta-runtime[invalid-version]` - `requires_ansible` is not a valid requirement specification +Please note that the linter will allow only a full version of Ansible such `2.16.0` and not allow their short form, like `2.16`. This is a safety measure +for asking authors to mention an explicit version that they tested with. Over the years we spotted multiple problems caused by the use of the short versions, users +ended up trying an outdated version that was never tested against by the collection maintainer. ## Problematic code diff --git a/src/ansiblelint/rules/meta_runtime.py b/src/ansiblelint/rules/meta_runtime.py index 09873ddd3c..bae3673885 100644 --- a/src/ansiblelint/rules/meta_runtime.py +++ b/src/ansiblelint/rules/meta_runtime.py @@ -32,8 +32,9 @@ class CheckRequiresAnsibleVersion(AnsibleLintRule): # Refer to https://access.redhat.com/support/policy/updates/ansible-automation-platform # Also add devel to this list supported_ansible = ["2.14.", "2.15.", "2.16."] + supported_ansible_examples = [f">={x}0" for x in supported_ansible] _ids = { - "meta-runtime[unsupported-version]": "'requires_ansible' key must be set to a supported version - 2.13.x, 2.14.x, 2.15.x", + "meta-runtime[unsupported-version]": f"'requires_ansible' key must refer to a currently supported version such: {', '.join(supported_ansible_examples)}", "meta-runtime[invalid-version]": "'requires_ansible' is not a valid requirement specification", } @@ -56,7 +57,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]: ): results.append( self.create_matcherror( - message="requires_ansible key must be set to a supported version.", + message=self._ids["meta-runtime[unsupported-version]"], tag="meta-runtime[unsupported-version]", filename=file, ), From 39b1158b68ebb14dbe264d51414d61e0684adccf Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 20 Dec 2023 15:17:38 +0000 Subject: [PATCH 2/3] Update src/ansiblelint/rules/meta_runtime.py Co-authored-by: Kate Case --- src/ansiblelint/rules/meta_runtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansiblelint/rules/meta_runtime.py b/src/ansiblelint/rules/meta_runtime.py index bae3673885..1a6e62719e 100644 --- a/src/ansiblelint/rules/meta_runtime.py +++ b/src/ansiblelint/rules/meta_runtime.py @@ -34,7 +34,7 @@ class CheckRequiresAnsibleVersion(AnsibleLintRule): supported_ansible = ["2.14.", "2.15.", "2.16."] supported_ansible_examples = [f">={x}0" for x in supported_ansible] _ids = { - "meta-runtime[unsupported-version]": f"'requires_ansible' key must refer to a currently supported version such: {', '.join(supported_ansible_examples)}", + "meta-runtime[unsupported-version]": f"'requires_ansible' key must refer to a currently supported version such as: {', '.join(supported_ansible_examples)}", "meta-runtime[invalid-version]": "'requires_ansible' is not a valid requirement specification", } From fda831c4db2ef30e16a219c42ed167fc85266fdc Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 20 Dec 2023 15:17:59 +0000 Subject: [PATCH 3/3] Update src/ansiblelint/rules/meta_runtime.md Co-authored-by: Kate Case --- src/ansiblelint/rules/meta_runtime.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansiblelint/rules/meta_runtime.md b/src/ansiblelint/rules/meta_runtime.md index 506d8b5b26..fad191d8e7 100644 --- a/src/ansiblelint/rules/meta_runtime.md +++ b/src/ansiblelint/rules/meta_runtime.md @@ -4,7 +4,7 @@ This rule checks the meta/runtime.yml `requires_ansible` key against the list of This rule can produce messages such as: -- `meta-runtime[unsupported-version]` - `requires_ansible` key must refer to a currently supported version such: >=2.14.0, >=2.15.0, >=2.16.0 +- `meta-runtime[unsupported-version]` - `requires_ansible` key must refer to a currently supported version such as: >=2.14.0, >=2.15.0, >=2.16.0 - `meta-runtime[invalid-version]` - `requires_ansible` is not a valid requirement specification Please note that the linter will allow only a full version of Ansible such `2.16.0` and not allow their short form, like `2.16`. This is a safety measure