Skip to content

Commit 9afab2b

Browse files
committed
release: add release script
Signed-off-by: Mustafa Elbehery <[email protected]>
1 parent 232894f commit 9afab2b

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

scripts/release.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
echo "enter release string according to semantic versioning (e.g. v1.2.3)."
8+
read -r INPUT
9+
if [[ ! "${INPUT}" =~ ^v[0-9]+.[0-9]+.[0-9]+ ]]; then
10+
echo "Expected 'version' param of the form 'v<major-version>.<minor-version>.<patch-version>' but got '${INPUT}'"
11+
exit 1
12+
fi
13+
14+
VERSION=${INPUT#v}
15+
RELEASE_VERSION="${VERSION}"
16+
MINOR_VERSION=$(echo "${VERSION}" | cut -d. -f 1-2)
17+
18+
REPOSITORY=${REPOSITORY:-"[email protected]:etcd-io/bbolt.git"}
19+
REMOTE="${REMOTE:-"origin"}"
20+
21+
# ensuring the minor-version is identical.
22+
source_version=$(grep -E "\s+Version\s*=" ./version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
23+
if [[ "${source_version}" != "${RELEASE_VERSION}" ]]; then
24+
source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
25+
if [[ "${source_minor_version}" != "${MINOR_VERSION}" ]]; then
26+
echo "Wrong bbolt minor version in version.go. Expected ${MINOR_VERSION} but got ${source_minor_version}. Aborting."
27+
exit 1
28+
fi
29+
fi
30+
31+
# creating a branch to bump 'version.go'.
32+
date_string=$(date +%Y%m%d)
33+
local_branch_name="version_${date_string}"
34+
local_branch_err=$(git checkout -b "${local_branch_name}" | grep -E "error|fatal" || true )
35+
if [[ -n "${local_branch_err}" ]]; then
36+
echo "${local_branch_err}"
37+
fi
38+
39+
# bump 'version.go'.
40+
echo "Updating version from '${source_version}' to '${RELEASE_VERSION}' in 'version.go'"
41+
sed -i "s/${source_version}/${RELEASE_VERSION}/g" ./version/version.go
42+
43+
# push 'version.go' to remote.
44+
echo "committing 'version.go'"
45+
git add ./version/version.go
46+
git commit -s -m "Update version to ${VERSION}"
47+
git push -u -f "${REMOTE}" "${local_branch_name}"
48+
echo "'version.go' has been committed to remote repo."
49+
50+
# create tag and push to remote.
51+
remote_tag_exists=$(git ls-remote --tags "${REPOSITORY}" | grep -c "${INPUT}" || true)
52+
if [ "${remote_tag_exists}" -gt 0 ]; then
53+
echo "Release version tag exists on remote. Checking out refs/tags/${INPUT}"
54+
git checkout -q "tags/${INPUT}"
55+
elif [ "${remote_tag_exists}" -eq 0 ]; then
56+
echo "Creating new tag for '${INPUT}'"
57+
git tag -f "${INPUT}"
58+
git push -f "${REMOTE}" "${INPUT}"
59+
fi
60+
echo "Tag '${INPUT}' has been created and pushed to remote repo."
61+
echo "SUCCESS"

0 commit comments

Comments
 (0)