runtime
228 / 500
question 228 CLI & Automation · medium

Tag a release with git

A release script tags the current commit, but only when it is safe. It talks to git through run (subprocess.run on a real machine; a stand-in in the checks). Write tag_release(version, run).

Functiontag_release(version, run)
Steps1. run(["git", "status", "--porcelain"], capture_output=True, text=True): any output means uncommitted changes. 2. run(["git", "tag", "--list", tag], …): any output means the tag exists. 3. run(["git", "tag", "-a", tag, "-m", "Release " + version], …)
tag"v" + version, e.g. "v1.4.0"
Returnsthe tag after step 3 succeeds
RaisesRuntimeError for uncommitted changes, an existing tag, or a failed step 3 (with git's stripped stderr in the message); later steps must not run after a refusal

Loading your progress…

Tag a release with git — Python practice · Runtime