|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Copyright © 2025 Meroxa, Inc. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +# Get the directory where the script is located |
| 19 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 20 | + |
| 21 | +source "${SCRIPT_DIR}/common.sh" |
| 22 | + |
| 23 | +TAG=$1 |
| 24 | + |
| 25 | +if ! check_semver "$TAG"; then |
| 26 | + echo "$TAG is NOT a valid semver string" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +# Check if yq is installed |
| 31 | +if ! command -v yq &> /dev/null; then |
| 32 | + echo "Error: yq is not installed. Please install it and try again." |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +V_TAG="v$TAG" |
| 37 | + |
| 38 | +BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 39 | +CURRENT_TAG=$(get_spec_version connector.yaml) |
| 40 | +MSG="You are about to bump the version from ${CURRENT_TAG} to ${V_TAG} on branch '${BRANCH}'.\n" |
| 41 | +while true; do |
| 42 | + printf "${MSG}" |
| 43 | + read -p "Are you sure you want to continue? [y/n]" yn |
| 44 | + echo |
| 45 | + case $yn in |
| 46 | + [Yy]* ) |
| 47 | + BRANCH_NAME="update-version-$V_TAG" |
| 48 | + git checkout -b "$BRANCH_NAME" |
| 49 | + yq e ".specification.version = \"${V_TAG}\"" -i connector.yaml |
| 50 | + git commit -am "Update version to $V_TAG" |
| 51 | + git push origin "$BRANCH_NAME" |
| 52 | + |
| 53 | + # Check if gh is installed |
| 54 | + if command -v gh &> /dev/null; then |
| 55 | + echo "Creating pull request..." |
| 56 | + gh pr create \ |
| 57 | + --base main \ |
| 58 | + --title "Update version to $V_TAG" \ |
| 59 | + --body "Automated version update to $V_TAG" \ |
| 60 | + --head "$BRANCH_NAME" |
| 61 | + else |
| 62 | + echo "GitHub CLI (gh) is not installed. To create a PR, please install gh or create it manually." |
| 63 | + echo "Branch '$BRANCH_NAME' has been pushed to origin." |
| 64 | + fi |
| 65 | + |
| 66 | + echo "Once the change has been merged, you can use scripts/tag.sh to push a new tag." |
| 67 | + break;; |
| 68 | + [Nn]* ) exit;; |
| 69 | + * ) echo "Please answer yes or no.";; |
| 70 | + esac |
| 71 | +done |
0 commit comments