Skip to content

Commit

Permalink
release: add release script
Browse files Browse the repository at this point in the history
Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
  • Loading branch information
Elbehery committed Feb 10, 2025
1 parent 5dca857 commit 0b369bb
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

echo "enter release string according to semantic versioning (e.g. v1.2.3)."
read INPUT
if [[ ! "${INPUT}" =~ ^v[0-9]+.[0-9]+.[0-9]+ ]]; then
echo "Expected 'version' param of the form 'v<major-version>.<minor-version>.<patch-version>' but got '${INPUT}'"
exit 1
fi

VERSION=${INPUT#v}
RELEASE_VERSION="${VERSION}"
MINOR_VERSION=$(echo "${VERSION}" | cut -d. -f 1-2)

echo $RELEASE_VERSION
echo $MINOR_VERSION

source_version=$(grep -E "\s+Version\s*=" ../version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")

echo $source_version
if [[ "${source_version}" != "${RELEASE_VERSION}" ]]; then
source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
echo $source_minor_version
if [[ "${source_minor_version}" != "${MINOR_VERSION}" ]]; then
echo "Wrong bbolt minor version in version.go. Expected ${MINOR_VERSION} but got ${source_minor_version}. Aborting."
exit 1
fi

echo "Updating version from ${source_version} to ${RELEASE_VERSION} in version.go"
sed -i "" "s/${source_version}/${RELEASE_VERSION}/g" ../version/version.go
fi

REPOSITORY=${REPOSITORY:-"git@github.com:etcd-io/bbolt.git"}
BRANCH=${BRANCH:-"release-${MINOR_VERSION}"}

echo "committing 'version.go' to remote repo"
date_string=$(date +%Y%m%d)
local_branch_name="version_${date_string}"
local_branch_err=$(git checkout -b $local_branch_name | grep -E "error|fatal" || true )
echo $local_branch_err
git add ../version/version.go

echo "committing version.go"
git commit -s -m "Update version to ${VERSION}"

git push -u origin
echo "version.go has been committed to remote repo"


remote_tag_exists=$(git ls-remote --tags $REPOSITORY | grep -c "${INPUT}" || true)
echo $remote_tag_exists
if [ "${remote_tag_exists}" -gt 0 ]; then
echo "Release version tag exists on remote. Checking out refs/tags/${INPUT}"
git checkout -q "tags/${INPUT}"
elif [ "${remote_tag_exists}" -eq 0 ]; then
echo "Create new tag"
git tag $INPUT
git push origin $INPUT
fi
echo "SUCCESS"

0 comments on commit 0b369bb

Please sign in to comment.