From 44f65e674c780c2b61a1ab529db69a7e8d8f4da5 Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Wed, 9 Mar 2022 15:17:12 +0100 Subject: [PATCH] Add "add upcoming entry" option to update_changelog --- scripts/update_changelog.sh | 38 +++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/scripts/update_changelog.sh b/scripts/update_changelog.sh index 6b2900615..36fe6cbc8 100755 --- a/scripts/update_changelog.sh +++ b/scripts/update_changelog.sh @@ -1,19 +1,28 @@ #!/bin/bash - +set -o errexit -o pipefail ORIGINAL_OPTS=$* -OPTS=$(getopt -l "help,since-tag:,full,token:" -o "hft" -- "$@") || exit 1 +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 ] [-u|--upcoming-tag] [-t|--token ] +-h, --help Display help +-f, --full Process changes since the beginning (by default: since latest git version tag) +--since-tag Process changes since git version tag (by default: since latest git version tag) +-u, --upcoming-tag Add a title in CHANGELOG for the new changes +--token Pass changelog github 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) - echo -e "Usage: $0 [-h|--help] [-f|--full] [--since-tag ] [-t|--token ] --h, --help Display help --f, --full Process changes since the beginning (by default: since latest git version tag) ---since-tag Process changes since git version tag (by default: since latest git version tag) ---token Pass changelog github token " + print_usage exit 0 ;; --since-tag) @@ -22,7 +31,13 @@ case $1 in ;; -f|--full) TAG="" - ORIGINAL_OPTS=$(echo "$ORIGINAL_OPTS" | sed "s/\\B$1\\b//") + remove_opt $1 + ;; + -u|--upcoming-tag) + remove_opt $1 + shift + UPCOMING_TAG="$1" + remove_opt $1 ;; --) shift @@ -50,4 +65,11 @@ 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.$$