|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Define ANSI color codes |
| 4 | +ORANGE='\033[0;33m' |
| 5 | +NC='\033[0m' # No Color |
| 6 | + |
| 7 | +# Function to read the current version from pubspec.yaml |
| 8 | +get_current_version() { |
| 9 | + grep '^version:' pubspec.yaml | awk '{print $2}' |
| 10 | +} |
| 11 | + |
| 12 | +# Function to parse the version and suggest the next version |
| 13 | +suggest_next_version() { |
| 14 | + local current_version=$1 |
| 15 | + local base_version=$(echo $current_version | awk -F '+' '{print $1}') |
| 16 | + local build_metadata=$(echo $current_version | awk -F '+' '{print $2}') |
| 17 | + |
| 18 | + if [[ -n $build_metadata ]]; then |
| 19 | + local next_build=$((build_metadata + 1)) |
| 20 | + echo "${base_version}+${next_build}" |
| 21 | + else |
| 22 | + IFS='.' read -r -a version_parts <<< "$base_version" |
| 23 | + local next_patch=$((version_parts[2] + 1)) |
| 24 | + echo "${version_parts[0]}.${version_parts[1]}.$next_patch" |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +# Function to update the version in pubspec.yaml |
| 29 | +update_version() { |
| 30 | + local new_version=$1 |
| 31 | + sed -i '' "s/^version:.*/version: $new_version/" pubspec.yaml |
| 32 | +} |
| 33 | + |
| 34 | +# Get the current version |
| 35 | +current_version=$(get_current_version) |
| 36 | +echo "Current version: ${ORANGE}$current_version${NC}" |
| 37 | + |
| 38 | +# Suggest the next version |
| 39 | +suggested_version=$(suggest_next_version "$current_version") |
| 40 | +echo "Suggested next version: ${ORANGE}$suggested_version${NC}" |
| 41 | + |
| 42 | +# Prompt the user for the new version |
| 43 | +read -p "Enter the new version (or press Enter to use suggested version): " user_version |
| 44 | +new_version=${user_version:-$suggested_version} |
| 45 | + |
| 46 | +# Ask for confirmation |
| 47 | +echo "You entered version ${ORANGE}$new_version${NC}" |
| 48 | +read -p "Do you want to update the version in pubspec.yaml? (y/n): " confirmation |
| 49 | + |
| 50 | +if [[ $confirmation == "y" || $confirmation == "Y" ]]; then |
| 51 | + # Update the version in pubspec.yaml |
| 52 | + update_version "$new_version" |
| 53 | + echo "Version updated to: ${ORANGE}$new_version${NC}" |
| 54 | +else |
| 55 | + echo "Version update canceled." |
| 56 | +fi |
0 commit comments