Files
ah-annotations/add-annotations.sh
T
volker.raschekandCopilot db3cdb4828
Install yq / install-yq (ubuntu-latest-arm64, arm64, linux) (push) Successful in 12s
Markdown linter / markdown-link-checker (push) Successful in 37s
Markdown linter / markdown-lint (push) Successful in 35s
Install yq / install-yq (ubuntu-latest-amd64, amd64, linux) (push) Successful in 10s
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 <copilot@github.com>
2026-09-15 13:41:47 +02:00

112 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# Generate ArtifactHub changelog annotations from git commit history
# ============================================================================
set -euo pipefail
readonly CHART_FILE="${CHART_FILE:="Chart.yaml"}"
readonly PRERELEASE_PATTERN="\-[a-zA-Z0-9]+([-\.][a-zA-Z0-9]+)*$"
CHANGE_LOG_YAML=""
cleanup() {
if [[ -n "${CHANGE_LOG_YAML:-}" && -f "${CHANGE_LOG_YAML}" ]]; then
rm -f "${CHANGE_LOG_YAML}"
fi
}
trap cleanup EXIT
if [[ ! -f "${CHART_FILE}" ]]; then
echo "ERROR: ${CHART_FILE} not found!" >&2
exit 1
fi
# 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
OLD_TAG="${INPUT_OLD_TAG}"
else
OLD_TAG="${DEFAULT_OLD_TAG}"
fi
if [[ -n "${INPUT_NEW_TAG:-}" ]]; then
NEW_TAG="${INPUT_NEW_TAG}"
else
NEW_TAG="${DEFAULT_NEW_TAG}"
fi
if [[ -z "$(git tag --list "${OLD_TAG}")" ]]; then
echo "ERROR: Tag '${OLD_TAG}' not found!" >&2
exit 1
fi
if [[ -z "$(git tag --list "${NEW_TAG}")" ]]; then
echo "ERROR: Tag '${NEW_TAG}' not found!" >&2
exit 1
fi
if [[ "${NEW_TAG}" =~ ${PRERELEASE_PATTERN} ]]; then
yq --no-colors --inplace ".annotations.\"artifacthub.io/prerelease\" = \"true\" | sort_keys(.)" "${CHART_FILE}"
fi
CHANGE_LOG_YAML="$(mktemp)"
echo "[]" > "${CHANGE_LOG_YAML}"
map_type_to_kind() {
case "${1}" in
feat)
echo "added"
;;
fix)
echo "fixed"
;;
chore|style|test|ci|docs|refac)
echo "changed"
;;
revert)
echo "removed"
;;
sec)
echo "security"
;;
*)
echo "skip"
;;
esac
}
COMMIT_TITLES="$(git log --pretty=format:"%s" "${OLD_TAG}..${NEW_TAG}")"
echo "INFO: Generate change log entries from ${OLD_TAG} until ${NEW_TAG}"
while IFS= read -r line; do
if [[ "${line}" =~ ^([a-zA-Z]+)(\([^\)]+\))?\:\ (.+)$ ]]; then
TYPE="${BASH_REMATCH[1]}"
KIND="$(map_type_to_kind "${TYPE}")"
if [[ "${KIND}" == "skip" ]]; then
continue
fi
DESC="${BASH_REMATCH[3]}"
echo "- ${KIND}: ${DESC}"
jq --arg kind "${KIND}" --arg description "${DESC}" '. += [ $ARGS.named ]' < "${CHANGE_LOG_YAML}" > "${CHANGE_LOG_YAML}.new"
mv "${CHANGE_LOG_YAML}.new" "${CHANGE_LOG_YAML}"
fi
done <<< "${COMMIT_TITLES}"
if [[ -s "${CHANGE_LOG_YAML}" ]]; then
yq --inplace --input-format json --output-format yml "${CHANGE_LOG_YAML}"
yq --no-colors --inplace ".annotations.\"artifacthub.io/changes\" |= loadstr(\"${CHANGE_LOG_YAML}\") | sort_keys(.)" "${CHART_FILE}"
else
echo "ERROR: Changelog file is empty: ${CHANGE_LOG_YAML}" >&2
exit 1
fi