Skip to content

Commit 1997268

Browse files
committed
added release.sh
1 parent 6878135 commit 1997268

2 files changed

Lines changed: 362 additions & 0 deletions

File tree

Scripts/release-advanced.sh

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#!/bin/bash
2+
3+
# TLPhotoPicker Advanced Release Script
4+
# Supports custom version bumping (major, minor, patch) or specific version
5+
6+
set -e # Exit on error
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
BLUE='\033[0;34m'
13+
NC='\033[0m' # No Color
14+
15+
# Files to update
16+
PODSPEC_FILE="TLPhotoPicker.podspec"
17+
CHANGELOG_FILE="CHANGELOG.md"
18+
19+
# Functions
20+
print_usage() {
21+
echo "Usage: $0 [patch|minor|major|VERSION]"
22+
echo ""
23+
echo "Arguments:"
24+
echo " patch Increment patch version (x.y.Z) - default"
25+
echo " minor Increment minor version (x.Y.0)"
26+
echo " major Increment major version (X.0.0)"
27+
echo " VERSION Specify exact version (e.g., 3.0.0)"
28+
echo ""
29+
echo "Examples:"
30+
echo " $0 # Increment patch: 2.1.12 -> 2.1.13"
31+
echo " $0 patch # Increment patch: 2.1.12 -> 2.1.13"
32+
echo " $0 minor # Increment minor: 2.1.12 -> 2.2.0"
33+
echo " $0 major # Increment major: 2.1.12 -> 3.0.0"
34+
echo " $0 2.5.0 # Set to specific version: 2.5.0"
35+
}
36+
37+
print_header() {
38+
echo -e "${GREEN}========================================${NC}"
39+
echo -e "${GREEN}TLPhotoPicker Release Script${NC}"
40+
echo -e "${GREEN}========================================${NC}"
41+
echo ""
42+
}
43+
44+
validate_version() {
45+
if [[ ! $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
46+
echo -e "${RED}Error: Invalid version format. Expected: x.y.z${NC}"
47+
return 1
48+
fi
49+
return 0
50+
}
51+
52+
# Parse arguments
53+
BUMP_TYPE="${1:-patch}"
54+
55+
print_header
56+
57+
# Check if help is requested
58+
if [[ "$BUMP_TYPE" == "-h" ]] || [[ "$BUMP_TYPE" == "--help" ]]; then
59+
print_usage
60+
exit 0
61+
fi
62+
63+
# Check if working directory is clean
64+
if [[ -n $(git status -s) ]]; then
65+
echo -e "${RED}Error: Working directory is not clean. Please commit or stash your changes.${NC}"
66+
exit 1
67+
fi
68+
69+
# Check if on master branch
70+
CURRENT_BRANCH=$(git branch --show-current)
71+
if [[ "$CURRENT_BRANCH" != "master" ]]; then
72+
echo -e "${YELLOW}Warning: You are not on the master branch (current: $CURRENT_BRANCH)${NC}"
73+
read -p "Do you want to continue? (y/n) " -n 1 -r
74+
echo ""
75+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
76+
echo -e "${RED}Release cancelled.${NC}"
77+
exit 1
78+
fi
79+
fi
80+
81+
# Get current version from podspec
82+
CURRENT_VERSION=$(grep -E "s.version\s*=\s*'[0-9]+\.[0-9]+\.[0-9]+'" $PODSPEC_FILE | sed -E "s/.*'([0-9]+\.[0-9]+\.[0-9]+)'.*/\1/")
83+
echo -e "Current version: ${YELLOW}$CURRENT_VERSION${NC}"
84+
85+
# Parse version numbers
86+
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
87+
MAJOR="${VERSION_PARTS[0]}"
88+
MINOR="${VERSION_PARTS[1]}"
89+
PATCH="${VERSION_PARTS[2]}"
90+
91+
# Calculate new version based on bump type
92+
case "$BUMP_TYPE" in
93+
patch)
94+
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
95+
;;
96+
minor)
97+
NEW_VERSION="$MAJOR.$((MINOR + 1)).0"
98+
;;
99+
major)
100+
NEW_VERSION="$((MAJOR + 1)).0.0"
101+
;;
102+
*)
103+
# Assume it's a specific version
104+
NEW_VERSION="$BUMP_TYPE"
105+
if ! validate_version "$NEW_VERSION"; then
106+
echo ""
107+
print_usage
108+
exit 1
109+
fi
110+
;;
111+
esac
112+
113+
echo -e "New version will be: ${GREEN}$NEW_VERSION${NC}"
114+
echo ""
115+
116+
# Ask for confirmation
117+
read -p "Do you want to proceed with version $NEW_VERSION? (y/n) " -n 1 -r
118+
echo ""
119+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
120+
echo -e "${RED}Release cancelled.${NC}"
121+
exit 1
122+
fi
123+
124+
# Optional: Ask for changelog entry
125+
echo ""
126+
echo -e "${BLUE}Enter a brief description of changes (or press Enter to skip):${NC}"
127+
read -r CHANGELOG_ENTRY
128+
129+
# Update podspec version
130+
echo ""
131+
echo -e "${YELLOW}[1/7] Updating $PODSPEC_FILE...${NC}"
132+
sed -i '' "s/s.version\s*=\s*'$CURRENT_VERSION'/s.version = '$NEW_VERSION'/" $PODSPEC_FILE
133+
134+
# Verify the change
135+
UPDATED_VERSION=$(grep -E "s.version\s*=\s*'[0-9]+\.[0-9]+\.[0-9]+'" $PODSPEC_FILE | sed -E "s/.*'([0-9]+\.[0-9]+\.[0-9]+)'.*/\1/")
136+
if [[ "$UPDATED_VERSION" != "$NEW_VERSION" ]]; then
137+
echo -e "${RED}Error: Failed to update version in $PODSPEC_FILE${NC}"
138+
exit 1
139+
fi
140+
echo -e "${GREEN}✓ Podspec updated${NC}"
141+
142+
# Update CHANGELOG if it exists
143+
if [[ -f "$CHANGELOG_FILE" ]]; then
144+
echo -e "${YELLOW}[2/7] Updating $CHANGELOG_FILE...${NC}"
145+
TODAY=$(date +%Y-%m-%d)
146+
147+
if [[ -n "$CHANGELOG_ENTRY" ]]; then
148+
# Add new version with custom entry
149+
sed -i '' "/^# /a\\
150+
\\
151+
## [$NEW_VERSION] - $TODAY\\
152+
### Changed\\
153+
- $CHANGELOG_ENTRY\\
154+
" $CHANGELOG_FILE
155+
else
156+
# Add new version with default entry
157+
sed -i '' "/^# /a\\
158+
\\
159+
## [$NEW_VERSION] - $TODAY\\
160+
### Changed\\
161+
- Version bump to $NEW_VERSION\\
162+
" $CHANGELOG_FILE
163+
fi
164+
echo -e "${GREEN}✓ Changelog updated${NC}"
165+
else
166+
echo -e "${YELLOW}[2/7] No CHANGELOG.md found, skipping...${NC}"
167+
fi
168+
169+
# Validate podspec
170+
echo -e "${YELLOW}[3/7] Validating podspec...${NC}"
171+
pod lib lint --allow-warnings
172+
173+
if [[ $? -ne 0 ]]; then
174+
echo -e "${RED}Error: Podspec validation failed!${NC}"
175+
echo -e "${YELLOW}Reverting changes...${NC}"
176+
git checkout $PODSPEC_FILE
177+
[[ -f "$CHANGELOG_FILE" ]] && git checkout $CHANGELOG_FILE
178+
exit 1
179+
fi
180+
echo -e "${GREEN}✓ Podspec validation passed${NC}"
181+
182+
# Commit changes
183+
echo -e "${YELLOW}[4/7] Committing changes...${NC}"
184+
git add $PODSPEC_FILE
185+
[[ -f "$CHANGELOG_FILE" ]] && git add $CHANGELOG_FILE
186+
187+
if [[ -n "$CHANGELOG_ENTRY" ]]; then
188+
git commit -m "chore: bump version to $NEW_VERSION
189+
190+
$CHANGELOG_ENTRY"
191+
else
192+
git commit -m "chore: bump version to $NEW_VERSION"
193+
fi
194+
echo -e "${GREEN}✓ Changes committed${NC}"
195+
196+
# Create git tag
197+
echo -e "${YELLOW}[5/7] Creating git tag $NEW_VERSION...${NC}"
198+
if [[ -n "$CHANGELOG_ENTRY" ]]; then
199+
git tag -a "$NEW_VERSION" -m "Release version $NEW_VERSION
200+
201+
$CHANGELOG_ENTRY"
202+
else
203+
git tag -a "$NEW_VERSION" -m "Release version $NEW_VERSION"
204+
fi
205+
echo -e "${GREEN}✓ Git tag created${NC}"
206+
207+
# Push changes and tags
208+
echo -e "${YELLOW}[6/7] Pushing to remote...${NC}"
209+
git push origin "$CURRENT_BRANCH"
210+
git push origin "$NEW_VERSION"
211+
echo -e "${GREEN}✓ Pushed to remote${NC}"
212+
213+
# Deploy to CocoaPods
214+
echo -e "${YELLOW}[7/7] Publishing to CocoaPods...${NC}"
215+
pod trunk push $PODSPEC_FILE --allow-warnings
216+
217+
if [[ $? -ne 0 ]]; then
218+
echo -e "${RED}Error: Failed to publish to CocoaPods!${NC}"
219+
echo -e "${YELLOW}Note: Git tag and commit have been pushed.${NC}"
220+
echo -e "${YELLOW}You may need to manually publish to CocoaPods using:${NC}"
221+
echo -e "${BLUE}pod trunk push $PODSPEC_FILE --allow-warnings${NC}"
222+
exit 1
223+
fi
224+
echo -e "${GREEN}✓ Published to CocoaPods${NC}"
225+
226+
# Print success summary
227+
echo ""
228+
echo -e "${GREEN}========================================${NC}"
229+
echo -e "${GREEN}✓ Release completed successfully!${NC}"
230+
echo -e "${GREEN}========================================${NC}"
231+
echo ""
232+
echo -e "Version: ${GREEN}$CURRENT_VERSION${NC}${GREEN}$NEW_VERSION${NC}"
233+
echo -e "CocoaPods: ${GREEN}✓ Published${NC}"
234+
echo -e "SPM: ${GREEN}✓ Available via git tag${NC}"
235+
echo -e "Git Tag: ${GREEN}$NEW_VERSION${NC}"
236+
echo ""
237+
echo -e "${BLUE}SPM users can now update their Package.swift:${NC}"
238+
echo -e "${BLUE}.package(url: \"https://github.com/tilltue/TLPhotoPicker.git\", from: \"$NEW_VERSION\")${NC}"
239+
echo ""

Scripts/release.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/bash
2+
3+
# TLPhotoPicker Release Script
4+
# Automates version bumping and deployment for CocoaPods and SPM
5+
6+
set -e # Exit on error
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
# Files to update
15+
PODSPEC_FILE="TLPhotoPicker.podspec"
16+
CHANGELOG_FILE="CHANGELOG.md"
17+
18+
echo -e "${GREEN}========================================${NC}"
19+
echo -e "${GREEN}TLPhotoPicker Release Script${NC}"
20+
echo -e "${GREEN}========================================${NC}"
21+
echo ""
22+
23+
# Check if working directory is clean
24+
if [[ -n $(git status -s) ]]; then
25+
echo -e "${RED}Error: Working directory is not clean. Please commit or stash your changes.${NC}"
26+
exit 1
27+
fi
28+
29+
# Get current version from podspec
30+
CURRENT_VERSION=$(grep -E "s.version\s*=\s*'[0-9]+\.[0-9]+\.[0-9]+'" $PODSPEC_FILE | sed -E "s/.*'([0-9]+\.[0-9]+\.[0-9]+)'.*/\1/")
31+
echo -e "Current version: ${YELLOW}$CURRENT_VERSION${NC}"
32+
33+
# Parse version numbers
34+
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
35+
MAJOR="${VERSION_PARTS[0]}"
36+
MINOR="${VERSION_PARTS[1]}"
37+
PATCH="${VERSION_PARTS[2]}"
38+
39+
# Calculate new version (increment patch by default)
40+
NEW_PATCH=$((PATCH + 1))
41+
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
42+
43+
echo -e "New version will be: ${GREEN}$NEW_VERSION${NC}"
44+
echo ""
45+
46+
# Ask for confirmation
47+
read -p "Do you want to proceed with version $NEW_VERSION? (y/n) " -n 1 -r
48+
echo ""
49+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
50+
echo -e "${RED}Release cancelled.${NC}"
51+
exit 1
52+
fi
53+
54+
# Update podspec version
55+
echo -e "${YELLOW}Updating $PODSPEC_FILE...${NC}"
56+
sed -i '' "s/s.version\s*=\s*'$CURRENT_VERSION'/s.version = '$NEW_VERSION'/" $PODSPEC_FILE
57+
58+
# Verify the change
59+
UPDATED_VERSION=$(grep -E "s.version\s*=\s*'[0-9]+\.[0-9]+\.[0-9]+'" $PODSPEC_FILE | sed -E "s/.*'([0-9]+\.[0-9]+\.[0-9]+)'.*/\1/")
60+
if [[ "$UPDATED_VERSION" != "$NEW_VERSION" ]]; then
61+
echo -e "${RED}Error: Failed to update version in $PODSPEC_FILE${NC}"
62+
exit 1
63+
fi
64+
65+
# Update CHANGELOG if it exists
66+
if [[ -f "$CHANGELOG_FILE" ]]; then
67+
echo -e "${YELLOW}Updating $CHANGELOG_FILE...${NC}"
68+
TODAY=$(date +%Y-%m-%d)
69+
# Add new version header at the top (after the main title)
70+
sed -i '' "/^# /a\\
71+
\\
72+
## [$NEW_VERSION] - $TODAY\\
73+
### Changed\\
74+
- Version bump to $NEW_VERSION\\
75+
" $CHANGELOG_FILE
76+
fi
77+
78+
# Validate podspec
79+
echo -e "${YELLOW}Validating podspec...${NC}"
80+
pod lib lint --allow-warnings
81+
82+
if [[ $? -ne 0 ]]; then
83+
echo -e "${RED}Error: Podspec validation failed!${NC}"
84+
echo -e "${YELLOW}Reverting changes...${NC}"
85+
git checkout $PODSPEC_FILE
86+
[[ -f "$CHANGELOG_FILE" ]] && git checkout $CHANGELOG_FILE
87+
exit 1
88+
fi
89+
90+
# Commit changes
91+
echo -e "${YELLOW}Committing changes...${NC}"
92+
git add $PODSPEC_FILE
93+
[[ -f "$CHANGELOG_FILE" ]] && git add $CHANGELOG_FILE
94+
git commit -m "chore: bump version to $NEW_VERSION"
95+
96+
# Create git tag
97+
echo -e "${YELLOW}Creating git tag $NEW_VERSION...${NC}"
98+
git tag -a "$NEW_VERSION" -m "Release version $NEW_VERSION"
99+
100+
# Push changes and tags
101+
echo -e "${YELLOW}Pushing to remote...${NC}"
102+
git push origin master
103+
git push origin "$NEW_VERSION"
104+
105+
# Deploy to CocoaPods
106+
echo -e "${YELLOW}Publishing to CocoaPods...${NC}"
107+
pod trunk push $PODSPEC_FILE --allow-warnings
108+
109+
if [[ $? -ne 0 ]]; then
110+
echo -e "${RED}Error: Failed to publish to CocoaPods!${NC}"
111+
echo -e "${YELLOW}Note: Git tag and commit have been pushed. You may need to manually publish to CocoaPods.${NC}"
112+
exit 1
113+
fi
114+
115+
echo ""
116+
echo -e "${GREEN}========================================${NC}"
117+
echo -e "${GREEN}Release completed successfully!${NC}"
118+
echo -e "${GREEN}========================================${NC}"
119+
echo -e "Version: ${GREEN}$NEW_VERSION${NC}"
120+
echo -e "CocoaPods: ${GREEN}Published${NC}"
121+
echo -e "SPM: ${GREEN}Available via git tag${NC}"
122+
echo ""
123+
echo -e "${YELLOW}Note: SPM users can now use version $NEW_VERSION by updating their Package.swift dependency.${NC}"

0 commit comments

Comments
 (0)