Skip to content

Commit

Permalink
Add new workflows to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Dec 19, 2024
1 parent ca6026e commit 8307bef
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions scripts/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
TEST_PATH_NAMES = ["integration"]


def get_now() -> datetime.datetime:
"""
Get current time.
"""
return datetime.datetime.now(datetime.timezone.utc)


@dataclass
class Workflow:
"""
Expand All @@ -33,10 +40,10 @@ class Workflow:

name: str
status: str
started_at: datetime.datetime
updated_at: datetime.datetime
branch: str
path: Path
branch: str = "-"
started_at: datetime.datetime | None = None
updated_at: datetime.datetime | None = None

@property
def check(self) -> str:
Expand All @@ -51,15 +58,18 @@ def check(self) -> str:
return "🔄"
if self.status == "failure":
return "❌"
if self.status == "new":
return "🆕"
return self.status

@property
def updated_ago(self) -> str:
"""
Time since last update.
"""
now = datetime.datetime.now(datetime.timezone.utc)
delta = now - self.started_at
if self.started_at is None:
return "never"
delta = get_now() - self.started_at
if delta.days:
return f"{delta.days} day{'s' if delta.days > 1 else '' } ago"
if delta.seconds > 60 * 60:
Expand All @@ -78,7 +88,11 @@ def duration(self) -> str:
"""
Duration.
"""
if self.started_at is None or self.updated_at is None:
return "00:00"
delta = self.updated_at - self.started_at
if self.status not in {"completed", "failure"}:
delta = get_now() - self.started_at
minutes = delta.seconds // 60
return f"{minutes:>02}:{delta.seconds % 60:>02}"

Expand Down Expand Up @@ -203,7 +217,11 @@ def get_workflow(path: Path) -> Workflow | None:
return None
response_json = json.loads(response)
if not response_json:
return None
return Workflow(
name=get_workflow_name(path),
status="new",
path=path,
)
data = response_json[0]
return Workflow(
name=get_workflow_name(path),
Expand Down

0 comments on commit 8307bef

Please sign in to comment.