Skip to content

Commit 0b369bb

Browse files
committed
release: add release script
Signed-off-by: Mustafa Elbehery <[email protected]>
1 parent 5dca857 commit 0b369bb

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

scripts/release.sh

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

0 commit comments

Comments
 (0)