fix: use prior tag before target version when version tag exists
This commit is contained in:
1 parent
e188bd69ba
commit
7867db3f2a
2 files changed
+21
-7
No files matched your search
+9
-3
@@ -109,11 +109,17 @@ 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 not from_ref:
|
||||||
code, out = subprocess.run(["git", "describe", "--tags", f"--match={tag_pattern}", "--exact-match", to_ref], capture_output=True, text=True).returncode, ""
|
if version:
|
||||||
if code == 0:
|
target_tag = version if version.startswith("v") else f"v{version}"
|
||||||
res = subprocess.run(["git", "describe", "--tags", f"--match={tag_pattern}", "--abbrev=0", f"{to_ref}^"], capture_output=True, text=True)
|
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():
|
if res.returncode == 0 and res.stdout.strip():
|
||||||
from_ref = res.stdout.strip()
|
from_ref = res.stdout.strip()
|
||||||
|
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, ""
|
||||||
|
if code == 0:
|
||||||
|
res = subprocess.run(["git", "describe", "--tags", f"--match={tag_pattern}", "--abbrev=0", f"{to_ref}^"], 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:
|
||||||
res = subprocess.run(["git", "describe", "--tags", f"--match={tag_pattern}", "--abbrev=0", to_ref], capture_output=True, text=True)
|
res = subprocess.run(["git", "describe", "--tags", f"--match={tag_pattern}", "--abbrev=0", to_ref], capture_output=True, text=True)
|
||||||
if res.returncode == 0 and res.stdout.strip():
|
if res.returncode == 0 and res.stdout.strip():
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
Reference in new issue
Block a user