Skip to content

Commit

Permalink
Fix incorrect email being sent out of build complete/fail. (#70)
Browse files Browse the repository at this point in the history
* The builder uploads the build.log on a success as well as failure, so we shouldn't break after reading the build log in case there's also a module file to be noticed (indicating a success, instead of a failure).

* Fix cache updating.

* Add 'SoftPack' to email subject.
  • Loading branch information
mjkw31 authored Nov 15, 2024
1 parent 774c0f1 commit 3ce70c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
37 changes: 18 additions & 19 deletions softpack_core/schemas/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,7 @@ def create(cls, env: EnvironmentInput) -> CreateResponse: # type: ignore
if not isinstance(response, CreateEnvironmentSuccess):
return response

environment = Environment.get_env(Path(env.path), env.name)
if environment is not None:
cls.insert_new_env(environment)
else:
return EnvironmentNotFoundError(path=env.path, name=env.name)
Environment.update_cache(Path(env.path, env.name))

builder_response = cls.submit_env_to_builder(env)
if builder_response is not None:
Expand Down Expand Up @@ -779,9 +775,7 @@ def delete(cls, name: str, path: str) -> DeleteResponse: # type: ignore
tree_oid = artifacts.delete_environment(name, path)
artifacts.commit_and_push(tree_oid, "delete environment")

index = cls.env_index_from_path(str(Path(path, name)))
if index is not None:
del Environment.environments[index]
Environment.update_cache(Path(path, name))

return DeleteEnvironmentSuccess(
message="Successfully deleted the environment"
Expand Down Expand Up @@ -958,17 +952,7 @@ async def write_artifacts(
)
artifacts.commit_and_push(tree_oid, commitMsg)

index = cls.env_index_from_path(str(folder_path))
path = Path(folder_path)
env = Environment.get_env(path.parent, path.name)

if index is None:
if env:
Environment.insert_new_env(env)
elif env:
Environment.environments[index] = env
else:
del Environment.environments[index]
Environment.update_cache(folder_path)

return WriteArtifactSuccess(
message="Successfully written artifact(s)",
Expand All @@ -978,6 +962,21 @@ async def write_artifacts(
error="".join(format_exception_only(type(e), e))
)

@classmethod
def update_cache(cls, folder_path: str | Path) -> None:
"""Regenerate the cached environment specified by the path."""
index = cls.env_index_from_path(str(folder_path))
path = Path(folder_path)
env = Environment.get_env(path.parent, path.name)

if index is None:
if env:
Environment.insert_new_env(env)
elif env:
Environment.environments[index] = env
else:
del Environment.environments[index]

@classmethod
def env_index_from_path(cls, folder_path: str) -> Optional[int]:
"""Return the index of a folder_path from the list of environments."""
Expand Down
6 changes: 2 additions & 4 deletions softpack_core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ async def upload_artifacts( # type: ignore[no-untyped-def]

files[i] = (f.filename, contents)

break

if f.filename == artifacts.module_file:
newState = State.ready

Expand Down Expand Up @@ -183,9 +181,9 @@ async def upload_artifacts( # type: ignore[no-untyped-def]
)

subject = (
"Your environment is ready!"
"Your SoftPack environment is ready!"
if newState == State.ready
else "Your environment failed to build"
else "Your SoftPack environment failed to build"
)

send_email(
Expand Down
12 changes: 9 additions & 3 deletions tests/integration/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ async def test_email_on_build_complete(
assert send_email.call_args[0][0] == app.settings.environments
assert "built sucessfully" in send_email.call_args[0][1]
assert "The error was" not in send_email.call_args[0][1]
assert send_email.call_args[0][2] == "Your environment is ready!"
assert send_email.call_args[0][2] == "Your SoftPack environment is ready!"
assert send_email.call_args[0][3] == "me"

client = TestClient(app.router)
Expand Down Expand Up @@ -441,7 +441,10 @@ async def test_email_on_build_complete(
"The error was a build error. Contact your softpack administrator."
in send_email.call_args[0][1]
)
assert send_email.call_args[0][2] == "Your environment failed to build"
assert (
send_email.call_args[0][2]
== "Your SoftPack environment failed to build"
)
assert send_email.call_args[0][3] == "me"

testable_env_input.username = ""
Expand Down Expand Up @@ -492,7 +495,10 @@ async def test_email_on_build_complete(
assert send_email.call_args[0][0] == app.settings.environments
assert "failed to build" in send_email.call_args[0][1]
assert "version conflict" in send_email.call_args[0][1]
assert send_email.call_args[0][2] == "Your environment failed to build"
assert (
send_email.call_args[0][2]
== "Your SoftPack environment failed to build"
)
assert send_email.call_args[0][3] == "me"


Expand Down

0 comments on commit 3ce70c8

Please sign in to comment.