|
| 1 | +#!/bin/bash |
| 2 | +# bump_aiohuesyncbox_version.sh |
| 3 | +# Usage: ./bump_aiohuesyncbox_version.sh <new_version> |
| 4 | +# Example: ./bump_aiohuesyncbox_version.sh 5.22.0 |
| 5 | + |
| 6 | + |
| 7 | +set -e |
| 8 | + |
| 9 | +# Determine the directory where the script is located |
| 10 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 11 | + |
| 12 | +# Get the previous version from pyproject.toml |
| 13 | +PREV_VERSION=$(grep -oP 'aiohuesyncbox==\K[0-9.]+' "$SCRIPT_DIR/pyproject.toml" | head -n1) |
| 14 | + |
| 15 | +echo "Current version is: $PREV_VERSION" |
| 16 | +if [ $# -ne 1 ]; then |
| 17 | + read -p "Enter new version: " NEW_VERSION |
| 18 | +else |
| 19 | + NEW_VERSION="$1" |
| 20 | +fi |
| 21 | +echo "New version is: $NEW_VERSION" |
| 22 | + |
| 23 | +# Function to compare versions (returns 0 if $1 > $2) |
| 24 | +version_gt() { |
| 25 | + [ "$1" = "$2" ] && return 1 |
| 26 | + local IFS=. |
| 27 | + local i ver1=($1) ver2=($2) |
| 28 | + # Fill empty fields in ver1 with zeros |
| 29 | + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do |
| 30 | + ver1[i]=0 |
| 31 | + done |
| 32 | + # Fill empty fields in ver2 with zeros |
| 33 | + for ((i=${#ver2[@]}; i<${#ver1[@]}; i++)); do |
| 34 | + ver2[i]=0 |
| 35 | + done |
| 36 | + for ((i=0; i<${#ver1[@]}; i++)); do |
| 37 | + if ((10#${ver1[i]} > 10#${ver2[i]})); then |
| 38 | + return 0 |
| 39 | + elif ((10#${ver1[i]} < 10#${ver2[i]})); then |
| 40 | + return 1 |
| 41 | + fi |
| 42 | + done |
| 43 | + return 1 |
| 44 | +} |
| 45 | + |
| 46 | +# Check if new version is higher than previous |
| 47 | +if ! version_gt "$NEW_VERSION" "$PREV_VERSION"; then |
| 48 | + echo "Error: New version ($NEW_VERSION) is not higher than previous version ($PREV_VERSION)." |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | + |
| 53 | +# Update dependency on aiohuesyncbox in huesyncbox/pyproject.toml |
| 54 | +sed -i "s/aiohuesyncbox==[0-9.]*/aiohuesyncbox==$NEW_VERSION/" "$SCRIPT_DIR/pyproject.toml" |
| 55 | + |
| 56 | +# Update version in huesyncbox/manifest.json |
| 57 | +sed -i "s/aiohuesyncbox==[0-9.]*/aiohuesyncbox==$NEW_VERSION/" "$SCRIPT_DIR/custom_components/huesyncbox/manifest.json" |
| 58 | + |
| 59 | +echo "Version bumped to $NEW_VERSION in pyproject.toml and manifest.json files." |
| 60 | + |
| 61 | +# Ask for confirmation to create a branch and commit |
| 62 | +read -p "Do you want to create a branch, commit the change and push? (y/n): " CONFIRM |
| 63 | +if [[ "$CONFIRM" == "y" ]]; then |
| 64 | + BRANCH_NAME="bump_aiohuesyncbox_$NEW_VERSION" |
| 65 | + git checkout -b "$BRANCH_NAME" |
| 66 | + git add pyproject.toml custom_components/huesyncbox/manifest.json |
| 67 | + git commit -m "Bump version to $NEW_VERSION" |
| 68 | + git push origin "$BRANCH_NAME" |
| 69 | +fi |
0 commit comments