-
Notifications
You must be signed in to change notification settings - Fork 272
/
Copy pathupdate-changelog.sh
executable file
·97 lines (80 loc) · 4.11 KB
/
update-changelog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
set -euo pipefail
DEV_CHANGES_DIR=$1
EMQX_VERSION=$2
[ -z "${DEBUG:-}" ] || set -x
process_changes() {
edition=$1
[ ! -d $DEV_CHANGES_DIR/$edition ] && return
# Add a section for the new version if it doesn't exist along with the Enhancements and Bug Fixes sections
if ! grep -q "^## $EMQX_VERSION" en_US/changes/changes-$edition-v5.md; then
sed -i "3i ## $EMQX_VERSION\n" en_US/changes/changes-$edition-v5.md
sed -i "5i ### Enhancements\n" en_US/changes/changes-$edition-v5.md
sed -i "7i ### Bug Fixes\n" en_US/changes/changes-$edition-v5.md
fi
# Get the line number of the Enhancements section
enhancements_ln=$(grep -n '^### Enhancements' en_US/changes/changes-$edition-v5.md | head -n 1 | cut -d: -f1)
# Increment the line number to leave a blank line before the first enhancement
enhancements_ln=$((enhancements_ln + 1))
shopt -s nullglob
for f in $DEV_CHANGES_DIR/$edition/fix-*.md $DEV_CHANGES_DIR/$edition/feat-*.md; do
pr_num="$(echo "${f}" | sed -E 's/.*-([0-9]+)\.[a-z]+\.md$/\1/')"
if ! grep -q "^- \[#$pr_num\]" en_US/changes/changes-$edition-v5.md; then
if [ $pr_num -lt 10000 ]; then
repo='emqx-platform'
else
repo='emqx'
fi
{
echo "- [#${pr_num}](https://github.com/emqx/$repo/pull/${pr_num}) $(head -n 1 "$f")"
# indent the content
tail -n +2 "$f" | sed '/^$/!s/^/ /'
echo ""
} > /tmp/$pr_num.md
if [[ "$f" =~ ^$DEV_CHANGES_DIR/$edition/feat-.*\.md ]]; then
sed -i "${enhancements_ln}r /tmp/$pr_num.md" en_US/changes/changes-$edition-v5.md
elif [[ "$f" =~ ^$DEV_CHANGES_DIR/$edition/fix-.*\.md ]]; then
# Get the line number of the Bug Fixes section
bugfixes_ln=$(grep -n 'Bug Fixes' en_US/changes/changes-$edition-v5.md | head -n 1 | cut -d: -f1)
# Increment the line number to leave a blank line before the first bug fix
bugfixes_ln=$((bugfixes_ln + 1))
sed -i "${bugfixes_ln}r /tmp/$pr_num.md" en_US/changes/changes-$edition-v5.md
fi
fi
done
# count number of files matching $DEV_CHANGES_DIR/$edition/breaking-*.md pattern
num_files=$(find $DEV_CHANGES_DIR/$edition -type f -name 'breaking-*.md' | wc -l)
# exit the function if no breaking changes files are found
[ $num_files -eq 0 ] && return
major_minor=$(echo $EMQX_VERSION | cut -d. -f1,2)
# create en_US/changes/breaking-changes-$edition-$major_minor.md if it does not exist
if [ ! -f en_US/changes/breaking-changes-$edition-$major_minor.md ]; then
echo "# Incompatible Changes in EMQX $major_minor" > en_US/changes/breaking-changes-$edition-$major_minor.md
echo "" >> en_US/changes/breaking-changes-$edition-$major_minor.md
echo "" >> en_US/changes/breaking-changes-$edition-$major_minor.md
fi
# Add a section for the new version in breaking-changes if it doesn't exist
if ! grep -q "^## $EMQX_VERSION" en_US/changes/breaking-changes-$edition-$major_minor.md; then
version=$( [[ $edition = ce ]] && echo "v$EMQX_VERSION" || echo "e$EMQX_VERSION" )
sed -i "3i ## $version\n" en_US/changes/breaking-changes-$edition-$major_minor.md
fi
for f in $DEV_CHANGES_DIR/$edition/breaking-*.md; do
pr_num="$(echo "${f}" | sed -E 's/.*-([0-9]+)\.[a-z]+\.md$/\1/')"
if ! grep -q "^- \[#$pr_num\]" en_US/changes/breaking-changes-$edition-$major_minor.md; then
if [ $pr_num -lt 10000 ]; then
repo='emqx-platform'
else
repo='emqx'
fi
{
echo "- [#${pr_num}](https://github.com/emqx/$repo/pull/${pr_num}) $(head -n 1 "$f")"
# indent the content
tail -n +2 "$f" | sed '/^$/!s/^/ /'
echo ""
} > /tmp/$pr_num.md
sed -i "4r /tmp/$pr_num.md" en_US/changes/breaking-changes-$edition-$major_minor.md
fi
done
}
process_changes ce
process_changes ee