Skip to content

release: add release script #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

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

# === Function Definitions ===
function get_gpg_key {
local git_email
local key_id

git_email=$(git config --get user.email)
key_id=$(gpg --list-keys --with-colons "${git_email}" | awk -F: '/^pub:/ { print $5 }')
if [[ -z "${key_id}" ]]; then
echo "Failed to load gpg key. Is gpg set up correctly for etcd releases?"
return 2
fi
echo "${key_id}"
}

# === Main Script Logic ===
echo "enter release string according to semantic versioning (e.g. v1.2.3)."
read -r 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)

REPOSITORY=${REPOSITORY:-"[email protected]:etcd-io/bbolt.git"}
REMOTE="${REMOTE:-"origin"}"
Comment on lines +31 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we checkout the target release-major.minor branch? Then we can reuse the same script on main branch to release the patches of the stable releases (release-1.4 and release-1.3) as well.

Otherwise, we will have to backport the PR to stable releases. But even we backport the PR, we still need to checkout the target release-major.minor branch?

cc @Elbehery @ivanvc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with changing the branch so we don't need to backport and maintain the script across branches. I'm working on a PR now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for my delayed response, i am fine with your decision 👍🏽


remote_tag_exists=$(git ls-remote --tags "${REPOSITORY}" | grep -c "${INPUT}" || true)
if [ "${remote_tag_exists}" -gt 0 ]; then
echo "Release version tag exists on remote."
exit 1
fi

# ensuring the minor-version is identical.
source_version=$(grep -E "\s+Version\s*=" ./version/version.go | sed -e "s/.*\"\(.*\)\".*/\1/g")
if [[ "${source_version}" != "${RELEASE_VERSION}" ]]; then
source_minor_version=$(echo "${source_version}" | cut -d. -f 1-2)
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
fi

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

# push 'version.go' to remote.
echo "committing 'version.go'"
git add ./version/version.go
git commit -s -m "Update version to ${VERSION}"
git push "${REMOTE}" "${INPUT}"
echo "'version.go' has been committed to remote repo."

# create tag and push to remote.
echo "Creating new tag for '${INPUT}'"
key_id=$(get_gpg_key) || return 2
git tag --local-user "${key_id}" --sign "${INPUT}" --message "${INPUT}"
git push "${REMOTE}" "${INPUT}"
echo "Tag '${INPUT}' has been created and pushed to remote repo."
echo "SUCCESS"