From 6b7b7fcf75805f0bfdadd88d680ec5f1850c1351 Mon Sep 17 00:00:00 2001 From: Alison Hart Date: Tue, 6 Feb 2024 11:19:46 -0500 Subject: [PATCH] Updating changelog check to include the docs/ dir (#264) Issue: AAH-3083 --- CHANGES/3083.feature | 1 + README.md | 7 ++++++ galaxy_importer/config.py | 1 + galaxy_importer/loaders/collection.py | 34 +++++++++++++++++---------- tests/unit/test_config.py | 1 + tests/unit/test_loader_collection.py | 22 +++++++++++++---- tests/unit/test_loader_doc_string.py | 7 +++--- 7 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 CHANGES/3083.feature diff --git a/CHANGES/3083.feature b/CHANGES/3083.feature new file mode 100644 index 00000000..43e4eeff --- /dev/null +++ b/CHANGES/3083.feature @@ -0,0 +1 @@ +Expand changelog check to the docs/ dir and add config option (default=True) \ No newline at end of file diff --git a/README.md b/README.md index ff177887..53541105 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ ANSIBLE_LOCAL_TMP = '~/.ansible/tmp' - `LOCAL_IMAGE_DOCKER` - Set to `True` to run the `ansible-test` container image via Docker; otherwise, Podman will be used. Defaults to `False`. +- `CHECK_CHANGELOG` - Set to `False` to not check for a `CHANGELOG.rst or` `CHANGELOG.md` file under the collection root or `docs/` dir, or a `changelogs/changelog.yml` file. Defaults to `True`. + ### Issues and Process @@ -78,3 +80,8 @@ ANSIBLE_LOCAL_TMP = '~/.ansible/tmp' To file an issue, visit the [Automation Hub Jira project](https://issues.redhat.com/projects/AAH/issues) Process details for `galaxy-importer`: [PROCESS.md](PROCESS.md) + + +### Additional Notes + +Place `.md` files in the `docs/` dir to have them show up in an imported collection's "Documentation" tab on Galaxy or Automation Hub. \ No newline at end of file diff --git a/galaxy_importer/config.py b/galaxy_importer/config.py index dd598f8a..e248f286 100644 --- a/galaxy_importer/config.py +++ b/galaxy_importer/config.py @@ -43,6 +43,7 @@ class Config(object): DEFAULTS = { "ansible_local_tmp": "~/.ansible/tmp", "ansible_test_local_image": False, + "check_changelog": True, "check_required_tags": False, "infra_osd": False, "local_image_docker": False, diff --git a/galaxy_importer/loaders/collection.py b/galaxy_importer/loaders/collection.py index e8be9cd4..cec8445d 100644 --- a/galaxy_importer/loaders/collection.py +++ b/galaxy_importer/loaders/collection.py @@ -103,7 +103,9 @@ def load(self): self.docs_blob = self._build_docs_blob() self.requires_ansible = file_parser.RuntimeFileParser(self.path).get_requires_ansible() self._check_ee_yml_dep_files() - self._check_collection_changelog() + + if self.cfg.check_changelog: + self._check_collection_changelog() if self.cfg.run_ansible_lint: self._lint_collection() @@ -204,19 +206,27 @@ def _check_ansible_test_ignore_files(self): # pragma: no cover self.log.warning(IGNORE_WARNING.format(file=ignore_file, line_count=line_count)) def _check_collection_changelog(self): - """Log an error when a CHANGELOG file is not present in the root of the collection.""" - changelog_rst_path = os.path.join(self.path, "CHANGELOG.rst") - changelog_md_path = os.path.join(self.path, "CHANGELOG.md") - changelog_yaml_path = os.path.join(self.path, "changelogs/changelog.yaml") - - if ( - not os.path.exists(changelog_rst_path) - and not os.path.exists(changelog_md_path) - and not os.path.exists(changelog_yaml_path) - ): + """Log an error when a CHANGELOG file is not present in the root" + " or docs/ dir of the collection.""" + changelog = False + changelog_paths = [ + "CHANGELOG.rst", + "CHANGELOG.md", + "docs/CHANGELOG.md", + "docs/CHANGELOG.rst", + "changelogs/changelog.yaml", + ] + + for log_path in changelog_paths: + full_path = os.path.join(self.path, log_path) + if os.path.exists(full_path): + changelog = True + + if not changelog: self.log.warning( "No changelog found. " - "Add a CHANGELOG.rst, CHANGELOG.md, or changelogs/changelog.yaml file." + "Add a CHANGELOG.rst or CHANGELOG.md file in the collection root " + "or docs/ dir, or a changelogs/changelog.yaml file." ) def _check_ee_yml_dep_files(self): # pragma: no cover diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index e5e0e506..94843254 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -57,6 +57,7 @@ def test_config_set_from_file(temp_config_file): assert cfg.log_level_main == "INFO" assert cfg.run_ansible_test is True assert cfg.ansible_test_local_image is True + assert cfg.check_changelog is True assert cfg.local_image_docker is True assert cfg.infra_osd is False assert cfg.tmp_root_dir == "/tmp" diff --git a/tests/unit/test_loader_collection.py b/tests/unit/test_loader_collection.py index fd6feace..fc1fbbbe 100644 --- a/tests/unit/test_loader_collection.py +++ b/tests/unit/test_loader_collection.py @@ -207,6 +207,7 @@ def test_manifest_success(_build_docs_blob, populated_collection_root): cfg=SimpleNamespace( run_ansible_doc=True, run_ansible_lint=False, + check_changelog=False, ansible_local_tmp=populated_collection_root, ), ).load() @@ -382,6 +383,7 @@ def test_filename_empty_value(_build_docs_blob, populated_collection_root): cfg=SimpleNamespace( run_ansible_doc=True, run_ansible_lint=False, + check_changelog=False, ansible_local_tmp=populated_collection_root, ), ).load() @@ -400,6 +402,7 @@ def test_filename_none(_build_docs_blob, populated_collection_root): filename, cfg=SimpleNamespace( run_ansible_doc=True, + check_changelog=False, run_ansible_lint=False, ansible_local_tmp=populated_collection_root, ), @@ -428,6 +431,7 @@ def test_license_file(populated_collection_root): cfg=SimpleNamespace( run_ansible_doc=True, run_ansible_lint=False, + check_changelog=False, ansible_local_tmp=populated_collection_root, ), ).load() @@ -446,7 +450,14 @@ def test_missing_readme(populated_collection_root): @pytest.mark.parametrize( - "changelog_path", ["CHANGELOG.rst", "CHANGELOG.md", "changelogs/changelog.yaml"] + "changelog_path", + [ + "CHANGELOG.rst", + "docs/CHANGELOG.rst", + "docs/CHANGELOG.md", + "CHANGELOG.md", + "changelogs/changelog.yaml", + ], ) def test_changelog(changelog_path, tmpdir, caplog): dirname = os.path.dirname(changelog_path) @@ -472,13 +483,14 @@ def test_changelog_fail(_build_docs_blob, populated_collection_root, caplog): cfg=SimpleNamespace( run_ansible_doc=True, run_ansible_lint=False, + check_changelog=True, ansible_local_tmp=populated_collection_root, ), ).load() assert ( "No changelog found. " - "Add a CHANGELOG.rst, CHANGELOG.md, or changelogs/changelog.yaml file." - in str(caplog.records[0]) + "Add a CHANGELOG.rst or CHANGELOG.md file in the collection root or docs/ dir, or a " + "changelogs/changelog.yaml file." in str(caplog.records[0]) ) @@ -554,6 +566,7 @@ def test_ansiblelint_playbook_errors(populated_collection_root, tmp_collection_r cfg=SimpleNamespace( run_ansible_doc=False, run_ansible_lint=True, + check_changelog=False, offline_ansible_lint=True, ansible_local_tmp=tmp_collection_root, ), @@ -587,13 +600,14 @@ def test_ansiblelint_true_loader(populated_collection_root, tmp_collection_root, cfg=SimpleNamespace( run_ansible_doc=False, run_ansible_lint=True, + check_changelog=False, offline_ansible_lint=True, ansible_local_tmp=tmp_collection_root, ), ) collection_loader.load() - assert len(caplog.records) == 1 # Changelog error expected + assert len(caplog.records) == 0 def test_ansiblelint_collection_role_errors(populated_collection_root, tmp_collection_root, caplog): diff --git a/tests/unit/test_loader_doc_string.py b/tests/unit/test_loader_doc_string.py index 3aca0b61..a7b67db3 100644 --- a/tests/unit/test_loader_doc_string.py +++ b/tests/unit/test_loader_doc_string.py @@ -24,7 +24,8 @@ from galaxy_importer import loaders -ANSIBLE_DOC_OUTPUT = json.loads(""" +ANSIBLE_DOC_OUTPUT = json.loads( + """ { "my_module": { "return": { @@ -38,7 +39,8 @@ } } } -""") +""" +) @pytest.fixture @@ -370,7 +372,6 @@ def test_transform_doc_strings_nested_suboptions(doc_string_loader): def test_load_function( mocked_run_ansible_doc_list, mocked_run_ansible_doc, doc_string_loader, tmpdir ): - doc_string_loader.path = str(tmpdir) tmpdir.mkdir("plugins").mkdir("modules").join("my_module.py").write("")