Skip to content

Commit 5a05933

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

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

scripts/release.sh

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
ORIGIN=${ORIGIN:-"origin"}
20+
BRANCH=${BRANCH:-"release-${MINOR_VERSION}"}
21+
22+
# ensuring the minor-version is identical.
23+
source_version=$(grep -E "\s+Version\s*=" ./version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
24+
if [[ "${source_version}" != "${RELEASE_VERSION}" ]]; then
25+
source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
26+
if [[ "${source_minor_version}" != "${MINOR_VERSION}" ]]; then
27+
echo "Wrong bbolt minor version in version.go. Expected ${MINOR_VERSION} but got ${source_minor_version}. Aborting."
28+
exit 1
29+
fi
30+
fi
31+
32+
# creating a branch to bump 'version.go'.
33+
date_string=$(date +%Y%m%d)
34+
local_branch_name="version_${date_string}"
35+
local_branch_err=$(git checkout -b "${local_branch_name}" | grep -E "error|fatal" || true )
36+
if [[ -n "${local_branch_err}" ]]; then
37+
echo "${local_branch_err}"
38+
fi
39+
40+
# bump 'version.go'.
41+
echo "Updating version from '${source_version}' to '${RELEASE_VERSION}' in 'version.go'"
42+
sed -i "s/${source_version}/${RELEASE_VERSION}/g" ./version/version.go
43+
44+
# push 'version.go' to remote.
45+
echo "committing 'version.go'"
46+
git add ./version/version.go
47+
git commit -s -m "Update version to ${VERSION}"
48+
git push -u -f "${ORIGIN}" "${local_branch_name}"
49+
echo "'version.go' has been committed to remote repo."
50+
51+
# create tag and push to remote.
52+
remote_tag_exists=$(git ls-remote --tags "${REPOSITORY}" | grep -c "${INPUT}" || true)
53+
if [ "${remote_tag_exists}" -gt 0 ]; then
54+
echo "Release version tag exists on remote. Checking out refs/tags/${INPUT}"
55+
git checkout -q "tags/${INPUT}"
56+
elif [ "${remote_tag_exists}" -eq 0 ]; then
57+
echo "Creating new tag for '${INPUT}'"
58+
git tag -f "${INPUT}"
59+
git push -f origin "${INPUT}"
60+
fi
61+
echo "Tag '${INPUT}' has been created and pushed to remote repo."
62+
echo "SUCCESS"

0 commit comments

Comments
 (0)