|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +usage() { |
| 4 | + cat <<EOF |
| 5 | +Usage: $(basename "$0") <bump_type> |
| 6 | +
|
| 7 | +Bumps the Helm chart version in Chart.yaml by the specified type. |
| 8 | +
|
| 9 | +Required argument: |
| 10 | + bump_type The type of version bump. Must be one of: |
| 11 | + - major |
| 12 | + - minor |
| 13 | + - patch |
| 14 | +
|
| 15 | +Examples: |
| 16 | + $(basename "$0") patch # 1.2.3 -> 1.2.4 |
| 17 | + $(basename "$0") minor # 1.2.3 -> 1.3.0 |
| 18 | + $(basename "$0") major # 1.2.3 -> 2.0.0 |
| 19 | +
|
| 20 | +EOF |
| 21 | + exit 1 |
| 22 | +} |
| 23 | + |
| 24 | +BUMP_TYPE="$1" |
| 25 | + |
| 26 | +if [[ -z "${BUMP_TYPE}" ]]; then |
| 27 | + echo -e "Error: no \$bump_type passed as \$1.\n" |
| 28 | + usage |
| 29 | +elif [[ "${BUMP_TYPE}" != "major" ]] && [[ "${BUMP_TYPE}" != "minor" ]] && [[ "${BUMP_TYPE}" != "patch" ]]; then |
| 30 | + echo -e "Error: \$bump_type \"${BUMP_TYPE}\" not recognized.\n" |
| 31 | + usage |
| 32 | +fi |
| 33 | + |
| 34 | +# requires git, yq |
| 35 | + |
| 36 | +REPO_ROOT=$(git rev-parse --show-toplevel) |
| 37 | + |
| 38 | +# Path to your Chart.yaml |
| 39 | +CHART_FILE="${REPO_ROOT}/charts/llm-d-modelservice/Chart.yaml" |
| 40 | + |
| 41 | +FEATURE_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 42 | + |
| 43 | +STASH_RESULT=$(git stash) |
| 44 | + |
| 45 | +git fetch origin |
| 46 | +git checkout main |
| 47 | +git merge --ff-only origin/main |
| 48 | + |
| 49 | +git switch ${FEATURE_BRANCH} |
| 50 | +if [[ "${STASH_RESULT}" != "No local changes to save" ]]; then |
| 51 | + git stash pop |
| 52 | +fi; |
| 53 | + |
| 54 | +git checkout main -- ${CHART_FILE} |
| 55 | + |
| 56 | +current_version=$(yq e '.version' "$CHART_FILE") |
| 57 | + |
| 58 | +IFS='.' read -r major minor patch <<< "$current_version" |
| 59 | + |
| 60 | +if [[ "${BUMP_TYPE}" == "patch" ]]; then |
| 61 | + patch=$((patch + 1)) |
| 62 | +elif [[ "${BUMP_TYPE}" == "minor" ]]; then |
| 63 | + minor=$((minor + 1)) |
| 64 | + patch=0 |
| 65 | +elif [[ "${BUMP_TYPE}" == "major" ]]; then |
| 66 | + major=$((major + 1)) |
| 67 | + minor=0 |
| 68 | + patch=0 |
| 69 | +fi |
| 70 | + |
| 71 | +new_version="$major.$minor.$patch" |
| 72 | + |
| 73 | +yq e -i ".version = \"$new_version\"" "$CHART_FILE" |
| 74 | + |
| 75 | +echo "Version updated: $current_version → $new_version" |
0 commit comments