-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
323 lines (272 loc) · 8.14 KB
/
release.sh
File metadata and controls
323 lines (272 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/bin/bash
# TagManager Release Workflow
# Complete automation for version bumping, building, and publishing
set -e
# Colors and emojis
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m'
ROCKET="🚀"
PACKAGE="📦"
CHECK="✅"
WARNING="⚠️"
ERROR="❌"
INFO="ℹ️"
SPARKLES="✨"
GEAR="⚙️"
TAG="🏷️"
print_header() {
echo -e "${BLUE}================================${NC}"
echo -e "${BLUE} TagManager Release Workflow${NC}"
echo -e "${BLUE}================================${NC}"
echo
}
print_success() {
echo -e "${GREEN}${CHECK} $1${NC}"
}
print_info() {
echo -e "${CYAN}${INFO} $1${NC}"
}
print_warning() {
echo -e "${YELLOW}${WARNING} $1${NC}"
}
print_error() {
echo -e "${RED}${ERROR} $1${NC}"
}
print_step() {
echo -e "${PURPLE}${GEAR} $1${NC}"
}
show_usage() {
echo -e "${CYAN}Usage:${NC}"
echo " ./release.sh <bump_type> [options]"
echo
echo -e "${CYAN}Bump Types:${NC}"
echo " patch Increment patch version (1.0.0 -> 1.0.1)"
echo " minor Increment minor version (1.0.0 -> 1.1.0)"
echo " major Increment major version (1.0.0 -> 2.0.0)"
echo
echo -e "${CYAN}Options:${NC}"
echo " --local-only Only install locally (skip PyPI)"
echo " --dry-run Show what would be done without executing"
echo " --skip-tests Skip running tests"
echo " --help Show this help message"
echo
echo -e "${CYAN}Examples:${NC}"
echo " ./release.sh patch # Patch release to PyPI"
echo " ./release.sh minor --local-only # Minor release, local only"
echo " ./release.sh major --dry-run # Show what major release would do"
}
run_tests() {
print_step "Running tests..."
if [[ -f "tests.py" ]]; then
python -m unittest tests.py -v
if [[ $? -eq 0 ]]; then
print_success "All tests passed"
else
print_error "Tests failed"
exit 1
fi
else
print_info "No tests.py found, skipping tests"
fi
}
check_git_status() {
print_step "Checking git status..."
if ! git status &>/dev/null; then
print_warning "Not in a git repository"
return 0
fi
# Check for uncommitted changes
if ! git diff-index --quiet HEAD --; then
print_warning "You have uncommitted changes:"
git status --porcelain
echo
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Aborted. Please commit your changes first."
exit 1
fi
else
print_success "Working directory is clean"
fi
}
bump_version() {
local bump_type=$1
local dry_run=$2
print_step "Bumping version ($bump_type)..."
if [[ "$dry_run" == "true" ]]; then
echo -e "${YELLOW}[DRY RUN]${NC} Would run: python bump_version.py $bump_type"
return 0
fi
# Get current version before bumping
CURRENT_VERSION=$(python bump_version.py --current | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
# Bump the version
python bump_version.py "$bump_type"
if [[ $? -eq 0 ]]; then
NEW_VERSION=$(python bump_version.py --current | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
print_success "Version bumped to $NEW_VERSION"
echo "$NEW_VERSION" > .release_version
else
print_error "Version bump failed"
exit 1
fi
}
install_package() {
local install_type=$1
local dry_run=$2
if [[ "$dry_run" == "true" ]]; then
echo -e "${YELLOW}[DRY RUN]${NC} Would run: ./install.sh $install_type"
return 0
fi
./install.sh "$install_type"
}
create_github_release() {
local version=$1
local dry_run=$2
print_step "Creating GitHub release..."
if [[ "$dry_run" == "true" ]]; then
echo -e "${YELLOW}[DRY RUN]${NC} Would create GitHub release for v$version"
return 0
fi
if command -v gh &> /dev/null; then
# Create release notes
cat > release_notes.md << EOF
# TagManager v$version
## What's New
- Version $version release
- See CHANGELOG.md for detailed changes
## Installation
\`\`\`bash
pip install tagmanager-cli
\`\`\`
## Quick Start
\`\`\`bash
tm add file.txt --tags work important
tm search --tags work
tm ls --tree
\`\`\`
EOF
gh release create "v$version" \
--title "TagManager v$version" \
--notes-file release_notes.md \
dist/*
rm release_notes.md
print_success "GitHub release created"
else
print_info "GitHub CLI not found, skipping GitHub release"
print_info "You can create a release manually at: https://github.com/davidtbilisi/TagManager/releases"
fi
}
main() {
print_header
# Parse arguments
BUMP_TYPE=""
LOCAL_ONLY=false
DRY_RUN=false
SKIP_TESTS=false
while [[ $# -gt 0 ]]; do
case $1 in
patch|minor|major)
BUMP_TYPE=$1
shift
;;
--local-only)
LOCAL_ONLY=true
shift
;;
--dry-run)
DRY_RUN=true
shift
;;
--skip-tests)
SKIP_TESTS=true
shift
;;
--help|-h)
show_usage
exit 0
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Validate bump type
if [[ -z "$BUMP_TYPE" ]]; then
print_error "Bump type required (patch, minor, or major)"
show_usage
exit 1
fi
# Show what we're going to do
echo -e "${CYAN}Release Plan:${NC}"
echo " Bump Type: $BUMP_TYPE"
echo " Target: $([ "$LOCAL_ONLY" = true ] && echo "Local only" || echo "PyPI + Local")"
echo " Mode: $([ "$DRY_RUN" = true ] && echo "Dry run" || echo "Execute")"
echo " Tests: $([ "$SKIP_TESTS" = true ] && echo "Skip" || echo "Run")"
echo
if [[ "$DRY_RUN" = false ]]; then
read -p "Continue with release? (Y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
print_info "Release cancelled"
exit 0
fi
fi
echo -e "${ROCKET} Starting release process..."
echo
# Step 1: Check git status
if [[ "$DRY_RUN" = false ]]; then
check_git_status
fi
# Step 2: Run tests
if [[ "$SKIP_TESTS" = false && "$DRY_RUN" = false ]]; then
run_tests
fi
# Step 3: Bump version
bump_version "$BUMP_TYPE" "$DRY_RUN"
# Get version for later steps
if [[ -f ".release_version" ]]; then
NEW_VERSION=$(cat .release_version)
rm .release_version
else
NEW_VERSION="unknown"
fi
# Step 4: Install package
if [[ "$LOCAL_ONLY" = true ]]; then
install_package "--local" "$DRY_RUN"
else
install_package "--remote" "$DRY_RUN"
fi
# Step 5: Create GitHub release (if publishing to PyPI)
if [[ "$LOCAL_ONLY" = false ]]; then
create_github_release "$NEW_VERSION" "$DRY_RUN"
fi
# Success message
echo
echo -e "${GREEN}${SPARKLES} Release Complete! ${SPARKLES}${NC}"
echo -e "${BLUE}================================${NC}"
if [[ "$DRY_RUN" = false ]]; then
echo -e "${CYAN}Version:${NC} $NEW_VERSION"
echo -e "${CYAN}Status:${NC} $([ "$LOCAL_ONLY" = true ] && echo "Local installation" || echo "Published to PyPI")"
echo
echo -e "${CYAN}Next Steps:${NC}"
if [[ "$LOCAL_ONLY" = false ]]; then
echo " • Check PyPI: https://pypi.org/project/tagmanager-cli/"
echo " • Verify installation: pip install --upgrade tagmanager-cli"
fi
echo " • Test the release: tm --help"
echo " • Update documentation if needed"
else
echo "This was a dry run. No changes were made."
fi
echo -e "${BLUE}================================${NC}"
}
# Run main function
main "$@"