diff --git a/tasks.py b/tasks.py index a36cd53ea..4bbfe52e2 100644 --- a/tasks.py +++ b/tasks.py @@ -209,10 +209,8 @@ def publish(context: Context, dry_run: str = ""): "js": prepare_js_release, "py": prepare_py_release, } - - parsed_tags: list[TagInfo] = [ - parse_tag(tag) for tag in dry_run.split(",") or get_current_tags(context) - ] + current_tags = dry_run.split(",") if dry_run else get_current_tags(context) + parsed_tags = [parse_tag(tag) for tag in current_tags] publishers: list[Callable[[bool], None]] = [] for tag_info in parsed_tags: @@ -315,23 +313,18 @@ def get_current_tags(context: Context) -> set[str]: context.run("git diff --cached --exit-code", hide=True) context.run("git diff --exit-code", hide=True) except Exception: - log.error("Cannot create a tag - there are uncommitted changes") + log.error("Cannot get current tags - there are uncommitted changes") return set() - tags_per_commit: dict[str, list[str]] = {} - for commit, tag in map( - str.split, - context.run( - r"git for-each-ref --format '%(objectname) %(refname:short)' refs/tags", - hide=True, - ).stdout.splitlines(), - ): - tags_per_commit.setdefault(commit, []).append(tag) - - current_commit = context.run( - "git rev-parse HEAD", silent=True, external=True - ).stdout.strip() - tags = set(tags_per_commit.get(current_commit, set())) + # get tags for current commit + tags = { + line + for line in map( + str.strip, + context.run("git tag --points-at HEAD", hide=True).stdout.splitlines(), + ) + if line + } if not tags: log.error("No tags found for current commit")