Skip to content

Commit 7e5d475

Browse files
authored
fix: Handle slashes in the Action step's name (#5)
* fix: properly handle slashes in the step name * add changelog * build a file path more robust
1 parent 318edad commit 7e5d475

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
## 3.3.0 (2025-08-27)
44

55
* [feat] Publish new action to be used by Coralogix integration
6+
7+
## 3.3.1 (2026-03-04)
8+
9+
* [fix] Handle slashes in the Action step's name

src/exporter.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@
144144
with zipfile.ZipFile("log.zip", 'r') as zip_ref:
145145
zip_ref.extractall("./logs")
146146

147+
148+
def _log_path_for_step(logs_dir: str, job_name: str, step_number: int, step_name: str, sanitize_slashes: bool = False) -> str:
149+
"""Build log file path. If sanitize_slashes, replace '/' with '_' (GitHub zip may sanitize names)."""
150+
j = str(job_name).replace("/", "_") if sanitize_slashes else str(job_name)
151+
s = str(step_name).replace("/", "_") if sanitize_slashes else str(step_name)
152+
return f"{logs_dir}{j}/{step_number}_{s}.txt"
153+
147154
# Jobs trace span
148155
# Set Jobs tracer and logger
149156
pcontext = trace.set_span_in_context(p_parent)
@@ -200,7 +207,18 @@
200207
with trace.use_span(child_1, end_on_exit=False):
201208
# Parse logs
202209
try:
203-
with open ("./logs/"+str(job["name"]).replace("/", "")+"/"+str(step['number'])+"_"+str(step['name'].replace("/",""))+".txt") as f:
210+
# Try exact API names first; then try with '/' replaced by '_' (GitHub zip may sanitize names)
211+
log_path = None
212+
for sanitize in (False, True):
213+
candidate = _log_path_for_step("./logs/", job["name"], step['number'], step['name'], sanitize_slashes=sanitize)
214+
if os.path.isfile(candidate):
215+
log_path = candidate
216+
break
217+
if log_path is None:
218+
raise FileNotFoundError(
219+
_log_path_for_step("", job["name"], step['number'], step['name'], sanitize_slashes=False).lstrip("/")
220+
)
221+
with open(log_path) as f:
204222
for line in f.readlines():
205223
try:
206224
line_to_add = line[29:-1].strip()
@@ -236,7 +254,7 @@
236254
print("Log file not expected for this step ->",step['name'],"<- because its status is ->",step['conclusion'])
237255
pass #We don't expect log file to exist
238256
else:
239-
print("ERROR: Log file does not exist: "+str(job["name"]).replace("/", "")+"/"+str(step['number'])+"_"+str(step['name'].replace("/",""))+".txt")
257+
print("ERROR: Log file does not exist: "+str(job["name"])+"/"+str(step['number'])+"_"+str(step['name'])+".txt")
240258

241259

242260
if step['conclusion'] == 'skipped' or step['conclusion'] == 'cancelled':

0 commit comments

Comments
 (0)