From 018fb2eba165ea1fb17276ae0e1ea3cfc785dc31 Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 18:59:08 +0000 Subject: [PATCH 1/9] chore: Generate changelog from template Resolves: #63 --- scripts/create-clog.sh | 72 +++++++++++++++++++++++++++++++++++ scripts/template_changelog.md | 20 ++++++++++ 2 files changed, 92 insertions(+) create mode 100755 scripts/create-clog.sh create mode 100644 scripts/template_changelog.md diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh new file mode 100755 index 000000000..764278320 --- /dev/null +++ b/scripts/create-clog.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# +# create-clog.sh +# +# Dependencies: sed +# +# Description: Uses template_changelog.md to create a new changelog. +# +# Examples: +# ./scripts/create-clog.sh "1.18.0" "05/18/2021" + + +set -eou pipefail + +VERSION_DELIM="<% X.Y.Z %>" +RELEASE_DATE_DELIM="<% MM/DD/YYYY %>" +VERSION="" +RELEASE_DATE="" + +# usage prints information for how to use this program +usage () { + echo "Usage: create-clog " + echo "Create a changelog from a template" + echo "Arugments:" + echo " : A version string 'x.y.z'" + echo " : A date string 'mm/dd/yyyy'" +} + +# init parses arguments and initializes all variables. +init () { + lenArgs=2 + if [ "$#" -ne $lenArgs ]; then + echo "illegal number of arguments." + echo "Expected: $lenArgs Received: $#" + usage + exit 1 + fi + + if [ -z "${1-}" ]; then + echo "version argument is empty." + echo "Expected a version string like 'x.y.z'" + usage + exit 1 + fi + + if [ -z "${2-}" ]; then + echo "release-date argument is empty." + echo "Expected a date string like 'mm/dd/yyyy'" + usage + exit 1 + fi + + VERSION="${1}" + RELEASE_DATE="${2}" +} + +# createFromTemplate creates a new changelog file from template_changelog.md +# using VERSION and RELEASE_DATE. +createFromTemplate () { + echo "Creating template using version: ${VERSION} and release date: ${RELEASE_DATE}" + pushd "$(git rev-parse --show-toplevel)" > /dev/null + clogPath="./changelog/${VERSION}.md" + cp ./scripts/template_changelog.md "${clogPath}" + sed -i "s|${VERSION_DELIM}|${VERSION}|g" "${clogPath}" + sed -i "s|${RELEASE_DATE_DELIM}|${RELEASE_DATE}|g" "${clogPath}" + popd > /dev/null +} + +# main program +init "$@" +createFromTemplate +echo "Done" \ No newline at end of file diff --git a/scripts/template_changelog.md b/scripts/template_changelog.md new file mode 100644 index 000000000..dfe099593 --- /dev/null +++ b/scripts/template_changelog.md @@ -0,0 +1,20 @@ +--- +title: "<% X.Y.Z %>" +description: "Released on <% MM/DD/YYYY %>" +--- + +### Breaking Changes ❗ + +There are no breaking changes in <% X.Y.Z %>. + +### Features ✨ + +There are no new features in <% X.Y.Z %>. + +### Bug Fixes 🐛 + +There are no bug fixes in <% X.Y.Z %>. + +### Security Updates 🔐 + +There are no security updates in <% X.Y.Z %>. From 4180585a6f4d626546b3f65135f00600aad64a8a Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 19:05:38 +0000 Subject: [PATCH 2/9] fixup! chore: Generate changelog from template --- scripts/create-clog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh index 764278320..159ae45c3 100755 --- a/scripts/create-clog.sh +++ b/scripts/create-clog.sh @@ -69,4 +69,4 @@ createFromTemplate () { # main program init "$@" createFromTemplate -echo "Done" \ No newline at end of file +echo "Done" From 4daca01907b62083a9162f15fcd32f81973adfbd Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 14:11:08 -0500 Subject: [PATCH 3/9] Too much arugula Co-authored-by: Jonathan Yu --- scripts/create-clog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh index 159ae45c3..c35ac8f47 100755 --- a/scripts/create-clog.sh +++ b/scripts/create-clog.sh @@ -21,7 +21,7 @@ RELEASE_DATE="" usage () { echo "Usage: create-clog " echo "Create a changelog from a template" - echo "Arugments:" + echo "Arguments:" echo " : A version string 'x.y.z'" echo " : A date string 'mm/dd/yyyy'" } From deb70858dfa92013f97b1febbd9ad9db010488ca Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 14:11:30 -0500 Subject: [PATCH 4/9] Use Function Co-authored-by: Jonathan Yu --- scripts/create-clog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh index c35ac8f47..605328fc1 100755 --- a/scripts/create-clog.sh +++ b/scripts/create-clog.sh @@ -18,7 +18,7 @@ VERSION="" RELEASE_DATE="" # usage prints information for how to use this program -usage () { +function usage () { echo "Usage: create-clog " echo "Create a changelog from a template" echo "Arguments:" From bdb8950766111d95e01611df560c3d2cfc801bae Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 19:15:21 +0000 Subject: [PATCH 5/9] fixup! Use Function --- scripts/create-clog.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh index 605328fc1..f57a7ebde 100755 --- a/scripts/create-clog.sh +++ b/scripts/create-clog.sh @@ -27,7 +27,7 @@ function usage () { } # init parses arguments and initializes all variables. -init () { +function init () { lenArgs=2 if [ "$#" -ne $lenArgs ]; then echo "illegal number of arguments." @@ -54,9 +54,9 @@ init () { RELEASE_DATE="${2}" } -# createFromTemplate creates a new changelog file from template_changelog.md +# create_from_template creates a new changelog file from template_changelog.md # using VERSION and RELEASE_DATE. -createFromTemplate () { +function create_from_template () { echo "Creating template using version: ${VERSION} and release date: ${RELEASE_DATE}" pushd "$(git rev-parse --show-toplevel)" > /dev/null clogPath="./changelog/${VERSION}.md" @@ -68,5 +68,5 @@ createFromTemplate () { # main program init "$@" -createFromTemplate +create_from_template echo "Done" From 61e62cb658dfb9ab5a90dc989650a7e56ac6fc8a Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 19:18:37 +0000 Subject: [PATCH 6/9] Dont use {} --- scripts/create-clog.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh index f57a7ebde..4d0df03f2 100755 --- a/scripts/create-clog.sh +++ b/scripts/create-clog.sh @@ -50,19 +50,19 @@ function init () { exit 1 fi - VERSION="${1}" - RELEASE_DATE="${2}" + VERSION="$1" + RELEASE_DATE="$2" } # create_from_template creates a new changelog file from template_changelog.md # using VERSION and RELEASE_DATE. function create_from_template () { - echo "Creating template using version: ${VERSION} and release date: ${RELEASE_DATE}" + echo "Creating template using version: $VERSION and release date: $RELEASE_DATE" pushd "$(git rev-parse --show-toplevel)" > /dev/null - clogPath="./changelog/${VERSION}.md" - cp ./scripts/template_changelog.md "${clogPath}" - sed -i "s|${VERSION_DELIM}|${VERSION}|g" "${clogPath}" - sed -i "s|${RELEASE_DATE_DELIM}|${RELEASE_DATE}|g" "${clogPath}" + clogPath="./changelog/$VERSION.md" + cp ./scripts/template_changelog.md "$clogPath" + sed -i "s|$VERSION_DELIM|$VERSION|g" "$clogPath" + sed -i "s|$RELEASE_DATE_DELIM|$RELEASE_DATE|g" "$clogPath" popd > /dev/null } From 83d7719fa74bee495a2ef507f3bc5cbae7e269f8 Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 19:51:14 +0000 Subject: [PATCH 7/9] Use getopt --- scripts/create-clog.sh | 62 ++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh index 4d0df03f2..a442236e2 100755 --- a/scripts/create-clog.sh +++ b/scripts/create-clog.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash # -# create-clog.sh +# create-clog.sh [--version=] [--release-date=] # -# Dependencies: sed +# Dependencies: getopt sed # # Description: Uses template_changelog.md to create a new changelog. # # Examples: -# ./scripts/create-clog.sh "1.18.0" "05/18/2021" +# ./scripts/create-clog.sh --version="1.18.0" --release-date="05/18/2021" set -eou pipefail @@ -17,41 +17,67 @@ RELEASE_DATE_DELIM="<% MM/DD/YYYY %>" VERSION="" RELEASE_DATE="" -# usage prints information for how to use this program +# usage prints information for how to use this program. Exits with status code +# 1. function usage () { - echo "Usage: create-clog " + echo "Usage: create-clog [--version=] [--release-date=]" echo "Create a changelog from a template" echo "Arguments:" echo " : A version string 'x.y.z'" echo " : A date string 'mm/dd/yyyy'" + exit 1 } # init parses arguments and initializes all variables. function init () { - lenArgs=2 - if [ "$#" -ne $lenArgs ]; then + options=$(getopt \ + --name="$(basename "$0")" \ + --longoptions=" \ + help, \ + release-date:, \ + version:" \ + --options="h" \ + -- "$@") + [ $? -eq 0 ] || { echo "illegal number of arguments." - echo "Expected: $lenArgs Received: $#" + echo "Expected: 2 Received: $#" usage - exit 1 - fi + } + + eval set -- "$options" + + while true; do + case "$1" in + -h|--help) + usage + ;; + --version) + shift; + VERSION="$1" + ;; + --release-date) + shift; + RELEASE_DATE="$1" + ;; + --) + shift + break + ;; + esac + shift + done - if [ -z "${1-}" ]; then + if [ -z "$VERSION" ]; then echo "version argument is empty." echo "Expected a version string like 'x.y.z'" usage - exit 1 fi - - if [ -z "${2-}" ]; then + + if [ -z "$RELEASE_DATE" ]; then echo "release-date argument is empty." echo "Expected a date string like 'mm/dd/yyyy'" usage - exit 1 fi - - VERSION="$1" - RELEASE_DATE="$2" } # create_from_template creates a new changelog file from template_changelog.md From 9ea024199ba1b5d8d56902763874ad292b03d2f3 Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 19:54:50 +0000 Subject: [PATCH 8/9] fixup! Use getopt --- scripts/create-clog.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh index a442236e2..58d438e04 100755 --- a/scripts/create-clog.sh +++ b/scripts/create-clog.sh @@ -39,8 +39,6 @@ function init () { --options="h" \ -- "$@") [ $? -eq 0 ] || { - echo "illegal number of arguments." - echo "Expected: 2 Received: $#" usage } From c0d42e81bef6a96f63b63145126a1f6acb4061d6 Mon Sep 17 00:00:00 2001 From: G r e y Date: Tue, 23 Mar 2021 19:55:36 +0000 Subject: [PATCH 9/9] fixup! Use getopt --- scripts/create-clog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create-clog.sh b/scripts/create-clog.sh index 58d438e04..453e1a3fe 100755 --- a/scripts/create-clog.sh +++ b/scripts/create-clog.sh @@ -45,7 +45,7 @@ function init () { eval set -- "$options" while true; do - case "$1" in + case "${1:-}" in -h|--help) usage ;;