-
Notifications
You must be signed in to change notification settings - Fork 361
/
Copy pathupdate_changelog.sh
executable file
·75 lines (64 loc) · 2.13 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
#!/bin/bash
set -o errexit -o pipefail
ORIGINAL_OPTS=$*
OPTS=$(getopt -l "help,since-tag:,upcoming-tag:,full,token:" -o "hu:ft" -- "$@") || exit 1
function print_usage() {
echo -e "Usage: $0 [-h|--help] [-f|--full] [--since-tag <tag>] [-u|--upcoming-tag] <tag> [-t|--token <token>]
-h, --help Display help
-f, --full Process changes since the beginning (by default: since latest git version tag)
--since-tag <tag> Process changes since git version tag <tag> (by default: since latest git version tag)
-u, --upcoming-tag <tag> Add a <tag> title in CHANGELOG for the new changes
--token <token> Pass changelog github token <token>"
}
function remove_opt() {
ORIGINAL_OPTS=$(echo "$ORIGINAL_OPTS" | sed "s/\\B$1\\b//")
}
eval set -- "$OPTS"
while true
do
case $1 in
-h|--help)
print_usage
exit 0
;;
--since-tag)
shift
TAG="$1"
;;
-f|--full)
TAG="<FULL>"
remove_opt $1
;;
-u|--upcoming-tag)
remove_opt $1
shift
UPCOMING_TAG="$1"
remove_opt $1
;;
--)
shift
break
;;
esac
shift
done
if [ -z "$TAG" ]
then
# Use latest git version tag
TAG=$(git tag --sort=creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | tail -1)
ORIGINAL_OPTS="$ORIGINAL_OPTS --since-tag $TAG"
fi
echo "Git version tag: $TAG"
cp CHANGELOG.md /tmp/CHANGELOG.md.$$
# Consolidate tag for matching changelog entries
TAG=$(echo "$TAG" | sed -e 's/-\([A-Za-z]*\)[^A-Za-z]*/-\1/' -e 's/-$//')
echo "Consolidated tag: $TAG"
sed -i -n "/^## \\[${TAG}[^]]*\\]/,\$p" CHANGELOG.md
github_changelog_generator -u CosmWasm -p cw-plus --base CHANGELOG.md $ORIGINAL_OPTS || cp /tmp/CHANGELOG.md.$$ CHANGELOG.md
if [ -n "$UPCOMING_TAG" ]
then
# Add "upcoming" version tag
TODAY=$(date "+%Y-%m-%d")
sed -i "s+\[Full Changelog\](https://github.com/CosmWasm/cw-plus/compare/\(.*\)\.\.\.HEAD)+[Full Changelog](https://github.com/CosmWasm/cw-plus/compare/$UPCOMING_TAG...HEAD)\n\n## [$UPCOMING_TAG](https://github.com/CosmWasm/cw-plus/tree/$UPCOMING_TAG) ($TODAY)\n\n[Full Changelog](https://github.com/CosmWasm/cw-plus/compare/\1...$UPCOMING_TAG)+" CHANGELOG.md
fi
rm -f /tmp/CHANGELOG.md.$$