Skip to content

Commit

Permalink
Build: fail builds if there is no index.html in the output dir (#10550
Browse files Browse the repository at this point in the history
)

* Build: fail builds if there is no `index.html` in the output dir

We announced we deprecated this in readthedocs/blog#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 <eric@ericholscher.com>
  • Loading branch information
humitos and ericholscher authored Jul 26, 2023
1 parent 752cfeb commit 31bd5ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
17 changes: 3 additions & 14 deletions readthedocs/projects/tasks/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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``
Expand Down

0 comments on commit 31bd5ad

Please sign in to comment.