Skip to content

Commit 507b2a0

Browse files
authored
feat(hooks): allow clean up v0.1.0 tag and release on regenerate (#27)
1 parent 8fa0c77 commit 507b2a0

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

hooks/post_gen_project.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
import os
99
import pprint
10+
import shutil
1011
import subprocess
1112
import sys
1213
from collections import OrderedDict
@@ -200,13 +201,38 @@ def run_post_gen_hook():
200201
)
201202

202203
if os.environ.get("SKIP_GIT_PUSH") != "true":
203-
# TODO: Remove --force; just for testing
204+
cmd = ["git", "push", "--set-upstream", "origin", "main"]
205+
206+
# We only force push if we were explicitly allowed to
207+
if os.environ.get("ALLOW_FORCE_PUSH") == "true":
208+
cmd.append("--force")
209+
204210
subprocess.run(
205-
["git", "push", "--set-upstream", "origin", "main", "--force"],
211+
cmd,
206212
capture_output=True,
207213
check=True,
208214
)
209215

216+
if os.environ.get("ALLOW_FORCE_PUSH") == "true":
217+
# Attempt to cleanup the v0.1.0 tag and corresponding release
218+
release = "v0.1.0"
219+
220+
subprocess.run(
221+
["git", "push", "--delete", "origin", release],
222+
check=False,
223+
stdout=subprocess.DEVNULL,
224+
stderr=subprocess.DEVNULL,
225+
)
226+
227+
# If the user has the gh cli installed and setup, we cleanup the corresponding release as well
228+
if shutil.which("gh"):
229+
subprocess.run(
230+
["gh", "release", "delete", release, "--yes"],
231+
check=False,
232+
stdout=subprocess.DEVNULL,
233+
stderr=subprocess.DEVNULL,
234+
)
235+
210236
# Cut an initial release
211237
subprocess.run(
212238
["task", "release"],

0 commit comments

Comments
 (0)