-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
1221f33
commit 27159db
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <command> [<options>] | ||
Description: | ||
This script will update CHANGELOG.md with the given version and date. | ||
Commands: | ||
prepare <version> <date> | ||
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 <released-version> <next-version> | ||
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 [<version>, <date>] 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 [<released-version>, <next-version>] 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 $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <version> | ||
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 [<version>] arguments" | ||
usage | ||
exit 1 | ||
fi | ||
|
||
echo "$VERSION" > version/VERSION | ||
} | ||
|
||
update_version "$@" | ||
exit $? |