Skip to content

Commit e003ab1

Browse files
committed
wip
1 parent 49aa2b5 commit e003ab1

3 files changed

Lines changed: 43 additions & 34 deletions

File tree

src/launchpad/artifact_processor.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from launchpad.artifacts.artifact_factory import ArtifactFactory
3535
from launchpad.constants import (
3636
ArtifactType,
37+
DistributionState,
3738
PreprodFeature,
3839
ProcessingErrorCode,
3940
ProcessingErrorMessage,
@@ -304,23 +305,11 @@ def _do_distribution(
304305
apple_info = cast(AppleAppInfo, info)
305306
if not apple_info.is_code_signature_valid:
306307
logger.warning(f"BUILD_DISTRIBUTION skipped for {artifact_id}: invalid code signature")
307-
self._update_artifact_error(
308-
organization_id,
309-
project_id,
310-
artifact_id,
311-
ProcessingErrorCode.ARTIFACT_PROCESSING_ERROR,
312-
ProcessingErrorMessage.INVALID_CODE_SIGNATURE,
313-
)
308+
self._update_distribution_skip(organization_id, project_id, artifact_id, "invalid_signature")
314309
return
315310
if apple_info.is_simulator:
316311
logger.warning(f"BUILD_DISTRIBUTION skipped for {artifact_id}: simulator build")
317-
self._update_artifact_error(
318-
organization_id,
319-
project_id,
320-
artifact_id,
321-
ProcessingErrorCode.ARTIFACT_PROCESSING_ERROR,
322-
ProcessingErrorMessage.SIMULATOR_BUILD,
323-
)
312+
self._update_distribution_skip(organization_id, project_id, artifact_id, "simulator")
324313
return
325314
with tempfile.TemporaryDirectory() as temp_dir_str:
326315
temp_dir = Path(temp_dir_str)
@@ -345,14 +334,8 @@ def _do_distribution(
345334
with apk.raw_file() as f:
346335
self._sentry_client.upload_installable_app(organization_id, project_id, artifact_id, f)
347336
else:
348-
logger.error(f"BUILD_DISTRIBUTION failed for {artifact_id} (project: {project_id}, org: {organization_id})")
349-
self._update_artifact_error(
350-
organization_id,
351-
project_id,
352-
artifact_id,
353-
ProcessingErrorCode.ARTIFACT_PROCESSING_ERROR,
354-
ProcessingErrorMessage.UNSUPPORTED_ARTIFACT_TYPE,
355-
)
337+
logger.error(f"BUILD_DISTRIBUTION failed for {artifact_id}: unsupported artifact type")
338+
self._update_distribution_skip(organization_id, project_id, artifact_id, "unsupported")
356339

357340
def _do_size(
358341
self,
@@ -434,6 +417,27 @@ def _update_artifact_error(
434417
else:
435418
logger.info(f"Successfully updated artifact {artifact_id} with error information")
436419

420+
def _update_distribution_skip(
421+
self,
422+
organization_id: str,
423+
project_id: str,
424+
artifact_id: str,
425+
skip_reason: str,
426+
) -> None:
427+
"""Update artifact with distribution skip state."""
428+
try:
429+
self._sentry_client.update_artifact(
430+
org=organization_id,
431+
project=project_id,
432+
artifact_id=artifact_id,
433+
data={
434+
"distribution_state": DistributionState.NOT_RAN.value,
435+
"distribution_skip_reason": skip_reason,
436+
},
437+
)
438+
except SentryClientError:
439+
logger.exception(f"Failed to update distribution skip for artifact {artifact_id}")
440+
437441
def _update_size_error_from_exception(
438442
self,
439443
organization_id: str,

src/launchpad/constants.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class PreprodFeature(Enum):
3232
BUILD_DISTRIBUTION = "build_distribution"
3333

3434

35+
# Matches PreprodArtifact.DistributionState in sentry
36+
class DistributionState(Enum):
37+
PENDING = 0
38+
COMPLETED = 1
39+
NOT_RAN = 2
40+
41+
3542
# Health check threshold - consider unhealthy if file not touched in 60 seconds
3643
HEALTHCHECK_MAX_AGE_SECONDS = 60.0
3744

@@ -49,8 +56,6 @@ class ProcessingErrorMessage(Enum):
4956
SIZE_ANALYSIS_FAILED = "Failed to perform size analysis"
5057
ARTIFACT_PARSING_FAILED = "Failed to parse artifact file"
5158
UNSUPPORTED_ARTIFACT_TYPE = "Unsupported artifact type"
52-
INVALID_CODE_SIGNATURE = "Cannot distribute app with invalid code signature"
53-
SIMULATOR_BUILD = "Cannot distribute simulator builds"
5459

5560
# System-related errors
5661
TEMP_FILE_CREATION_FAILED = "Failed to create temporary file"

tests/unit/artifacts/test_artifact_processor.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from launchpad.artifacts.apple.zipped_xcarchive import ZippedXCArchive
1010
from launchpad.artifacts.artifact import Artifact
1111
from launchpad.constants import (
12+
DistributionState,
1213
ProcessingErrorCode,
1314
ProcessingErrorMessage,
1415
)
@@ -139,8 +140,7 @@ def test_processing_error_message_enum_values(self):
139140
assert ProcessingErrorMessage.SIZE_ANALYSIS_FAILED.value == "Failed to perform size analysis"
140141
assert ProcessingErrorMessage.UNKNOWN_ERROR.value == "An unknown error occurred"
141142

142-
def test_do_distribution_unknown_artifact_type_reports_error(self):
143-
"""Test that _do_distribution reports an error for unknown artifact types."""
143+
def test_do_distribution_unknown_artifact_type_skips(self):
144144
mock_sentry_client = Mock(spec=SentryClient)
145145
mock_sentry_client.update_artifact.return_value = None
146146
self.processor._sentry_client = mock_sentry_client
@@ -157,12 +157,12 @@ def test_do_distribution_unknown_artifact_type_reports_error(self):
157157
project="test-project-id",
158158
artifact_id="test-artifact-id",
159159
data={
160-
"error_code": ProcessingErrorCode.ARTIFACT_PROCESSING_ERROR.value,
161-
"error_message": ProcessingErrorMessage.UNSUPPORTED_ARTIFACT_TYPE.value,
160+
"distribution_state": DistributionState.NOT_RAN.value,
161+
"distribution_skip_reason": "unsupported",
162162
},
163163
)
164164

165-
def test_do_distribution_invalid_code_signature_reports_error(self):
165+
def test_do_distribution_invalid_code_signature_skips(self):
166166
mock_sentry_client = Mock(spec=SentryClient)
167167
mock_sentry_client.update_artifact.return_value = None
168168
self.processor._sentry_client = mock_sentry_client
@@ -179,13 +179,13 @@ def test_do_distribution_invalid_code_signature_reports_error(self):
179179
project="test-project-id",
180180
artifact_id="test-artifact-id",
181181
data={
182-
"error_code": ProcessingErrorCode.ARTIFACT_PROCESSING_ERROR.value,
183-
"error_message": ProcessingErrorMessage.INVALID_CODE_SIGNATURE.value,
182+
"distribution_state": DistributionState.NOT_RAN.value,
183+
"distribution_skip_reason": "invalid_signature",
184184
},
185185
)
186186
mock_sentry_client.upload_installable_app.assert_not_called()
187187

188-
def test_do_distribution_simulator_build_reports_error(self):
188+
def test_do_distribution_simulator_build_skips(self):
189189
mock_sentry_client = Mock(spec=SentryClient)
190190
mock_sentry_client.update_artifact.return_value = None
191191
self.processor._sentry_client = mock_sentry_client
@@ -202,8 +202,8 @@ def test_do_distribution_simulator_build_reports_error(self):
202202
project="test-project-id",
203203
artifact_id="test-artifact-id",
204204
data={
205-
"error_code": ProcessingErrorCode.ARTIFACT_PROCESSING_ERROR.value,
206-
"error_message": ProcessingErrorMessage.SIMULATOR_BUILD.value,
205+
"distribution_state": DistributionState.NOT_RAN.value,
206+
"distribution_skip_reason": "simulator",
207207
},
208208
)
209209
mock_sentry_client.upload_installable_app.assert_not_called()

0 commit comments

Comments
 (0)