Skip to content

Commit

Permalink
make the git steps more
Browse files Browse the repository at this point in the history
  • Loading branch information
roumail committed Oct 15, 2024
1 parent c466ed2 commit c9f2d03
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,39 @@ def update_changelog(version):
f.write(f'\n## [{version}] - {datetime.now().strftime("%Y-%m-%d")}\n')


def update_git(new_version):
def delete_tag(tag):
# Delete the local and remote tag if it exists
print(f"Deleting existing tag {tag} locally and remotely...")
subprocess.run(["git", "tag", "-d", tag], check=True)
subprocess.run(["git", "push", "origin", f":refs/tags/{tag}"], check=True)


def tag_exists_on_remote(tag):
result = subprocess.run(
["git", "ls-remote", "--tags", "origin", tag], capture_output=True, text=True
)
return bool(result.stdout.strip())


def update_git(new_version: str, delete_existing_tag: bool = False):
# Fetch tags to ensure the local repo is up to date
subprocess.run(["git", "fetch", "--tags"], check=True)
tag_name = f"v{new_version}"

if tag_exists_on_remote(tag_name) and delete_existing_tag:
delete_tag(tag_name)
else:
print(f"Tag {tag_name} already exists on the remote. Aborting!")
sys.exit(1)

subprocess.run(
["git", "commit", "-am", f"Bump version to {new_version}"], check=True
)

subprocess.run(
["git", "tag", f"v{new_version}", "-m", f"Release v{new_version}"], check=True
["git", "tag", tag_name, "-m", f"Release v{new_version}"], check=True
)
subprocess.run(["git", "push", "origin", f"v{new_version}"], check=True)
subprocess.run(["git", "push", "origin", tag_name], check=True)


def main():
Expand Down

0 comments on commit c9f2d03

Please sign in to comment.