Skip to content

Commit da3aa2f

Browse files
github-actions[bot]Liam Cervante
andauthored
Backport of Add changelog and version scripts to automate releases into v1.10 (#36108)
* backport of commit e60aae3 * backport of commit e9b3a54 * backport of commit f0390a5 --------- Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>
1 parent 24236f4 commit da3aa2f

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

scripts/changelog.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) HashiCorp, Inc.
3+
# SPDX-License-Identifier: BUSL-1.1
4+
5+
6+
set -uo pipefail
7+
8+
function usage {
9+
cat <<-'EOF'
10+
Usage: ./changelog.sh <command> [<options>]
11+
12+
Description:
13+
This script will update CHANGELOG.md with the given version and date.
14+
15+
Commands:
16+
prepare <version> <date>
17+
prepare updates the first line in the CHANGELOG.md file with the
18+
given version and date.
19+
20+
./changelog.sh prepare 1.0.0 "November 1, 2021"
21+
22+
cleanup <released-version> <next-version>
23+
cleanup prepends a new section to the CHANGELOG.md file with the given
24+
version and (Unreleased) as the date. If the released version contains a
25+
pre-release tag, the next version will replace the top line instead of
26+
inserting a new section.
27+
EOF
28+
}
29+
30+
function prepare {
31+
VERSION="${1:-}"
32+
DATE="${2:-}"
33+
34+
if [[ -z "$VERSION" || -z "$DATE" ]]; then
35+
echo "missing at least one of [<version>, <date>] arguments"
36+
usage
37+
exit 1
38+
fi
39+
40+
sed -i '' -e "1s/.*/## $VERSION ($DATE)/" CHANGELOG.md
41+
}
42+
43+
function cleanup {
44+
RELEASED_VERSION="${1:-}"
45+
NEXT_VERSION="${2:-}"
46+
47+
if [[ -z "$RELEASED_VERSION" || -z "$NEXT_VERSION" ]]; then
48+
echo "missing at least one of [<released-version>, <next-version>] arguments"
49+
usage
50+
exit 1
51+
fi
52+
53+
if [[ "$RELEASED_VERSION" == *-* ]]; then
54+
# then we have a pre-release version, so we should replace the top line
55+
sed -i '' -e "1s/.*/## $NEXT_VERSION (Unreleased)/" CHANGELOG.md
56+
else
57+
sed -i '' -e "1s/^/## $NEXT_VERSION (Unreleased)\n\n/" CHANGELOG.md
58+
fi
59+
}
60+
61+
function main {
62+
case "$1" in
63+
prepare)
64+
prepare "${@:2}"
65+
66+
;;
67+
cleanup)
68+
cleanup "${@:2}"
69+
70+
;;
71+
*)
72+
usage
73+
exit 1
74+
75+
;;
76+
esac
77+
}
78+
79+
main "$@"
80+
exit $?

scripts/version-bump.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) HashiCorp, Inc.
3+
# SPDX-License-Identifier: BUSL-1.1
4+
5+
6+
set -uo pipefail
7+
8+
function usage {
9+
cat <<-'EOF'
10+
Usage: ./version-bump.sh <version>
11+
12+
Description:
13+
This script will update the version/VERSION file with the given version.
14+
EOF
15+
}
16+
17+
function update_version {
18+
VERSION="${1:-}"
19+
20+
if [[ -z "$VERSION" ]]; then
21+
echo "missing at least one of [<version>] arguments"
22+
usage
23+
exit 1
24+
fi
25+
26+
echo "$VERSION" > version/VERSION
27+
}
28+
29+
update_version "$@"
30+
exit $?

0 commit comments

Comments
 (0)