From db3cdb4828f664cd195bf4fd660aaa6f4959234c Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Tue, 15 Sep 2026 13:41:47 +0200 Subject: [PATCH] fix: detect prerelease tags of the checked out commit The default end tag was determined by listing all tags and filtering out prereleases. As a result the currently built prerelease tag was never evaluated and the changelog was generated for the previous stable release instead. The end tag is now the tag of the checked out commit, so the prerelease annotation is set as expected. Prerelease filtering remains in place for the start tag only. Additionally the changelog is no longer skipped for prereleases, since consumers of the chart benefit from the changes list before the stable release. Co-authored-by: Copilot --- README.md | 15 +++++++-------- add-annotations.sh | 7 +++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index acf6dee..ba2ce3f 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,14 @@ them to `Chart.yaml`. The action parses conventional commit messages between two Git tags and produces an `artifacthub.io/changes` annotation. Pre-release tags according to [SemVer 2.0](https://semver.org/) (e.g. `-alpha`, `-beta.1`, `-rc.2`) are detected -automatically and result in an `artifacthub.io/prerelease` annotation instead. +automatically and additionally result in an `artifacthub.io/prerelease` annotation. ## Usage ### Auto-detect tags -Without explicit inputs the action determines the two most recent stable (non-pre-release) tags from the Git history: +Without explicit inputs the action uses the currently checked out tag as end tag and the most recent stable +(non-pre-release) tag as start tag: ```yaml steps: @@ -59,13 +60,11 @@ steps: ## Pre-releases Tags containing a hyphen-separated pre-release identifier according to [SemVer 2.0](https://semver.org/) are treated as -pre-releases (e.g. `v1.0.0-alpha`, `v1.0.0-beta.1`, `v2.0.0-rc.2`). When `new-tag` is a pre-release tag, the action: +pre-releases (e.g. `v1.0.0-alpha`, `v1.0.0-beta.1`, `v2.0.0-rc.2`). When `new-tag` is a pre-release tag, the action sets +`artifacthub.io/prerelease: "true"` in `Chart.yaml` in addition to the generated changelog. -1. Sets `artifacthub.io/prerelease: "true"` in `Chart.yaml`. -2. Skips changelog generation entirely. - -When auto-detecting tags (no explicit `old-tag`/`new-tag`), the action ignores pre-release tags and selects the two -most recent stable tags instead. +When auto-detecting tags (no explicit `old-tag`/`new-tag`), the end tag is the tag of the checked out commit - including +pre-releases - while the start tag is always the most recent stable tag. ## Commit type mapping diff --git a/add-annotations.sh b/add-annotations.sh index 7ae0130..1bb218e 100755 --- a/add-annotations.sh +++ b/add-annotations.sh @@ -23,8 +23,9 @@ if [[ ! -f "${CHART_FILE}" ]]; then exit 1 fi -# Determine old and new tags -DEFAULT_NEW_TAG="$(git tag --sort=-version:refname | grep --invert-match --perl-regexp "${PRERELEASE_PATTERN}" | head --lines 1)" +# Determine old and new tags. The new tag is the currently checked out one - including prereleases - so that +# prereleases are detected. Only the old tag is restricted to stable releases. +DEFAULT_NEW_TAG="$(git describe --tags --exact-match HEAD 2>/dev/null || git tag --sort=-version:refname | head --lines 1)" DEFAULT_OLD_TAG="$(git tag --sort=-version:refname | grep --invert-match --perl-regexp "${PRERELEASE_PATTERN}" | head --lines 2 | tail --lines 1)" if [[ -n "${INPUT_OLD_TAG:-}" ]]; then @@ -50,9 +51,7 @@ if [[ -z "$(git tag --list "${NEW_TAG}")" ]]; then fi if [[ "${NEW_TAG}" =~ ${PRERELEASE_PATTERN} ]]; then - echo "INFO: Tag '${NEW_TAG}' is a prerelease, setting prerelease annotation and skipping changelog." yq --no-colors --inplace ".annotations.\"artifacthub.io/prerelease\" = \"true\" | sort_keys(.)" "${CHART_FILE}" - exit 0 fi CHANGE_LOG_YAML="$(mktemp)"