1 Commits
Author SHA1 Message Date
Junie 7867db3f2a fix: use prior tag before target version when version tag exists 2026-09-28 15:20:23 -07:00
2 changed files with 18 additions and 4 deletions

No files matched your search

+6
View File
@@ -108,6 +108,12 @@ save_file = os.environ.get("INPUT_SAVE_TO_FILE", "")
subprocess.run(["git", "fetch", "--tags", "--prune"], capture_output=True) subprocess.run(["git", "fetch", "--tags", "--prune"], capture_output=True)
if not from_ref:
if version:
target_tag = version if version.startswith("v") else f"v{version}"
res = subprocess.run(["git", "describe", "--tags", f"--match={tag_pattern}", "--abbrev=0", f"{target_tag}^"], capture_output=True, text=True)
if res.returncode == 0 and res.stdout.strip():
from_ref = res.stdout.strip()
if not from_ref: if not from_ref:
code, out = subprocess.run(["git", "describe", "--tags", f"--match={tag_pattern}", "--exact-match", to_ref], capture_output=True, text=True).returncode, "" code, out = subprocess.run(["git", "describe", "--tags", f"--match={tag_pattern}", "--exact-match", to_ref], capture_output=True, text=True).returncode, ""
if code == 0: if code == 0:
+12 -4
View File
@@ -41,7 +41,15 @@ def run_git(args):
return 1, "", str(e) return 1, "", str(e)
def find_previous_tag(to_ref, tag_pattern): def find_previous_tag(to_ref, tag_pattern, version=""):
# 0. If a target version is provided (e.g. 1.8.0), check if tag v$VERSION already exists.
# If it does, the commits for this release start from the tag BEFORE v$VERSION:
if version:
target_tag = version if version.startswith("v") else f"v{version}"
code_prev, prev_tag, _ = run_git(["describe", "--tags", f"--match={tag_pattern}", "--abbrev=0", f"{target_tag}^"])
if code_prev == 0 and prev_tag:
return prev_tag
# 1. Check if to_ref itself is tagged with an exact tag matching tag_pattern: # 1. Check if to_ref itself is tagged with an exact tag matching tag_pattern:
if tag_pattern: if tag_pattern:
code, stdout, _ = run_git(["describe", "--tags", f"--match={tag_pattern}", "--exact-match", to_ref]) code, stdout, _ = run_git(["describe", "--tags", f"--match={tag_pattern}", "--exact-match", to_ref])
@@ -72,12 +80,12 @@ def find_previous_tag(to_ref, tag_pattern):
return None return None
def collect_commits(from_ref, to_ref, tag_pattern, max_commits): def collect_commits(from_ref, to_ref, tag_pattern, max_commits, version=""):
# Ensure tags are up-to-date # Ensure tags are up-to-date
run_git(["fetch", "--tags", "--prune"]) run_git(["fetch", "--tags", "--prune"])
if not from_ref: if not from_ref:
from_ref = find_previous_tag(to_ref, tag_pattern) from_ref = find_previous_tag(to_ref, tag_pattern, version)
commits = "" commits = ""
if from_ref: if from_ref:
@@ -179,7 +187,7 @@ def query_llm(args, commits_text):
def main(): def main():
args = parse_args() args = parse_args()
commits = collect_commits(args.from_ref, args.to_ref, args.tag_pattern, args.max_commits) commits = collect_commits(args.from_ref, args.to_ref, args.tag_pattern, args.max_commits, args.version)
if not commits: if not commits:
sys.stderr.write("[action-release-notes] No commits discovered; using fallback release notes.\n") sys.stderr.write("[action-release-notes] No commits discovered; using fallback release notes.\n")