Skip to content

Commit d35e27d

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

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

scripts/release.sh

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

0 commit comments

Comments
 (0)