1+ #! /bin/bash
2+ # Release script for claude-code-trees
3+ # Usage: ./scripts/release.sh [patch|minor|major]
4+
5+ set -e
6+
7+ # Colors for output
8+ RED=' \033[0;31m'
9+ GREEN=' \033[0;32m'
10+ YELLOW=' \033[1;33m'
11+ NC=' \033[0m' # No Color
12+
13+ # Default to patch version
14+ VERSION_TYPE=${1:- patch}
15+
16+ echo -e " ${GREEN} 🚀 Preparing release for claude-code-trees${NC} "
17+
18+ # Get current version from pyproject.toml
19+ CURRENT_VERSION=$( grep ' ^version = ' pyproject.toml | cut -d' "' -f2)
20+ echo -e " ${YELLOW} Current version: $CURRENT_VERSION ${NC} "
21+
22+ # Calculate new version
23+ IFS=' .' read -ra VERSION_PARTS <<< " $CURRENT_VERSION"
24+ MAJOR=${VERSION_PARTS[0]}
25+ MINOR=${VERSION_PARTS[1]}
26+ PATCH=${VERSION_PARTS[2]}
27+
28+ case $VERSION_TYPE in
29+ major)
30+ MAJOR=$(( MAJOR + 1 ))
31+ MINOR=0
32+ PATCH=0
33+ ;;
34+ minor)
35+ MINOR=$(( MINOR + 1 ))
36+ PATCH=0
37+ ;;
38+ patch)
39+ PATCH=$(( PATCH + 1 ))
40+ ;;
41+ * )
42+ echo -e " ${RED} Invalid version type. Use: patch, minor, or major${NC} "
43+ exit 1
44+ ;;
45+ esac
46+
47+ NEW_VERSION=" $MAJOR .$MINOR .$PATCH "
48+ echo -e " ${GREEN} New version: $NEW_VERSION ${NC} "
49+
50+ # Update version in pyproject.toml
51+ if [[ " $OSTYPE " == " darwin" * ]]; then
52+ # macOS
53+ sed -i ' ' " s/^version = \" .*\" /version = \" $NEW_VERSION \" /" pyproject.toml
54+ else
55+ # Linux
56+ sed -i " s/^version = \" .*\" /version = \" $NEW_VERSION \" /" pyproject.toml
57+ fi
58+
59+ # Update version in __init__.py if it exists
60+ if [ -f " src/claude_code_trees/__init__.py" ]; then
61+ if grep -q " __version__" src/claude_code_trees/__init__.py; then
62+ if [[ " $OSTYPE " == " darwin" * ]]; then
63+ sed -i ' ' " s/__version__ = \" .*\" /__version__ = \" $NEW_VERSION \" /" src/claude_code_trees/__init__.py
64+ else
65+ sed -i " s/__version__ = \" .*\" /__version__ = \" $NEW_VERSION \" /" src/claude_code_trees/__init__.py
66+ fi
67+ else
68+ echo " __version__ = \" $NEW_VERSION \" " >> src/claude_code_trees/__init__.py
69+ fi
70+ fi
71+
72+ # Prompt for changelog entry
73+ echo -e " ${YELLOW} Enter changelog entry for v$NEW_VERSION (press Ctrl+D when done):${NC} "
74+ CHANGELOG_ENTRY=$( cat)
75+
76+ # Update CHANGELOG.md
77+ if [ -f " CHANGELOG.md" ]; then
78+ # Create temporary file with new entry
79+ cat > /tmp/changelog_new.md << EOF
80+ # Changelog
81+
82+ All notable changes to Claude Code Trees will be documented in this file.
83+
84+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
85+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
86+
87+ ## [$NEW_VERSION ] - $( date +%Y-%m-%d)
88+
89+ $CHANGELOG_ENTRY
90+
91+ EOF
92+
93+ # Append rest of changelog (skipping header)
94+ tail -n +7 CHANGELOG.md >> /tmp/changelog_new.md
95+
96+ # Replace changelog
97+ mv /tmp/changelog_new.md CHANGELOG.md
98+ fi
99+
100+ # Build the package to verify
101+ echo -e " ${YELLOW} Building package...${NC} "
102+ pdm build
103+
104+ # Run tests
105+ echo -e " ${YELLOW} Running tests...${NC} "
106+ pdm run test || {
107+ echo -e " ${RED} Tests failed! Aborting release.${NC} "
108+ exit 1
109+ }
110+
111+ # Git operations
112+ echo -e " ${YELLOW} Committing changes...${NC} "
113+ git add pyproject.toml CHANGELOG.md src/claude_code_trees/__init__.py
114+ git commit -m " Release v$NEW_VERSION "
115+
116+ # Create tag
117+ echo -e " ${YELLOW} Creating tag v$NEW_VERSION ...${NC} "
118+ git tag -a " v$NEW_VERSION " -m " Release v$NEW_VERSION "
119+
120+ echo -e " ${GREEN} ✅ Release prepared successfully!${NC} "
121+ echo " "
122+ echo " Next steps:"
123+ echo " 1. Review the changes: git show"
124+ echo " 2. Push to GitHub: git push && git push --tags"
125+ echo " 3. Create release on GitHub: https://github.com/rizome-dev/claude-code-trees/releases/new"
126+ echo " - Tag: v$NEW_VERSION "
127+ echo " - Title: v$NEW_VERSION "
128+ echo " - Copy description from CHANGELOG.md"
129+ echo " 4. The GitHub Action will automatically publish to PyPI"
130+ echo " "
131+ echo -e " ${YELLOW} Or run: git push && git push --tags && gh release create v$NEW_VERSION --title \" v$NEW_VERSION \" --notes-file CHANGELOG.md${NC} "
0 commit comments