feat: initial rpm-changelog composite action
Generates an rpm %changelog entry from git history and prepends it to the target spec file. Runs in release CI so every tag push gets a fresh dated entry covering the commits since the previous matching tag. Avoids stale dates, forgotten bumps, and bogus-weekday warnings. Inputs: spec path, version, optional release suffix, author, tag-pattern, exclude-patterns. The last two make the defaults (v* tags, filter bump-version chores and merges) tweakable for projects with different conventions. Migrated from inline logic in helexa/cortex so any project can adopt the same pattern with a single uses: reference. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
86
scripts/generate-rpm-changelog.sh
Executable file
86
scripts/generate-rpm-changelog.sh
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
# Generate an rpm %changelog entry for this release and prepend it to
|
||||
# the spec's existing %changelog section.
|
||||
#
|
||||
# Usage: generate-rpm-changelog.sh <spec-file> <version>
|
||||
#
|
||||
# Environment overrides:
|
||||
# CHANGELOG_AUTHOR — "Name <email>", default "Gitea Actions <actions@git.lair.cafe>"
|
||||
# RELEASE — release suffix, default "1"
|
||||
# TAG_PATTERN — glob for release tags, default "v*"
|
||||
# EXCLUDE_PATTERNS — newline-separated grep -E patterns to drop
|
||||
#
|
||||
# Collects commits since the previous matching tag, drops filtered
|
||||
# lines (bump-version chore commits, merges, etc.), and writes a
|
||||
# dated entry.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SPEC="$1"
|
||||
VERSION="$2"
|
||||
AUTHOR="${CHANGELOG_AUTHOR:-Gitea Actions <actions@git.lair.cafe>}"
|
||||
RELEASE="${RELEASE:-1}"
|
||||
TAG_PATTERN="${TAG_PATTERN:-v*}"
|
||||
EXCLUDE_PATTERNS="${EXCLUDE_PATTERNS:-$'^- chore: bump version\n^- Merge'}"
|
||||
|
||||
if [ ! -f "$SPEC" ]; then
|
||||
echo "error: spec file not found: $SPEC" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! grep -q '^%changelog' "$SPEC"; then
|
||||
echo "error: no %changelog section in $SPEC — refusing to mangle" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Find the previous release tag (exclude the current tag at HEAD).
|
||||
PREV_TAG=$(git describe --tags --abbrev=0 --match="$TAG_PATTERN" HEAD^ 2>/dev/null || echo "")
|
||||
|
||||
if [ -n "$PREV_TAG" ]; then
|
||||
RAW=$(git log --no-merges --pretty=format:'- %s' "${PREV_TAG}..HEAD")
|
||||
|
||||
# Build a combined grep -E pattern from the exclude list; drop blanks.
|
||||
COMBINED=""
|
||||
while IFS= read -r pat; do
|
||||
[ -z "$pat" ] && continue
|
||||
if [ -z "$COMBINED" ]; then
|
||||
COMBINED="$pat"
|
||||
else
|
||||
COMBINED="${COMBINED}|${pat}"
|
||||
fi
|
||||
done <<< "$EXCLUDE_PATTERNS"
|
||||
|
||||
if [ -n "$COMBINED" ]; then
|
||||
LOG=$(printf '%s\n' "$RAW" | grep -Ev "$COMBINED" || true)
|
||||
else
|
||||
LOG="$RAW"
|
||||
fi
|
||||
else
|
||||
LOG=""
|
||||
fi
|
||||
|
||||
if [ -z "$LOG" ]; then
|
||||
LOG="- No user-visible changes"
|
||||
fi
|
||||
|
||||
DATE=$(LC_ALL=C date -u +'%a %b %d %Y')
|
||||
ENTRY="* ${DATE} ${AUTHOR} - ${VERSION}-${RELEASE}
|
||||
${LOG}
|
||||
"
|
||||
|
||||
# Prepend the entry to the %changelog section.
|
||||
TMP=$(mktemp)
|
||||
awk -v entry="$ENTRY" '
|
||||
inserted == 0 && /^%changelog[[:space:]]*$/ {
|
||||
print
|
||||
print entry
|
||||
inserted = 1
|
||||
next
|
||||
}
|
||||
{ print }
|
||||
' "$SPEC" > "$TMP"
|
||||
|
||||
mv "$TMP" "$SPEC"
|
||||
|
||||
echo "Added changelog entry for ${VERSION}-${RELEASE}:"
|
||||
echo "$ENTRY"
|
||||
Reference in New Issue
Block a user