| 18 | |
| 19 | |
| 20 | def _update_workflow_id(content: str, workflow_id: str) -> str: |
| 21 | pattern = re.compile(r"^(id:\\s*).*$", re.MULTILINE) |
| 22 | match = pattern.search(content) |
| 23 | if match: |
| 24 | return pattern.sub(rf"\\1{workflow_id}", content, count=1) |
| 25 | |
| 26 | lines = content.splitlines() |
| 27 | insert_index = 0 |
| 28 | if lines and lines[0].strip() == "---": |
| 29 | insert_index = 1 |
| 30 | lines.insert(insert_index, f"id: {workflow_id}") |
| 31 | updated = "\n".join(lines) |
| 32 | if content.endswith("\n"): |
| 33 | updated += "\n" |
| 34 | return updated |
| 35 | |
| 36 | |
| 37 | def validate_workflow_filename(filename: str, *, require_yaml_extension: bool = True) -> str: |