Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport master] Fix branch name used in pull request creation on release creation #1297

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions c2cciutils/scripts/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import multi_repo_automation as mra
import ruamel.yaml.comments

import c2cciutils


def main() -> None:
"""Create a new version with its stabilization branch."""
Expand Down Expand Up @@ -102,12 +104,34 @@ def main() -> None:

# # # Do the changes for the new version # # #

stabilization_branches = mra.get_stabilization_branches(repo)
remotes = [r for r in mra.run(["git", "remote"], stdout=subprocess.PIPE).stdout.split() if r != ""]
remote_branches = [
b.strip()[len("remotes/") :]
for b in mra.run(["git", "branch", "--all"], stdout=subprocess.PIPE).stdout.split()
if b != "" and b.strip().startswith("remotes/")
]
if "upstream" in remotes:
remote_branches = [b[len("upstream") + 1 :] for b in remote_branches if b.startswith("upstream/")]
elif "origin" in remotes:
remote_branches = [b[len("origin") + 1 :] for b in remote_branches if b.startswith("origin/")]
else:
remote_branches = ["/".join(b.split("/")[1:]) for b in remote_branches]

config = c2cciutils.get_config()
branch_re = c2cciutils.compile_re(config["version"].get("branch_to_version_re", []))
branches_match = [c2cciutils.match(b, branch_re) for b in remote_branches]
version_branch = {m.groups()[0] if m.groups() else b: b for m, c, b in branches_match if m is not None}

stabilization_branches = [
version_branch.get(version, version) for version in mra.get_stabilization_versions(repo)
]
modified_files = []

if version:
stabilization_branches.append(version)

if os.path.exists("SECURITY.md"):
modified_files.append("SECURITY.md")
with mra.Edit("SECURITY.md") as security_md:
security_md_lines = security_md.data.split("\n")
index = -1
Expand Down Expand Up @@ -141,6 +165,7 @@ def main() -> None:
)

if os.path.exists(".github/renovate.json5"):
modified_files.append(".github/renovate.json5")
with mra.EditRenovateConfig(".github/renovate.json5") as renovate_config:
if stabilization_branches:
if "baseBranches: " in renovate_config.data:
Expand All @@ -153,6 +178,7 @@ def main() -> None:
renovate_config.add({"baseBranches": stabilization_branches_with_master}, "baseBranches")

if stabilization_branches and os.path.exists(".github/workflows/audit.yaml"):
modified_files.append(".github/workflows/audit.yaml")
with mra.EditYAML(".github/workflows/audit.yaml") as yaml:
for job in yaml["jobs"].values():
matrix = job.get("strategy", {}).get("matrix", {})
Expand All @@ -178,7 +204,7 @@ def main() -> None:
message = f"Create the new version '{version}'" if version else "Update the supported versions"
if os.path.exists(".pre-commit-config.yaml"):
subprocess.run(["pre-commit", "run", "--color=never", "--all-files"], check=False)
subprocess.run(["git", "add", "--all"], check=True)
subprocess.run(["git", "add", *modified_files], check=True)
subprocess.run(["git", "commit", f"--message={message}"], check=True)

# Push it
Expand All @@ -199,7 +225,7 @@ def main() -> None:
"create",
f"--title={message}",
"--body=",
"--head=new_version",
f"--head={branch_name}",
f"--base={repo.get('master_branch', 'master')}",
)

Expand Down
Loading