Skip to content

Commit 3599dfb

Browse files
committed
per branch
1 parent 4594db5 commit 3599dfb

File tree

1 file changed

+9
-65
lines changed

1 file changed

+9
-65
lines changed

scripts/release/branch_detection.py

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,25 @@
66
Evergreen patch builds, Evergreen regular builds).
77
"""
88

9-
import os
109
import subprocess
1110
from typing import Optional
1211

13-
from scripts.release.constants import get_version_id, is_evg_patch, is_running_in_evg
14-
1512

1613
def get_current_branch() -> Optional[str]:
1714
"""
1815
Detect the current git branch for cache scoping.
1916
20-
In Evergreen CI:
21-
- For patch builds: tries to detect the original branch (not evg-pr-test-* branches)
22-
- For master builds: returns master
23-
2417
:return: branch name or 'master' as fallback
2518
"""
26-
if not is_running_in_evg():
27-
# Local development - use git directly
28-
try:
29-
result = subprocess.run(
30-
["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True, check=True
31-
)
32-
branch = result.stdout.strip()
33-
return branch if branch != "HEAD" else "master"
34-
except (subprocess.CalledProcessError, FileNotFoundError):
35-
return "master"
36-
37-
# Running in Evergreen
38-
if is_evg_patch():
39-
# For patch builds, try to detect the original branch
40-
# This logic is based on scripts/evergreen/precommit_bump.sh
41-
try:
42-
# Get all remote refs with their commit hashes
43-
result = subprocess.run(
44-
["git", "for-each-ref", "--format=%(refname:short) %(objectname)", "refs/remotes/origin"],
45-
capture_output=True,
46-
text=True,
47-
check=True,
48-
)
49-
50-
# Get current commit hash
51-
current_commit = subprocess.run(
52-
["git", "rev-parse", "HEAD"], capture_output=True, text=True, check=True
53-
).stdout.strip()
54-
55-
# Find branches that point to the current commit, excluding evg-pr-test-* branches
56-
for line in result.stdout.strip().split("\n"):
57-
if not line:
58-
continue
59-
parts = line.split()
60-
if len(parts) >= 2:
61-
ref_name, commit_hash = parts[0], parts[1]
62-
if commit_hash == current_commit and not ref_name.startswith("origin/evg-pr-test-"):
63-
# Remove 'origin/' prefix
64-
branch = ref_name.replace("origin/", "", 1)
65-
return branch
66-
67-
except (subprocess.CalledProcessError, FileNotFoundError):
68-
pass
69-
else:
70-
# For non-patch builds, try to get the branch from git
71-
try:
72-
result = subprocess.run(
73-
["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True, check=True
74-
)
75-
branch = result.stdout.strip()
76-
if branch and branch != "HEAD":
77-
return branch
78-
except (subprocess.CalledProcessError, FileNotFoundError):
79-
pass
80-
81-
# Fallback to master
82-
return "master"
83-
19+
try:
20+
result = subprocess.run(
21+
["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True, check=True
22+
)
23+
branch = result.stdout.strip()
24+
if branch and branch != "HEAD":
25+
return branch
26+
except (subprocess.CalledProcessError, FileNotFoundError):
27+
return "master"
8428

8529
def get_cache_scope() -> str:
8630
"""

0 commit comments

Comments
 (0)