feat: auto-populate release description from CHANGELOG
- Extract changelog entry for current version when creating releases - Parse CHANGELOG.md and add to release body in Gitea - Falls back to 'See commit history for details.' if no changelog found - Keeps release notes synchronized with version
This commit is contained in:
@@ -15,20 +15,44 @@ API_BASE="${GITEA_API_BASE:-https://git.24unix.net/api/v1}"
|
||||
API_BASE="${API_BASE%/}"
|
||||
RELEASE_TAG="v${VERSION}"
|
||||
API_URL="${API_BASE}/repos/${GITEA_OWNER}/${GITEA_REPO}"
|
||||
CHANGELOG_FILE="$ROOT_DIR/CHANGELOG.md"
|
||||
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
echo "❌ jq is required to parse Gitea responses." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract changelog for this version
|
||||
extract_changelog() {
|
||||
local version="$1"
|
||||
local changelog_file="$2"
|
||||
|
||||
if [[ ! -f "$changelog_file" ]]; then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
awk -v ver="## $version" '
|
||||
/^## [0-9]/ { if (found) exit; if ($0 ~ ver) found=1; next }
|
||||
found && /^## / { exit }
|
||||
found { print }
|
||||
' "$changelog_file" | sed '1d;$d' | sed -e 's/^[[:space:]]*$//' | sed -e :a -e '/^\s*$/d;N;ba'
|
||||
}
|
||||
|
||||
CHANGELOG_BODY="$(extract_changelog "$VERSION" "$CHANGELOG_FILE")"
|
||||
if [[ -z "$CHANGELOG_BODY" ]]; then
|
||||
CHANGELOG_BODY="See commit history for details."
|
||||
fi
|
||||
|
||||
PRERELEASE_FLAG="${GITEA_PRERELEASE:-true}"
|
||||
|
||||
create_payload="$(jq -n \
|
||||
--arg tag "$RELEASE_TAG" \
|
||||
--arg name "iKeyMon ${VERSION}" \
|
||||
--arg target "$TARGET_COMMIT" \
|
||||
--arg body "$CHANGELOG_BODY" \
|
||||
--argjson prerelease "$PRERELEASE_FLAG" \
|
||||
'{ tag_name: $tag, name: $name, target_commitish: $target, draft: false, prerelease: $prerelease }')"
|
||||
'{ tag_name: $tag, name: $name, target_commitish: $target, body: $body, draft: false, prerelease: $prerelease }')"
|
||||
|
||||
response_file="$(mktemp)"
|
||||
http_code=$(curl -sS -w "%{http_code}" -o "$response_file" \
|
||||
|
||||
Reference in New Issue
Block a user