|
144 | 144 | with zipfile.ZipFile("log.zip", 'r') as zip_ref: |
145 | 145 | zip_ref.extractall("./logs") |
146 | 146 |
|
| 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 | + |
147 | 154 | # Jobs trace span |
148 | 155 | # Set Jobs tracer and logger |
149 | 156 | pcontext = trace.set_span_in_context(p_parent) |
|
200 | 207 | with trace.use_span(child_1, end_on_exit=False): |
201 | 208 | # Parse logs |
202 | 209 | 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: |
204 | 222 | for line in f.readlines(): |
205 | 223 | try: |
206 | 224 | line_to_add = line[29:-1].strip() |
|
236 | 254 | print("Log file not expected for this step ->",step['name'],"<- because its status is ->",step['conclusion']) |
237 | 255 | pass #We don't expect log file to exist |
238 | 256 | 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") |
240 | 258 |
|
241 | 259 |
|
242 | 260 | if step['conclusion'] == 'skipped' or step['conclusion'] == 'cancelled': |
|
0 commit comments