Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Mlflow Mlflow Check Patch PRs

From Leeroopedia
Revision as of 13:17, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Mlflow_Mlflow_Check_Patch_PRs.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Release Management, CI Automation
Last Updated 2026-02-13 20:00 GMT

Overview

Release automation script that verifies all PRs labeled for a patch release have been cherry-picked to the release branch, and generates cherry-pick shell scripts for any missing commits.

Description

This script automates the patch release cherry-pick verification workflow to prevent missed bug fixes in MLflow release branches. It performs the following operations:

GitHub API Integration:

  • get_token() - Retrieves a GitHub token from the GH_TOKEN environment variable or the gh CLI
  • get_headers() - Builds HTTP authorization headers for GitHub API requests
  • get_commit_count() - Uses the GitHub GraphQL API to count commits on a branch since a given date
  • get_commits() - Fetches commits from the release branch via the REST API (last 90 days), using parallel page fetching with ThreadPoolExecutor for efficiency. Extracts PR numbers from commit messages matching the pattern ... (#NNNN)
  • fetch_patch_prs() - Searches GitHub issues API for PRs labeled with v{version}, excluding closed-but-not-merged PRs

Version Handling:

  • validate_version() - Ensures the version string has exactly three components (major.minor.micro) using packaging.version.Version
  • get_release_branch() - Derives the release branch name (e.g., branch-2.10 from version 2.10.1)

Cherry-Pick Script Generation: When missing cherry-picks are detected, the script:

  1. Identifies the corresponding commits on the master branch
  2. Splits them into chunks of MAX_COMMITS_PER_SCRIPT (90) to stay under GitHub's 100-commit rebase merge limit
  3. Generates executable shell scripts (cherry-pick.sh or cherry-pick-N.sh) in the temp directory
  4. Each script includes safety guards against running on the master branch
  5. Prints step-by-step instructions for the cherry-pick workflow

The script uses ANSI escape codes to highlight unmerged PRs in red in the terminal output.

Two dataclasses track the data: Commit (sha, pr_num, date) and PR (pr_num, merged).

Usage

Run this script before a patch release to verify that all labeled PRs have been cherry-picked. It requires a GitHub token (via GH_TOKEN env var or gh CLI) and a valid version string. Use --dry-run (default) for verification-only mode or --no-dry-run to exit with a non-zero status when cherry-picks are missing.

Code Reference

Source Location

Signature

@dataclass(frozen=True)
class Commit:
    sha: str
    pr_num: int
    date: str

@dataclass(frozen=True)
class PR:
    pr_num: int
    merged: bool

def chunk_list(lst: list[str], size: int) -> list[list[str]]: ...
def get_token() -> str | None: ...
def get_headers() -> dict[str, str]: ...
def validate_version(version: str) -> None: ...
def get_release_branch(version: str) -> str: ...
def get_commit_count(branch: str, since: str) -> int: ...
def get_commits(branch: str) -> list[Commit]: ...
def is_closed(pr: dict[str, Any]) -> bool: ...
def fetch_patch_prs(version: str) -> dict[int, bool]: ...
def main(version: str, dry_run: bool) -> None: ...

Import

# Run as a command-line script
python dev/check_patch_prs.py --version 2.10.1
python dev/check_patch_prs.py --version 2.10.1 --no-dry-run

I/O Contract

Inputs

Name Type Required Description
--version str Yes The patch version to check (e.g., "2.10.1"), must be in major.minor.micro format
--dry-run flag No Dry run mode (default: True). Exits with 0 even if cherry-picks are missing
--no-dry-run flag No Disables dry run mode. Exits with 1 if cherry-picks are missing
GH_TOKEN env var No GitHub personal access token. Falls back to gh auth token if not set
DRY_RUN env var No Controls dry run default ("true"/"false"), overridden by CLI flags

Outputs

Name Type Description
Console output Text List of missing cherry-picks with PR URLs and merge status, highlighted in color
Cherry-pick scripts Shell scripts Generated shell scripts in the temp directory (e.g., /tmp/cherry-pick.sh) containing git cherry-pick commands
Exit code int 0 if all cherry-picks are present or in dry-run mode; 1 if cherry-picks are missing and not in dry-run mode

Usage Examples

Checking a Patch Release

# Check if all v2.10.1 labeled PRs are cherry-picked (dry run)
python dev/check_patch_prs.py --version 2.10.1

# Check and fail if any are missing (for CI)
python dev/check_patch_prs.py --version 2.10.1 --no-dry-run

# Using environment variable for token
GH_TOKEN=ghp_xxxx python dev/check_patch_prs.py --version 2.10.1

Generated Cherry-Pick Script Example

#!/usr/bin/env bash
# Cherry-picks for v2.10.1 -> branch-2.10
set -euo pipefail

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$current_branch" == "master" ]]; then
    echo "ERROR: This script must not be run on the master branch."
    exit 1
fi

git cherry-pick abc123 def456 ghi789

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment