|
22 | 22 | TC_EXECUTION_TEMPLATE = "https://firefox-ci-tc.services.mozilla.com/tasks/%TASK_ID%/runs/%RUN_ID%/logs/live/public/logs/live.log"
|
23 | 23 |
|
24 | 24 |
|
25 |
| -def get_execution_link() -> str: |
| 25 | +def get_execution_link(os_name: str = None) -> str: |
26 | 26 | """Using environment variables, get the link to the test execution"""
|
27 |
| - link = "" |
| 27 | + # TaskCluster (Linux) |
| 28 | + if os_name == "Linux" and "TASKCLUSTER_PROXY_URL" in os.environ: |
| 29 | + link = TC_EXECUTION_TEMPLATE |
| 30 | + for item in ["RUN_ID", "TASK_ID"]: |
| 31 | + link = link.replace(f"%{item}%", os.environ.get(item)) |
| 32 | + return link |
| 33 | + |
| 34 | + # GitHub Actions support for Windows and Mac |
| 35 | + if os_name in ["Windows", "Mac"]: |
| 36 | + repo = os.environ.get("GITHUB_REPOSITORY") |
| 37 | + run_id = os.environ.get("GITHUB_RUN_ID") |
| 38 | + if repo and run_id: |
| 39 | + return f"https://github.com/{repo}/actions/runs/{run_id}" |
| 40 | + |
| 41 | + # Generic GitHub run fallback |
| 42 | + repo = os.environ.get("GITHUB_REPOSITORY") |
| 43 | + run_id = os.environ.get("GITHUB_RUN_ID") |
| 44 | + server = os.environ.get("GITHUB_SERVER_URL", "https://github.com") |
| 45 | + if repo and run_id: |
| 46 | + return f"{server}/{repo}/actions/runs/{run_id}" |
| 47 | + |
| 48 | + # Fallback for backward compatibility (when no os_name is passed) |
28 | 49 | if "TASKCLUSTER_PROXY_URL" in os.environ:
|
29 | 50 | link = TC_EXECUTION_TEMPLATE
|
30 | 51 | for item in ["RUN_ID", "TASK_ID"]:
|
31 | 52 | link = link.replace(f"%{item}%", os.environ.get(item))
|
32 | 53 | return link
|
33 | 54 |
|
| 55 | + logging.warning( |
| 56 | + f"Could not generate execution link for os_name={os_name}. Missing required environment variables." |
| 57 | + ) |
| 58 | + return "" |
| 59 | + |
34 | 60 |
|
35 | 61 | def replace_link_in_description(description, os_name) -> str:
|
36 | 62 | """Add or replace a test execution link in the test run description"""
|
37 |
| - logging.warning(f"Modifying plan description for %{os_name}%") |
38 |
| - if os_name not in description: |
39 |
| - # TODO: remove following conditional when links for GHA resolved |
40 |
| - if os_name == "Linux": |
41 |
| - return f"{description}\n[{os_name} execution link]({get_execution_link()})" |
42 |
| - else: |
43 |
| - link = get_execution_link() |
44 |
| - if link in description: |
45 |
| - return description |
46 |
| - lines = description.split("\n") |
47 |
| - for i, line in enumerate(lines): |
48 |
| - if os_name in line: |
49 |
| - lines[i] = ( |
50 |
| - f"{description}\n[{os_name} execution link]({get_execution_link()})" |
51 |
| - ) |
52 |
| - return description |
| 63 | + |
| 64 | + link = get_execution_link(os_name) |
| 65 | + if not link: |
| 66 | + return description |
| 67 | + |
| 68 | + new_line = f"[{os_name} execution link]({link})" |
| 69 | + lines = description.splitlines() |
| 70 | + pat = re.compile( |
| 71 | + rf"^\s*\[{re.escape(os_name)}\s+execution\s+link\]\(.*?\)\s*$", |
| 72 | + re.IGNORECASE, |
| 73 | + ) |
| 74 | + |
| 75 | + # Look for existing line to replace |
| 76 | + for i, line in enumerate(lines): |
| 77 | + if pat.match(line): |
| 78 | + if line.strip() == new_line: |
| 79 | + return description |
| 80 | + lines[i] = new_line |
| 81 | + return "\n".join(lines) |
| 82 | + |
| 83 | + # No existing line found, append new one |
| 84 | + lines.append(new_line) |
| 85 | + return "\n".join(lines) |
| 86 | + |
| 87 | + |
| 88 | +def determine_current_os() -> str: |
| 89 | + """Determine the current operating system for execution link generation""" |
| 90 | + |
| 91 | + # Check if we're in GitHub Actions |
| 92 | + if os.environ.get("GITHUB_ACTIONS"): |
| 93 | + if sys.platform == "win32": |
| 94 | + return "Windows" |
| 95 | + elif sys.platform == "darwin": |
| 96 | + return "Mac" |
| 97 | + elif sys.platform.startswith("linux"): |
| 98 | + return "Linux" |
| 99 | + |
| 100 | + # Check if we're in TaskCluster (Linux) |
| 101 | + elif "TASKCLUSTER_PROXY_URL" in os.environ: |
| 102 | + return "Linux" |
| 103 | + |
| 104 | + return None |
53 | 105 |
|
54 | 106 |
|
55 | 107 | def get_plan_title(version_str: str, channel: str) -> str:
|
@@ -660,11 +712,22 @@ def collect_changes(testrail_session: TestRail, report):
|
660 | 712 | logging.info(f"Plan found ({expected_plan.get('id')}) but is completed.")
|
661 | 713 | return None
|
662 | 714 |
|
663 |
| - # Add execution link to plan description |
664 |
| - |
665 |
| - os_name = config.split(" ")[0] |
666 |
| - description = replace_link_in_description(expected_plan["description"], os_name) |
667 |
| - testrail_session.update_plan(expected_plan["id"], description=description) |
| 715 | + # Add execution link for current OS only |
| 716 | + current_os = determine_current_os() |
| 717 | + if current_os: |
| 718 | + description = expected_plan.get("description") or "" |
| 719 | + updated_description = replace_link_in_description(description, current_os) |
| 720 | + if updated_description != description: |
| 721 | + logging.info(f"Adding {current_os} execution link to TestRail plan") |
| 722 | + testrail_session.update_plan( |
| 723 | + expected_plan["id"], description=updated_description |
| 724 | + ) |
| 725 | + else: |
| 726 | + logging.info( |
| 727 | + f"TestRail plan already has current {current_os} execution link" |
| 728 | + ) |
| 729 | + else: |
| 730 | + logging.warning("Could not determine current OS for execution link") |
668 | 731 |
|
669 | 732 | # Find or add correct config for session
|
670 | 733 |
|
|
0 commit comments