Skip to content

Commit

Permalink
Build: mark build as CANCELLED when command exits with 183 (#11240)
Browse files Browse the repository at this point in the history
Closes #11232
  • Loading branch information
humitos committed Mar 26, 2024
1 parent f3fedde commit eff8744
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
DOCKER_VERSION,
RTD_SKIP_BUILD_EXIT_CODE,
)
from .exceptions import BuildAppError, BuildUserError
from .exceptions import BuildAppError, BuildCancelled, BuildUserError

log = structlog.get_logger(__name__)

Expand Down Expand Up @@ -527,7 +527,7 @@ def run_command_class(
version_slug=self.version.slug if self.version else "",
)
elif build_cmd.exit_code == RTD_SKIP_BUILD_EXIT_CODE:
raise BuildUserError(BuildUserError.SKIPPED_EXIT_CODE_183)
raise BuildCancelled(BuildCancelled.SKIPPED_EXIT_CODE_183)
else:
# TODO: for now, this still outputs a generic error message
# that is the same across all commands. We could improve this
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class BuildAppError(BuildBaseException):

class BuildUserError(BuildBaseException):
GENERIC = "build:user:generic"
SKIPPED_EXIT_CODE_183 = "build:user:exit-code-183"

BUILD_COMMANDS_WITHOUT_OUTPUT = "build:user:output:no-html"
BUILD_OUTPUT_IS_NOT_A_DIRECTORY = "build:user:output:is-no-a-directory"
Expand Down Expand Up @@ -59,6 +58,7 @@ class BuildMaxConcurrencyError(BuildUserError):

class BuildCancelled(BuildUserError):
CANCELLED_BY_USER = "build:user:cancelled"
SKIPPED_EXIT_CODE_183 = "build:user:exit-code-183"


class MkDocsYAMLParseError(BuildUserError):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/notifications/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_rendered_body(self):
type=ERROR,
),
Message(
id=BuildUserError.SKIPPED_EXIT_CODE_183,
id=BuildCancelled.SKIPPED_EXIT_CODE_183,
header=_("Build skipped."),
body=_(
textwrap.dedent(
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/projects/tasks/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class UpdateDocsTask(SyncRepositoryMixin, Task):
# Do not send notifications on failure builds for these exceptions.
exceptions_without_notifications = (
BuildCancelled.CANCELLED_BY_USER,
BuildUserError.SKIPPED_EXIT_CODE_183,
BuildCancelled.SKIPPED_EXIT_CODE_183,
BuildAppError.BUILDS_DISABLED,
BuildMaxConcurrencyError.LIMIT_REACHED,
)
Expand Down Expand Up @@ -541,7 +541,7 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
version_type = self.data.version.type

status = BUILD_STATUS_FAILURE
if message_id == BuildUserError.SKIPPED_EXIT_CODE_183:
if message_id == BuildCancelled.SKIPPED_EXIT_CODE_183:
# The build was skipped by returning the magic exit code,
# marked as CANCELLED, but communicated to GitHub as successful.
# This is because the PR has to be available for merging when the build
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
LATEST,
)
from readthedocs.builds.models import APIVersion, Build, BuildCommandResult, Version
from readthedocs.doc_builder.exceptions import BuildMaxConcurrencyError, BuildUserError
from readthedocs.doc_builder.exceptions import BuildCancelled, BuildMaxConcurrencyError
from readthedocs.integrations.models import GenericAPIWebhook, Integration
from readthedocs.notifications.constants import READ, UNREAD
from readthedocs.notifications.models import Notification
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_reset_build(self):

Notification.objects.add(
attached_to=build,
message_id=BuildUserError.SKIPPED_EXIT_CODE_183,
message_id=BuildCancelled.SKIPPED_EXIT_CODE_183,
)

self.assertEqual(build.commands.count(), 1)
Expand Down

0 comments on commit eff8744

Please sign in to comment.