chore: refactor the format-changelog script
This commit is contained in:
parent
0753146f65
commit
6599c44213
|
@ -0,0 +1,12 @@
|
||||||
|
# ${version}
|
||||||
|
|
||||||
|
## Enhancements
|
||||||
|
|
||||||
|
$(section feat)
|
||||||
|
|
||||||
|
$(section perf)
|
||||||
|
|
||||||
|
## Bug fixes
|
||||||
|
|
||||||
|
$(section fix)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
# ${version}
|
||||||
|
|
||||||
|
## 增强
|
||||||
|
|
||||||
|
$(section feat)
|
||||||
|
|
||||||
|
$(section perf)
|
||||||
|
|
||||||
|
## 修复
|
||||||
|
|
||||||
|
$(section fix)
|
||||||
|
|
|
@ -3,20 +3,27 @@ set -euo pipefail
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
export LANG=C.UTF-8
|
export LANG=C.UTF-8
|
||||||
|
|
||||||
[ "$#" -ne 2 ] && {
|
[ "$#" -ne 4 ] && {
|
||||||
echo "Usage $0 <EMQX version> <en|zh>" 1>&2;
|
echo "Usage $0 <emqx|emqx-enterprise> <LAST TAG> <VERSION> <OUTPUT DIR>" 1>&2;
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
version="${1}"
|
profile="${1}"
|
||||||
language="${2}"
|
last_tag="${2}"
|
||||||
|
version="${3}"
|
||||||
|
output_dir="${4}"
|
||||||
|
languages=("en" "zh")
|
||||||
|
top_dir="$(git rev-parse --show-toplevel)"
|
||||||
|
templates_dir="$top_dir/scripts/changelog-lang-templates"
|
||||||
|
declare -a changes
|
||||||
|
changes=("")
|
||||||
|
|
||||||
changes_dir="$(git rev-parse --show-toplevel)/changes/${version}"
|
echo "generated changelogs from tag:${last_tag} to HEAD"
|
||||||
|
|
||||||
item() {
|
item() {
|
||||||
local filename pr indent
|
local filename pr indent
|
||||||
filename="${1}"
|
filename="${1}"
|
||||||
pr="$(echo "${filename}" | sed -E 's/.*-([0-9]+)\.(en|zh)\.md$/\1/')"
|
pr="$(echo "${filename}" | sed -E 's/.*-([0-9]+)\.[a-z]+\.md$/\1/')"
|
||||||
indent="- [#${pr}](https://github.com/emqx/emqx/pull/${pr}) "
|
indent="- [#${pr}](https://github.com/emqx/emqx/pull/${pr}) "
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
echo "${indent}${line}"
|
echo "${indent}${line}"
|
||||||
|
@ -27,40 +34,36 @@ item() {
|
||||||
|
|
||||||
section() {
|
section() {
|
||||||
local prefix=$1
|
local prefix=$1
|
||||||
for i in "${changes_dir}"/"${prefix}"-*."${language}".md; do
|
for file in "${changes[@]}"; do
|
||||||
item "${i}"
|
if [[ $file =~ .*$prefix-.*$language.md ]]; then
|
||||||
|
item "$file"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "${language}" = "en" ]; then
|
generate() {
|
||||||
cat <<EOF
|
local language=$1
|
||||||
# ${version}
|
local output="$output_dir/${version}_$language.md"
|
||||||
|
local template_file="$templates_dir/$language"
|
||||||
|
local template
|
||||||
|
if [ -f "$template_file" ]; then
|
||||||
|
template=$(cat "$template_file")
|
||||||
|
eval "echo \"$template\" > $output"
|
||||||
|
else
|
||||||
|
echo "Invalid language ${language}" 1>&2;
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
## Enhancements
|
changes_dir=("$top_dir/changes/ce")
|
||||||
|
if [ "$profile" == "emqx-enterprise" ]; then
|
||||||
$(section feat)
|
changes_dir+=("$top_dir/changes/ee")
|
||||||
|
|
||||||
$(section perf)
|
|
||||||
|
|
||||||
## Bug fixes
|
|
||||||
|
|
||||||
$(section fix)
|
|
||||||
EOF
|
|
||||||
elif [ "${language}" = "zh" ]; then
|
|
||||||
cat <<EOF
|
|
||||||
# ${version}
|
|
||||||
|
|
||||||
## 增强
|
|
||||||
|
|
||||||
$(section feat)
|
|
||||||
|
|
||||||
$(section perf)
|
|
||||||
|
|
||||||
## 修复
|
|
||||||
|
|
||||||
$(section fix)
|
|
||||||
EOF
|
|
||||||
else
|
|
||||||
echo "Invalid language ${language}" 1>&2;
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
while read -d "" -r file; do
|
||||||
|
changes+=("$file")
|
||||||
|
done < <(git diff --name-only -z -a "tags/${last_tag}...HEAD" "${changes_dir[@]}")
|
||||||
|
|
||||||
|
for language in "${languages[@]}"; do
|
||||||
|
generate "$language"
|
||||||
|
done
|
||||||
|
|
|
@ -26,6 +26,8 @@ options:
|
||||||
--dryrun: Do not actually create the git tag.
|
--dryrun: Do not actually create the git tag.
|
||||||
--skip-appup: Skip checking appup
|
--skip-appup: Skip checking appup
|
||||||
Useful when you are sure that appup is already updated'
|
Useful when you are sure that appup is already updated'
|
||||||
|
--prev-tag: Provide the prev tag to automatically generate changelogs
|
||||||
|
If this option is absent, the tag found by git describe will be used
|
||||||
|
|
||||||
NOTE: For 5.0 series the current working branch must be 'release-50' for opensource edition
|
NOTE: For 5.0 series the current working branch must be 'release-50' for opensource edition
|
||||||
and 'release-e50' for enterprise edition.
|
and 'release-e50' for enterprise edition.
|
||||||
|
@ -92,6 +94,11 @@ while [ "$#" -gt 0 ]; do
|
||||||
fi
|
fi
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--prev-tag)
|
||||||
|
shift
|
||||||
|
PREV_TAG="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
logerr "Unknown option $1"
|
logerr "Unknown option $1"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -208,10 +215,17 @@ if [ -d "${CHECKS_DIR}" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
generate_changelog () {
|
generate_changelog () {
|
||||||
local CHANGES_EN_MD="changes/${TAG}-en.md" CHANGES_ZH_MD="changes/${TAG}-zh.md"
|
local from_tag="${PREV_TAG:-}"
|
||||||
./scripts/format-changelog.sh "${TAG}" "en" > "$CHANGES_EN_MD"
|
if [[ -z $from_tag ]]; then
|
||||||
./scripts/format-changelog.sh "${TAG}" "zh" > "$CHANGES_ZH_MD"
|
if [ $PROFILE == "emqx" ]; then
|
||||||
git add "$CHANGES_EN_MD" "$CHANGES_ZH_MD"
|
from_tag="$(git describe --tags --abbrev=0 --match 'v*')"
|
||||||
|
else
|
||||||
|
from_tag="$(git describe --tags --abbrev=0 --match 'e*')"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
local output_dir="changes"
|
||||||
|
./scripts/format-changelog.sh $PROFILE "${from_tag}" "${TAG}" $output_dir
|
||||||
|
git add $output_dir
|
||||||
[ -n "$(git status -s)" ] && git commit -m "chore: Generate changelog for ${TAG}"
|
[ -n "$(git status -s)" ] && git commit -m "chore: Generate changelog for ${TAG}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue