Skip to content

Commit

Permalink
Last tag parsing from environment variables too
Browse files Browse the repository at this point in the history
  • Loading branch information
xfenix committed Aug 4, 2022
1 parent 0931831 commit bf0a166
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scripts/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
"""Helper functions."""
import os
import re
import shlex
import subprocess


def parse_last_git_tag() -> str:
"""Return last git tag."""
last_tag_hash: str = subprocess.check_output(shlex.split("git rev-list --tags --max-count=1")).strip().decode()
return subprocess.check_output(shlex.split(f"git describe --tags {last_tag_hash}")).strip().decode().lstrip("v")
"""Return last git tag (works in CI and on localhost)."""
last_tag_from_environment: str | None = os.getenv("GITHUB_REF_NAME")
if last_tag_from_environment is None:
last_tag_hash: str = subprocess.check_output(shlex.split("git rev-list --tags --max-count=1")).strip().decode()
return subprocess.check_output(shlex.split(f"git describe --tags {last_tag_hash}")).strip().decode().lstrip("v")
else:
return last_tag_from_environment.lstrip("v")


def replace_tag_in_readme(readme_text: str, new_tag: str) -> str:
Expand Down

0 comments on commit bf0a166

Please sign in to comment.