build_step.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from dataclasses import dataclass
  10. from datetime import datetime
  11. @dataclass
  12. class BuildItemOutcomeBase:
  13. step_key: str
  14. build_number: int
  15. commit_hash: str
  16. created_at: datetime
  17. duration_in_min: float | None
  18. passed: bool
  19. completed: bool
  20. retry_count: int
  21. def formatted_date(self) -> str:
  22. return self.created_at.strftime("%Y-%m-%d %H:%M:%S %z")
  23. @dataclass
  24. class BuildStepOutcome(BuildItemOutcomeBase):
  25. """Outcome of an atomic build step. For sharded jobs, more than one build step exists for a job."""
  26. id: str
  27. web_url_to_job: str
  28. parallel_job_index: int | None
  29. exit_status: int | None
  30. def web_url_to_build(self) -> str:
  31. return self.web_url_to_job[: self.web_url_to_job.index("#")]
  32. @dataclass
  33. class BuildJobOutcome(BuildItemOutcomeBase):
  34. """Outcome, which aggregates multiple build steps in case of a sharded job."""
  35. ids: list[str]
  36. web_url_to_build: str
  37. # number of merged shards, 1 otherwise
  38. count_items: int
  39. @dataclass
  40. class BuildStepMatcher:
  41. step_key: str
  42. # will be ignored if not specified
  43. parallel_job_index: int | None
  44. def matches(self, job_step_key: str, job_parallel_index: int | None) -> bool:
  45. if self.step_key != job_step_key:
  46. return False
  47. if self.parallel_job_index is None:
  48. # not specified
  49. return True
  50. return self.parallel_job_index == job_parallel_index