Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai>
Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai>
Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai>
Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai>
Co-Authored-By: Clément Siriex <clement.sirieix@mistral.ai>
Co-Authored-By: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai>
Co-Authored-By: Thaddee Tyl <thaddee.tyl@gmail.com>
Co-Authored-By: David Brochart <david.brochart@gmail.com>
Co-Authored-By: Joseph Guhlin <joseph.guhlin@gmail.com>
Co-Authored-By: Thomas Kenbeek <thomaskenbeek@gmail.com>
Co-Authored-By: Remenby31 <baptiste.cruvellier31@gmail.com>
This commit is contained in:
Mathias Gesbert 2026-01-27 16:39:30 +01:00 committed by Mathias Gesbert
parent 79f215d91c
commit d33db9fff8
217 changed files with 16911 additions and 4305 deletions

View file

@ -10,6 +10,8 @@ This script increments the version in pyproject.toml based on the specified bump
from __future__ import annotations
import argparse
from datetime import date
import os
from pathlib import Path
import re
import subprocess
@ -50,7 +52,6 @@ def update_hard_values_files(filepath: str, patterns: list[tuple[str, str]]) ->
if not path.exists():
raise FileNotFoundError(f"{filepath} not found in current directory")
# Replace patterns
for pattern, replacement in patterns:
content = path.read_text()
updated_content = re.sub(pattern, replacement, content, flags=re.MULTILINE)
@ -71,7 +72,6 @@ def get_current_version() -> str:
content = pyproject_path.read_text()
# Find version line
version_match = re.search(r'^version = "([^"]+)"$', content, re.MULTILINE)
if not version_match:
raise ValueError("Version not found in pyproject.toml")
@ -79,7 +79,60 @@ def get_current_version() -> str:
return version_match.group(1)
def update_changelog(new_version: str) -> None:
changelog_path = Path("CHANGELOG.md")
if not changelog_path.exists():
raise FileNotFoundError("CHANGELOG.md not found in current directory")
content = changelog_path.read_text()
today = date.today().isoformat()
first_entry_match = re.search(r"^## \[[\d.]+\]", content, re.MULTILINE)
if not first_entry_match:
raise ValueError("Could not find version entry in CHANGELOG.md")
insert_position = first_entry_match.start()
new_entry = f"## [{new_version}] - {today}\n\n"
new_entry += "### Added\n\n"
new_entry += "### Changed\n\n"
new_entry += "### Fixed\n\n"
new_entry += "### Removed\n\n"
new_entry += "\n"
updated_content = content[:insert_position] + new_entry + content[insert_position:]
changelog_path.write_text(updated_content)
print(f"Added changelog entry for version {new_version}")
def print_warning(new_version: str) -> None:
warning = f"""
{"=" * 80}
WARNING: CHANGELOG UPDATE REQUIRED
{"=" * 80}
Don't forget to fill in the changelog entry for version {new_version} in CHANGELOG.md! 📝
Also, remember to fill in vibe/whats_new.md if needed (you can leave it blank). 📝
{"=" * 80}
"""
print(warning, file=sys.stderr)
def clean_up_whats_new_message() -> None:
whats_new_path = Path("vibe/whats_new.md")
if not whats_new_path.exists():
raise FileNotFoundError("whats_new.md not found in current directory")
whats_new_path.write_text("")
def main() -> None:
os.chdir(Path(__file__).parent.parent)
parser = argparse.ArgumentParser(
description="Bump semver version in pyproject.toml",
formatter_class=argparse.RawDescriptionHelpFormatter,
@ -140,9 +193,15 @@ Examples:
[(f'version="{current_version}"', f'version="{new_version}"')],
)
# Update CHANGELOG.md
update_changelog(new_version)
clean_up_whats_new_message()
subprocess.run(["uv", "lock"], check=True)
print(f"\nSuccessfully bumped version from {current_version} to {new_version}")
print_warning(new_version)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)

284
scripts/prepare_release.py Executable file
View file

@ -0,0 +1,284 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
from pathlib import Path
import re
import subprocess
import sys
def run_git_command(
*args: str, check: bool = True, capture_output: bool = False
) -> subprocess.CompletedProcess[str]:
"""Run a git command and return the result."""
result = subprocess.run(
["git"] + list(args), check=check, capture_output=capture_output, text=True
)
return result
def ensure_public_remote() -> None:
result = run_git_command("remote", "-v", capture_output=True, check=False)
remotes = result.stdout
public_remote_url = "git@github.com:mistralai/mistral-vibe.git"
if public_remote_url in remotes:
print("Public remote already exists with correct URL")
return
print(f"Creating public remote: {public_remote_url}")
run_git_command("remote", "add", "public", public_remote_url)
print("Public remote created successfully")
def switch_to_tag(version: str) -> None:
tag = f"v{version}"
print(f"Switching to tag {tag}...")
result = run_git_command(
"rev-parse", "--verify", tag, capture_output=True, check=False
)
if result.returncode != 0:
raise ValueError(f"Tag {tag} does not exist")
run_git_command("switch", "--detach", tag)
print(f"Successfully switched to tag {tag}")
def get_version_from_pyproject() -> str:
pyproject_path = Path("pyproject.toml")
if not pyproject_path.exists():
raise FileNotFoundError("pyproject.toml not found in current directory")
content = pyproject_path.read_text()
version_match = re.search(r'^version = "([^"]+)"$', content, re.MULTILINE)
if not version_match:
raise ValueError("Version not found in pyproject.toml")
return version_match.group(1)
def get_latest_version() -> str:
result = run_git_command("ls-remote", "--tags", "public", capture_output=True)
remote_tags_output = (
result.stdout.strip().split("\n") if result.stdout.strip() else []
)
if not remote_tags_output:
raise ValueError("No version tags found on public remote")
versions: list[tuple[int, int, int, str]] = []
MIN_PARTS_IN_LS_REMOTE_LINE = 2 # hash and ref
for line in remote_tags_output:
parts = line.split()
if len(parts) < MIN_PARTS_IN_LS_REMOTE_LINE:
continue
_hash, tag_ref = parts[0], parts[1]
if not tag_ref.startswith("refs/tags/"):
continue
tag = tag_ref.replace("refs/tags/", "")
match = re.match(r"^v(\d+\.\d+\.\d+)$", tag)
if not match:
continue
tag_version = match.group(1)
try:
major, minor, patch = parse_version(tag_version)
versions.append((major, minor, patch, tag_version))
except ValueError:
continue
if not versions:
raise ValueError(
"No valid version tags found on public remote (format: vX.Y.Z)"
)
versions.sort()
return max(versions)[3]
def parse_version(version_str: str) -> tuple[int, int, int]:
match = re.match(r"^(\d+)\.(\d+)\.(\d+)$", version_str.strip())
if not match:
raise ValueError(f"Invalid version format: {version_str}")
return int(match.group(1)), int(match.group(2)), int(match.group(3))
def create_release_branch(version: str) -> None:
branch_name = f"release/v{version}"
print(f"Creating release branch: {branch_name}")
result = run_git_command(
"branch", "--list", branch_name, capture_output=True, check=False
)
if result.stdout.strip():
print(f"Warning: Branch {branch_name} already exists", file=sys.stderr)
response = input(f"Delete and recreate {branch_name}? (y/N): ")
if response.lower() == "y":
run_git_command("branch", "-D", branch_name)
else:
print("Aborting", file=sys.stderr)
sys.exit(1)
run_git_command("switch", "-c", branch_name)
print(f"Created and switched to branch {branch_name}")
def cherry_pick_commits(previous_version: str, current_version: str) -> None:
previous_tag = f"v{previous_version}-private"
current_tag = f"v{current_version}-private"
result = run_git_command(
"rev-parse", "--verify", previous_tag, capture_output=True, check=False
)
if result.returncode != 0:
raise ValueError(f"Tag {previous_tag} does not exist")
result = run_git_command(
"rev-parse", "--verify", current_tag, capture_output=True, check=False
)
if result.returncode != 0:
raise ValueError(f"Tag {current_tag} does not exist")
print(f"Cherry-picking commits from {previous_tag}..{current_tag}...")
run_git_command("cherry-pick", f"{previous_tag}..{current_tag}")
print("Successfully cherry-picked all commits")
def get_commits_summary(previous_version: str, current_version: str) -> str:
previous_tag = f"v{previous_version}-private"
current_tag = f"v{current_version}-private"
result = run_git_command(
"log", f"{previous_tag}..{current_tag}", "--oneline", capture_output=True
)
return result.stdout.strip()
def get_changelog_entry(version: str) -> str:
changelog_path = Path("CHANGELOG.md")
if not changelog_path.exists():
return "CHANGELOG.md not found"
content = changelog_path.read_text()
pattern = rf"^## \[{re.escape(version)}\] - .+?(?=^## \[|\Z)"
match = re.search(pattern, content, re.MULTILINE | re.DOTALL)
if not match:
return f"No changelog entry found for version {version}"
return match.group(0).strip()
def print_summary(
current_version: str,
previous_version: str,
commits_summary: str,
changelog_entry: str,
) -> None:
print("\n" + "=" * 80)
print("RELEASE PREPARATION SUMMARY")
print("=" * 80)
print(f"\nVersion: {current_version}")
print(f"Previous version: {previous_version}")
print(f"Release branch: release/v{current_version}")
print("\n" + "-" * 80)
print("COMMITS IN THIS RELEASE")
print("-" * 80)
if commits_summary:
print(commits_summary)
else:
print("No commits found")
print("\n" + "-" * 80)
print("CHANGELOG ENTRY")
print("-" * 80)
print(changelog_entry)
print("\n" + "-" * 80)
print("NEXT STEPS")
print("-" * 80)
print(
f"To review/edit commits before publishing, use interactive rebase:\n"
f" git rebase -i v{previous_version}"
)
print("\n" + "-" * 80)
print("REMINDERS")
print("-" * 80)
print("Before publishing the release:")
print(" ✓ Credit any public contributors in the release notes")
print(" ✓ Close related issues once the release is published")
print(
" ✓ Review and update the changelog if needed "
"(should be made in the private main branch)"
)
print("\n" + "=" * 80)
def main() -> None:
parser = argparse.ArgumentParser(
description="Prepare a release branch by cherry-picking from private tags",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument("version", help="Version to prepare release for (e.g., 1.1.3)")
args = parser.parse_args()
current_version = args.version
try:
# Step 1: Ensure public remote exists
ensure_public_remote()
# Step 2: Fetch all remotes
print("Fetching all remotes...")
run_git_command("fetch", "--all")
print("Successfully fetched all remotes")
# Step 3: Find latest version
previous_version = get_latest_version()
print(f"Previous version: {previous_version}")
# Step 4: Verify version matches pyproject.toml
pyproject_version = get_version_from_pyproject()
if current_version != pyproject_version:
raise ValueError(
f"Version mismatch: provided version '{current_version}' does not match "
f"pyproject.toml version '{pyproject_version}'"
)
print(f"Version verified: {current_version}")
# Step 5: Switch to previous version tag
switch_to_tag(previous_version)
# Step 6: Create release branch
create_release_branch(current_version)
# Step 7: Cherry-pick commits
cherry_pick_commits(previous_version, current_version)
# Step 8: Get summary information
commits_summary = get_commits_summary(previous_version, current_version)
changelog_entry = get_changelog_entry(current_version)
# Step 9: Print summary
print_summary(
current_version, previous_version, commits_summary, changelog_entry
)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()