Skip to content

Commit

Permalink
fix how we collect tags on current commit (#1063)
Browse files Browse the repository at this point in the history
* fix how we collect tags on current commit

* fix dry-run handling
  • Loading branch information
rmorshea committed Jun 16, 2023
1 parent 6df7ecd commit 9bf3db7
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 9bf3db7

Please sign in to comment.