From 31bd5ad658132fe0b1bbbdf422887ac6d57b13a4 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 26 Jul 2023 13:36:54 +0200 Subject: [PATCH] Build: fail builds if there is no `index.html` in the output dir (#10550) * Build: fail builds if there is no `index.html` in the output dir We announced we deprecated this in https://github.com/readthedocs/blog/pull/230/ and we already contacted the users to warn about this. This PR has to be merged after July 25th, 2023 and it has to be deployed on August 1st. Closes #1800 * Test: create an "index.html" to run build successfully --------- Co-authored-by: Eric Holscher --- readthedocs/projects/tasks/builds.py | 17 +++-------------- readthedocs/projects/tests/test_build_tasks.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/readthedocs/projects/tasks/builds.py b/readthedocs/projects/tasks/builds.py index 41d79b11c9d..9e409f91263 100644 --- a/readthedocs/projects/tasks/builds.py +++ b/readthedocs/projects/tasks/builds.py @@ -574,24 +574,13 @@ def get_valid_artifact_types(self): if artifact_type == "html": index_html_filepath = os.path.join(artifact_directory, "index.html") - readme_html_filepath = os.path.join(artifact_directory, "README.html") - if not os.path.exists(index_html_filepath) and not os.path.exists( - readme_html_filepath - ): - log.warning( + if not os.path.exists(index_html_filepath): + log.info( "Failing the build. " "HTML output does not contain an 'index.html' at its root directory.", index_html=index_html_filepath, - readme_html=readme_html_filepath, ) - # TODO: uncomment this line to fail the build once we have - # communicated with projects without an index.html or - # README.html - # - # NOTE: we want to deprecate serving README.html as an - # index.html file as well. - # - # raise BuildUserError(BuildUserError.BUILD_OUTPUT_HTML_NO_INDEX_FILE) + raise BuildUserError(BuildUserError.BUILD_OUTPUT_HTML_NO_INDEX_FILE) if not os.path.exists(artifact_directory): # There is no output directory. diff --git a/readthedocs/projects/tests/test_build_tasks.py b/readthedocs/projects/tests/test_build_tasks.py index a69f9c19b6c..547da8c42e3 100644 --- a/readthedocs/projects/tests/test_build_tasks.py +++ b/readthedocs/projects/tests/test_build_tasks.py @@ -294,6 +294,14 @@ def test_build_updates_documentation_type(self, load_yaml_config): ) ).touch() + # Create an "index.html" at root to avoid failing the builds + pathlib.Path( + os.path.join( + self.project.artifact_path(version=self.version.slug, type_="html"), + "index.html", + ) + ).touch() + self._trigger_update_docs_task() # Update version state @@ -438,6 +446,14 @@ def test_successful_build( ) ).touch() + # Create an "index.html" at root to avoid failing the builds + pathlib.Path( + os.path.join( + self.project.artifact_path(version=self.version.slug, type_="html"), + "index.html", + ) + ).touch() + self._trigger_update_docs_task() # It has to be called twice, ``before_start`` and ``after_return``