11#! /bin/bash
2- set -e
2+ set -eo pipefail
3+
4+ # Colors for output
5+ RED=' \033[0;31m'
6+ GREEN=' \033[0;32m'
7+ YELLOW=' \033[1;33m'
8+ NC=' \033[0m' # No Color
9+
10+ # Function to print colored output
11+ print_color () {
12+ printf " ${! 1} %s${NC} \n" " $2 "
13+ }
14+
15+ # Function to check if command exists
16+ command_exists () {
17+ command -v " $1 " > /dev/null 2>&1
18+ }
19+
20+ # Check required tools
21+ for cmd in git poetry sed; do
22+ if ! command_exists " $cmd " ; then
23+ print_color " RED" " Error: $cmd is not installed. Please install it and try again."
24+ exit 1
25+ fi
26+ done
327
428# Ensure we're on the main branch
529if [ " $( git rev-parse --abbrev-ref HEAD) " != " main" ]; then
6- echo " You must be on the main branch to release."
30+ print_color " RED" " Error: You must be on the main branch to release."
31+ exit 1
32+ fi
33+
34+ # Check for uncommitted changes
35+ if ! git diff-index --quiet HEAD --; then
36+ print_color " RED" " Error: You have uncommitted changes. Please commit or stash them before releasing."
737 exit 1
838fi
939
@@ -13,11 +43,32 @@ current_version=$(poetry version -s)
1343# Ask for the new version
1444read -p " Current version is $current_version . What should the new version be? " new_version
1545
46+ # Validate new version format (simple check)
47+ if ! [[ $new_version =~ ^[0-9]+\. [0-9]+\. [0-9]+$ ]]; then
48+ print_color " RED" " Error: Invalid version format. Please use semantic versioning (e.g., 1.2.3)."
49+ exit 1
50+ fi
51+
1652# Update the version in pyproject.toml
1753poetry version $new_version
1854
1955# Update documentation version
20- sed -i " s/version: $current_version /version: $new_version /" docs/index.md
56+ if [ -f docs/index.md ]; then
57+ sed -i " s/version: $current_version /version: $new_version /" docs/index.md
58+ else
59+ print_color " YELLOW" " Warning: docs/index.md not found. Skipping documentation version update."
60+ fi
61+
62+ # Show changes and ask for confirmation
63+ print_color " YELLOW" " The following files will be modified:"
64+ git status --porcelain
65+
66+ read -p " Do you want to proceed with these changes? (y/n) " -n 1 -r
67+ echo
68+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
69+ print_color " RED" " Release cancelled."
70+ exit 1
71+ fi
2172
2273# Commit the changes
2374git add pyproject.toml docs/index.md
@@ -27,4 +78,4 @@ git commit -m ":bookmark: Release: $new_version"
2778git tag -a v$new_version -m " Release: $new_version "
2879git push origin main --tags
2980
30- echo " Release $new_version has been created and pushed. CI will handle the rest, including documentation deployment ."
81+ print_color " GREEN " " Release $new_version has been created and pushed."
0 commit comments