Skip to content

Commit 496b48c

Browse files
Fix: Comparison can be timezone aware (#10)
* push with minimal changes * change to safe_yaml
1 parent c0dd752 commit 496b48c

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

gha_cli/cli.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import os
44
from collections import namedtuple
5-
from datetime import datetime
5+
from datetime import datetime, timezone
66
from typing import Optional, List, Set, Dict, Union, Any, Tuple
77

88
import click
@@ -83,7 +83,11 @@ def get_action_latest_release(self, uses_tag_value: str) -> Optional[str]:
8383
logging.debug(f"Found in cache {action_name}: {latest_release}")
8484
if _is_sha(current_version):
8585
logging.debug(f"Current version for {action_name} is a SHA: {current_version}, checking whether latest release is newer")
86-
if latest_release[1] > datetime.now():
86+
now = datetime.now(timezone.utc)
87+
release_time = latest_release[1]
88+
if release_time.tzinfo is None:
89+
release_time = release_time.replace(tzinfo=timezone.utc)
90+
if release_time > now:
8791
return latest_release[0]
8892
return latest_release[0] if self._compare_versions(latest_release[0], current_version) > 0 else None
8993

@@ -126,7 +130,7 @@ def list_full_paths(path: str) -> set[str]:
126130

127131
def get_workflow_action_names(self, repo_name: str, workflow_path: str) -> Set[str]:
128132
workflow_content = self._get_workflow_file_content(repo_name, workflow_path)
129-
workflow = yaml.load(workflow_content, Loader=yaml.CLoader)
133+
workflow = yaml.safe_load(workflow_content)
130134
res = set()
131135
for job in workflow.get("jobs", dict()).values():
132136
for step in job.get("steps", list()):
@@ -149,7 +153,7 @@ def get_repo_actions_latest(self, repo_name: str) -> Dict[str, List[ActionVersio
149153
if "@" not in action:
150154
continue
151155
all_actions_no_version.add(action.split("@")[0])
152-
logging.info(f"Found {len(all_actions_no_version)} actions in workflows: {", ".join(all_actions_no_version)}")
156+
logging.info(f"Found {len(all_actions_no_version)} actions in workflows: {', '.join(all_actions_no_version)}")
153157
for path, actions in actions_per_path.items():
154158
for action in actions:
155159
if "@" not in action:
@@ -165,7 +169,7 @@ def get_repo_workflow_names(self, repo_name: str) -> Dict[str, str]:
165169
for path in workflow_paths:
166170
try:
167171
content = self._get_workflow_file_content(repo_name, path)
168-
yaml_content = yaml.load(content, Loader=yaml.CLoader)
172+
yaml_content = yaml.safe_load(content)
169173
res[path] = yaml_content.get("name", path)
170174
except FileNotFoundError as ex:
171175
logging.warning(ex)

0 commit comments

Comments
 (0)