Skip to content

Commit 24bb55e

Browse files
committed
Support SSH origin, support mirror repositories, fix a typo
1 parent c1fceb7 commit 24bb55e

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

run_release.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,12 @@ def start_build_of_source_and_docs(db: DbfilenameShelf) -> None:
734734
["git", "ls-remote", "--get-url", "origin"],
735735
cwd=db["git_repo"]
736736
).decode().strip()
737-
match = re.match(r"github\.com/([^/]+)/", origin_remote_url)
738-
if not match:
737+
if https_match := re.match(r"github\.com/([^/]+)/", origin_remote_url):
738+
origin_remote_github_owner = https_match.group(1)
739+
elif ssh_match := re.match(r"^git@github\.com:([^/]+)/", origin_remote_url):
740+
origin_remote_github_owner = ssh_match.group(1)
741+
else:
739742
raise ReleaseException(f"Could not parse GitHub owner from 'origin' remote URL: {origin_remote_url}")
740-
origin_remote_github_owner = match.group(1)
741-
742743
# We ask for human verification at this point since this commit SHA is 'locked in'
743744
print()
744745
print(f"Go to https://github.com/{origin_remote_github_owner}/cpython/commit/{commit_sha}")
@@ -782,7 +783,7 @@ def create_release_object_in_db(db: DbfilenameShelf) -> None:
782783
raise ReleaseException("The django release object has not been created")
783784

784785

785-
def wait_util_all_files_are_in_folder(db: DbfilenameShelf) -> None:
786+
def wait_until_all_files_are_in_folder(db: DbfilenameShelf) -> None:
786787
client = paramiko.SSHClient()
787788
client.load_system_host_keys()
788789
client.set_missing_host_key_policy(paramiko.WarningPolicy)
@@ -990,15 +991,30 @@ def branch_new_versions(db: DbfilenameShelf) -> None:
990991
)
991992

992993

994+
def is_mirror(repo: pathlib.Path, remote: str) -> bool:
995+
"""Return True if the `repo` directory was created with --mirror."""
996+
997+
cmd = ["git", "config", "--local", "--get", f"remote.{remote}.mirror"]
998+
try:
999+
out = subprocess.check_output(cmd, cwd=repo)
1000+
except subprocess.CalledProcessError:
1001+
return False
1002+
return out.startswith(b"true")
1003+
1004+
9931005
def push_to_local_fork(db: DbfilenameShelf) -> None:
9941006
def _push_to_local(dry_run=False):
9951007
git_command = ["git", "push"]
9961008
if dry_run:
9971009
git_command.append("--dry-run")
9981010

1011+
git_command.append("origin")
1012+
if not is_mirror(db["git_repo"], "origin"):
1013+
# mirrors push everything always, specifying `--tags` or refspecs doesn't work.
1014+
git_command += ["HEAD", "--tags"]
1015+
9991016
subprocess.check_call(
1000-
git_command + ["origin", "HEAD", "--tags"],
1001-
cwd=db["git_repo"],
1017+
git_command, cwd=db["git_repo"],
10021018
)
10031019

10041020
_push_to_local(dry_run=True)
@@ -1143,7 +1159,7 @@ def _api_key(api_key):
11431159
Task(place_files_in_download_folder, "Place files in the download folder"),
11441160
Task(upload_docs_to_the_docs_server, "Upload docs to the PSF docs server"),
11451161
Task(unpack_docs_in_the_docs_server, "Place docs files in the docs folder"),
1146-
Task(wait_util_all_files_are_in_folder, "Wait until all files are ready"),
1162+
Task(wait_until_all_files_are_in_folder, "Wait until all files are ready"),
11471163
Task(create_release_object_in_db, "The django release object has been created"),
11481164
Task(post_release_merge, "Merge the tag into the release branch"),
11491165
Task(branch_new_versions, "Branch out new versions and prepare main branch"),

0 commit comments

Comments
 (0)