Skip to content

Commit d9319cb

Browse files
WorkerPantshuonw
andauthored
Remove force flags from release tagging & confirm commit before doing so (Cherry-pick of #20640) (#20644)
This does two changes in response to my mistake with retagging 2.21.0.dev0 (https://pantsbuild.slack.com/archives/C0D7TNJHL/p1709588198420159): - adds a check that the commit-to-be-tagged is correct, via `git show` - removes the `-f` (force) flags from both the `git tag` and `git push` invocation, so that if a tag already exists, we're not automatically overwriting it. The second of these is explicitly revisiting #4504 (that introduced the flags). I believe our release process is quite different to how it was then, and thus we can be more careful with tags now. And, if someone really needs to move a tag, they can always add the `-f` flags themselves, as required (or delete the tag, or similar). This is referenced in a comment. Co-authored-by: Huon Wilson <[email protected]>
1 parent 13308be commit d9319cb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/python/pants_release/release.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ def build_fs_util() -> None:
666666
def tag_release() -> None:
667667
banner("Tagging release")
668668

669+
check_head_commit()
669670
check_clean_git_branch()
670671
check_pgp()
671672

@@ -675,6 +676,17 @@ def tag_release() -> None:
675676
banner("Successfully tagged release")
676677

677678

679+
def check_head_commit() -> None:
680+
banner("Checking current HEAD commit")
681+
git("show", capture_stdout=False)
682+
683+
key_confirmation = input(
684+
f"\nIs this the correct commit to tag for {CONSTANTS.pants_stable_version}? [Y/n]: "
685+
)
686+
if key_confirmation and key_confirmation.lower() != "y":
687+
die("Please check out the appropriate commit first")
688+
689+
678690
def check_clean_git_branch() -> None:
679691
banner("Checking for a clean Git branch")
680692
git_status = git("status", "--porcelain")
@@ -721,16 +733,17 @@ def check_pgp() -> None:
721733

722734
def run_tag_release() -> None:
723735
tag_name = f"release_{CONSTANTS.pants_stable_version}"
736+
# If you need to re-tag a release that's already been tagged once and definitely know what
737+
# you're doing, feel free to do an ad-hoc addition of --force flags here.
724738
git(
725739
"tag",
726-
"-f",
727740
f"--local-user={get_pgp_key_id()}",
728741
"-m",
729742
f"pantsbuild.pants release {CONSTANTS.pants_stable_version}",
730743
tag_name,
731744
capture_stdout=False,
732745
)
733-
git("push", "-f", "[email protected]:pantsbuild/pants.git", tag_name, capture_stdout=False)
746+
git("push", "[email protected]:pantsbuild/pants.git", tag_name, capture_stdout=False)
734747

735748

736749
def upload_wheels_via_twine() -> None:

0 commit comments

Comments
 (0)