From 27159db98c152657438fbe7f0a23cc7350864275 Mon Sep 17 00:00:00 2001 From: Liam Cervante Date: Wed, 27 Nov 2024 13:08:47 +0100 Subject: [PATCH] Add changelog and version scripts to automate releases (#36099) * Add changelog and version scripts to automate releases * not always replacing the first line * make copyrightfix --- scripts/changelog.sh | 80 +++++++++++++++++++++++++++++++++++++++++ scripts/version-bump.sh | 30 ++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100755 scripts/changelog.sh create mode 100755 scripts/version-bump.sh diff --git a/scripts/changelog.sh b/scripts/changelog.sh new file mode 100755 index 000000000000..f5c23c9d2381 --- /dev/null +++ b/scripts/changelog.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + + +set -uo pipefail + +function usage { + cat <<-'EOF' +Usage: ./changelog.sh [] + +Description: + This script will update CHANGELOG.md with the given version and date. + +Commands: + prepare + prepare updates the first line in the CHANGELOG.md file with the + given version and date. + + ./changelog.sh prepare 1.0.0 "November 1, 2021" + + cleanup + cleanup prepends a new section to the CHANGELOG.md file with the given + version and (Unreleased) as the date. If the released version contains a + pre-release tag, the next version will replace the top line instead of + inserting a new section. +EOF +} + +function prepare { + VERSION="${1:-}" + DATE="${2:-}" + + if [[ -z "$VERSION" || -z "$DATE" ]]; then + echo "missing at least one of [, ] arguments" + usage + exit 1 + fi + + sed -i '' -e "1s/.*/## $VERSION ($DATE)/" CHANGELOG.md +} + +function cleanup { + RELEASED_VERSION="${1:-}" + NEXT_VERSION="${2:-}" + + if [[ -z "$RELEASED_VERSION" || -z "$NEXT_VERSION" ]]; then + echo "missing at least one of [, ] arguments" + usage + exit 1 + fi + + if [[ "$RELEASED_VERSION" == *-* ]]; then + # then we have a pre-release version, so we should replace the top line + sed -i '' -e "1s/.*/## $NEXT_VERSION (Unreleased)/" CHANGELOG.md + else + sed -i '' -e "1s/^/## $NEXT_VERSION (Unreleased)\n\n/" CHANGELOG.md + fi +} + +function main { + case "$1" in + prepare) + prepare "${@:2}" + + ;; + cleanup) + cleanup "${@:2}" + + ;; + *) + usage + exit 1 + + ;; + esac +} + +main "$@" +exit $? diff --git a/scripts/version-bump.sh b/scripts/version-bump.sh new file mode 100755 index 000000000000..b75843d4af96 --- /dev/null +++ b/scripts/version-bump.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + + +set -uo pipefail + +function usage { + cat <<-'EOF' +Usage: ./version-bump.sh + +Description: + This script will update the version/VERSION file with the given version. +EOF +} + +function update_version { + VERSION="${1:-}" + + if [[ -z "$VERSION" ]]; then + echo "missing at least one of [] arguments" + usage + exit 1 + fi + + echo "$VERSION" > version/VERSION +} + +update_version "$@" +exit $?