Implementation:Apache Kafka Git Archive And Build
| Knowledge Sources | |
|---|---|
| Domains | Release_Engineering, Build_Systems |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
Concrete tool for creating source tarballs and building binary distributions provided by the Kafka release module.
Description
The git module provides targz for creating source archives via git archive and clone for creating clean checkouts. The runtime module provides cmd for executing build commands like Gradle's releaseTarGz task. Together they produce the source and binary artifacts needed for an Apache release.
Usage
Import these functions when automating the artifact build phase of a release. Use targz to create the source tarball, clone to create a clean build environment, and cmd to run Gradle build tasks.
Code Reference
Source Location
- Repository: Apache Kafka
- File: release/git.py (L102-113), release/runtime.py (L109-146)
Signature
def targz(rev, prefix, target, **kwargs):
"""
Creates a tar.gz archive from a git revision.
Uses 'git archive --format tar.gz --prefix {prefix} --output {target} {rev}'.
"""
def clone(url, target, **kwargs):
"""
Clones a git repository to the target directory.
"""
def cmd(action, cmd_arg, *args, **kwargs):
"""
Execute an external command with retry support.
Prints the action description and command, captures output,
and offers retry on failure.
"""
Import
from git import targz, clone
from runtime import cmd
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| rev | str | Yes | Git revision to archive |
| prefix | str | Yes | Directory prefix inside the tarball |
| target | str | Yes | Output file path for the tarball |
| url | str | Yes (for clone) | Repository URL to clone |
| action | str | Yes (for cmd) | Human-readable action description |
| cmd_arg | str | Yes (for cmd) | Shell command to execute |
Outputs
| Name | Type | Description |
|---|---|---|
| targz | None | Source tarball created at target path |
| clone | None | Repository cloned to target directory |
| cmd returns | bool | True if command succeeded, False if allowed_failure and failed |
Usage Examples
Build Source and Binary Artifacts
from git import targz, clone
from runtime import cmd
import tempfile
version = "3.7.0"
rc_tag = "3.7.0-rc0"
# Create source tarball from tag
targz(rc_tag, f"kafka-{version}-src/", f"kafka-{version}-src.tgz")
# Clone for clean build
with tempfile.TemporaryDirectory() as tmpdir:
clone("https://github.com/apache/kafka.git", tmpdir)
cmd("Building binary distribution",
f"./gradlew releaseTarGz", cwd=tmpdir)