forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·123 lines (101 loc) · 2.53 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
REPO_DIR="$(cd "$(dirname "$0")"/.. && pwd)"
cd "${REPO_DIR}"
TRUNK="main"
usage() {
echo "Usage: $0 -y [-C] [-f]" >&2
echo >&2
echo " -y Proceed with release. Must be specified." >&2
echo " -C Only prepare the changelog; do not commit, tag or push" >&2
echo " -T Skip tests before preparing release" >&2
echo " -f Force release prep when \`${TRUNK}\` branch is not checked out" >&2
echo >&2
}
while getopts ':yCTfh' opt; do
case "$opt" in
y)
GOTIME=1
;;
C)
NOTAG=1
;;
T)
NOTEST=1
;;
f)
FORCE=1
;;
*)
usage
exit 1
;;
esac
done
if [[ "${GOTIME}" != "1" ]]; then
echo "Specify \`-y\` to initiate release!" >&2
usage
exit 1
fi
if [[ "$(uname)" == "Darwin" ]]; then
echo "(Using BSD sed)"
SED="sed -E"
else
echo "(Using GNU sed)"
SED="sed -r"
fi
DATE="$(date '+%B %d, %Y')"
PROVIDER_URL="https:\/\/github.com\/hashicorp\/terraform-provider-azurerm\/issues"
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ "${BRANCH}" != "${TRUNK}" ]]; then
if [[ "${FORCE}" == "1" ]]; then
echo "Caution: Proceeding with release prep on branch: ${BRANCH}"
else
echo "Release must be prepped on \`${TRUNK}\` branch. Specify \`-f\` to override." >&2
exit 1
fi
fi
if [[ "$(git status --short)" != "" ]]; then
echo "Error: working tree is dirty" >&2
exit 4
fi
set -e
if [[ "${NOTEST}" == "1" ]]; then
echo "Warning: Skipping tests"
else
echo "Running tests..."
( set -x; TF_ACC= scripts/run-test.sh )
fi
echo "Preparing changelog for release..."
if [[ ! -f CHANGELOG.md ]]; then
echo "Error: CHANGELOG.md not found."
exit 2
fi
# Get the next release
RELEASE="$($SED -n 's/^## v?([0-9.]+) \(Unreleased\)/\1/p' CHANGELOG.md)"
if [[ "${RELEASE}" == "" ]]; then
echo "Error: could not determine next release in CHANGELOG.md" >&2
exit 3
fi
# Ensure latest changes are checked out
( set -x; git pull --rebase origin "${TRUNK}" )
# Replace [GH-nnnn] references with issue links
( set -x; $SED -i.bak "s/\[GH-([0-9]+)\]/\(\[#\1\]\(${PROVIDER_URL}\/\1\)\)/g" CHANGELOG.md )
# Set the date for the latest release
( set -x; $SED -i.bak "s/^(## v?[0-9.]+) \(Unreleased\)/\1 (${DATE})/i" CHANGELOG.md )
rm CHANGELOG.md.bak
if [[ "${NOTAG}" == "1" ]]; then
echo "Warning: Skipping commit, tag and push."
exit 0
fi
echo "Committing changelog..."
(
set -x
git commit CHANGELOG.md -m v"${RELEASE}"
git push origin "${BRANCH}"
)
echo "Releasing v${RELEASE}..."
(
set -x
git tag v"${RELEASE}"
git push origin v"${RELEASE}"
)