Skip to content

Commit

Permalink
Updating changelog check to include the docs/ dir (#264)
Browse files Browse the repository at this point in the history
Issue: AAH-3083
  • Loading branch information
alisonlhart authored Feb 6, 2024
1 parent d4b5e6d commit 6b7b7fc
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGES/3083.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expand changelog check to the docs/ dir and add config option (default=True)
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,17 @@ 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

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.
1 change: 1 addition & 0 deletions galaxy_importer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 22 additions & 12 deletions galaxy_importer/loaders/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 18 additions & 4 deletions tests/unit/test_loader_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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,
),
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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])
)


Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_loader_doc_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from galaxy_importer import loaders


ANSIBLE_DOC_OUTPUT = json.loads("""
ANSIBLE_DOC_OUTPUT = json.loads(
"""
{
"my_module": {
"return": {
Expand All @@ -38,7 +39,8 @@
}
}
}
""")
"""
)


@pytest.fixture
Expand Down Expand Up @@ -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("")

Expand Down

0 comments on commit 6b7b7fc

Please sign in to comment.