Skip to content

Add scripts for bumping the connector version and tagging the code #294

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 3, 2025
Merged
Show file tree
Hide file tree
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
71 changes: 71 additions & 0 deletions scripts/bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
set -e

# Copyright © 2025 Meroxa, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

source "${SCRIPT_DIR}/common.sh"

TAG=$1

if ! check_semver "$TAG"; then
echo "$TAG is NOT a valid semver string"
exit 1
fi

# Check if yq is installed
if ! command -v yq &> /dev/null; then
echo "Error: yq is not installed. Please install it and try again."
exit 1
fi

V_TAG="v$TAG"

BRANCH=$(git rev-parse --abbrev-ref HEAD)
CURRENT_TAG=$(get_spec_version connector.yaml)
MSG="You are about to bump the version from ${CURRENT_TAG} to ${V_TAG} on branch '${BRANCH}'.\n"
while true; do
printf "${MSG}"
read -p "Are you sure you want to continue? [y/n]" yn
echo
case $yn in
[Yy]* )
BRANCH_NAME="update-version-$V_TAG"
git checkout -b "$BRANCH_NAME"
yq e ".specification.version = \"${V_TAG}\"" -i connector.yaml
git commit -am "Update version to $V_TAG"
git push origin "$BRANCH_NAME"

# Check if gh is installed
if command -v gh &> /dev/null; then
echo "Creating pull request..."
gh pr create \
--base main \
--title "Update version to $V_TAG" \
--body "Automated version update to $V_TAG" \
--head "$BRANCH_NAME"
else
echo "GitHub CLI (gh) is not installed. To create a PR, please install gh or create it manually."
echo "Branch '$BRANCH_NAME' has been pushed to origin."
fi

echo "Once the change has been merged, you can use scripts/tag.sh to push a new tag."
break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
36 changes: 36 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Copyright © 2025 Meroxa, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

check_semver() {
local version=$1
local SV_REGEX="^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$"

if ! [[ $version =~ $SV_REGEX ]]; then
echo "$version is NOT a valid semver string"
return 1
fi
return 0
}

get_spec_version() {
local yaml_file=$1

if command -v yq &> /dev/null; then
yq '.specification.version' "$yaml_file"
else
sed -n '/specification:/,/version:/ s/.*version: //p' "$yaml_file" | tail -1
fi
}
49 changes: 49 additions & 0 deletions scripts/tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Copyright © 2025 Meroxa, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

source "${SCRIPT_DIR}/common.sh"

HAS_UNCOMMITTED=$(git status --porcelain=v1 2>/dev/null | wc -l | awk '{print $1}')
if (( $HAS_UNCOMMITTED != 0 )); then
echo "You have uncommitted changes, cannot tag."
exit 1
fi

LAST_COMMIT=$(git log -1 --oneline)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
CURRENT_TAG=$(git describe --tags --abbrev=0)
V_TAG=$(get_spec_version connector.yaml)
MSG="You are about to bump the version from ${CURRENT_TAG} to ${V_TAG}.
Current commit is '${LAST_COMMIT}' on branch '${BRANCH}'.
The release process is automatic and quick, so if you make a mistake,
everyone will see it very soon."

while true; do
printf "${MSG}"
read -p "Are you sure you want to continue? [y/n]" yn
echo
case $yn in
[Yy]* )
git tag -a $V_TAG -m "Release: $V_TAG"
git push origin $V_TAG
break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done