Implementation:Apache Kafka Git Branch And Tag Management
| Knowledge Sources | |
|---|---|
| Domains | Release_Engineering, Version_Control |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
Concrete tool for creating release branches, tags, and updating version files provided by the Kafka release module.
Description
The git and textfiles modules in the Kafka release toolkit provide functions for branch creation, tag creation, and file-based text replacement. The git module wraps git CLI commands via subprocess, while textfiles handles version bumps by replacing patterns in configuration files like gradle.properties.
Usage
Import these functions when automating the branch and version management phase of a Kafka release. Call create_branch to create the release branch, textfiles.replace to bump versions, and create_tag to mark the release point.
Code Reference
Source Location
- Repository: Apache Kafka
- File: release/git.py (L96-121), release/textfiles.py (L55-73)
Signature
def create_branch(branch, ref, **kwargs):
"""Creates git branch 'branch' to track 'ref'."""
def create_tag(tag, **kwargs):
"""Creates annotated git tag with the tag name as message."""
def replace(path, pattern, replacement, **kwargs):
"""
Replace all occurrences of a text pattern in a text file.
If regex=True in kwargs, uses re.sub for regex replacement.
Otherwise, replaces lines starting with the pattern.
"""
Import
from git import create_branch, create_tag
from textfiles import replace
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| branch | str | Yes | Name of the release branch to create |
| ref | str | Yes | Git ref to branch from (e.g., trunk) |
| tag | str | Yes | Annotated tag name (e.g., 3.7.0-rc0) |
| path | str | Yes (for replace) | File path to modify |
| pattern | str | Yes (for replace) | Text pattern to find |
| replacement | str | Yes (for replace) | Replacement text |
| regex | bool | No | Use regex matching (default False) |
Outputs
| Name | Type | Description |
|---|---|---|
| create_branch | None | New git branch created locally |
| create_tag | None | Annotated git tag created |
| replace | None | File modified in-place with replacements applied |
Usage Examples
Create Release Branch and Bump Version
from git import create_branch, create_tag
from textfiles import replace
# Create release branch from trunk
create_branch("3.7", "trunk")
# Bump version in gradle.properties
replace("gradle.properties", "version=", "version=3.7.0")
# Create release candidate tag
create_tag("3.7.0-rc0")