-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathincrement_build_number.sh
More file actions
executable file
·146 lines (125 loc) · 4.84 KB
/
increment_build_number.sh
File metadata and controls
executable file
·146 lines (125 loc) · 4.84 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
#!/bin/bash
# Script to increment build number by 1 in all Android and iOS files
# This script updates versionCode in Android build.gradle and CFBundleVersion in iOS Info.plist files
set -e # Exit on any error
echo "Incrementing build numbers..."
# Function to increment version code in Android build.gradle
increment_android_version() {
local file="$1"
echo "Updating Android version in: $file"
# Find current versionCode and increment it
current_version=$(grep -o 'versionCode [0-9]*' "$file" | awk '{print $2}')
if [ -n "$current_version" ]; then
new_version=$((current_version + 1))
echo " Current versionCode: $current_version -> New versionCode: $new_version"
# Replace versionCode with new value
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/versionCode $current_version/versionCode $new_version/" "$file"
else
# Linux
sed -i "s/versionCode $current_version/versionCode $new_version/" "$file"
fi
else
echo " WARNING: No versionCode found in $file"
fi
}
# Function to increment CFBundleVersion in iOS Info.plist files
increment_ios_version() {
local file="$1"
echo "Updating iOS version in: $file"
# Find current CFBundleVersion and increment it
current_version=$(grep -A1 '<key>CFBundleVersion</key>' "$file" | grep '<string>' | sed 's/.*<string>\([0-9]*\)<\/string>.*/\1/')
if [ -n "$current_version" ]; then
new_version=$((current_version + 1))
echo " Current CFBundleVersion: $current_version -> New CFBundleVersion: $new_version"
# Replace CFBundleVersion with new value
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/<string>$current_version<\/string>/<string>$new_version<\/string>/" "$file"
else
# Linux
sed -i "s/<string>$current_version<\/string>/<string>$new_version<\/string>/" "$file"
fi
else
echo " WARNING: No CFBundleVersion found in $file"
fi
}
# Function to increment CURRENT_PROJECT_VERSION in iOS project.pbxproj
increment_ios_project_version() {
local file="$1"
echo "Updating iOS project version in: $file"
# Find all CURRENT_PROJECT_VERSION entries and increment them
current_versions=$(grep -o 'CURRENT_PROJECT_VERSION = [0-9]*;' "$file" | awk '{print $3}' | sed 's/;//' | sort -u)
if [ -n "$current_versions" ]; then
for current_version in $current_versions; do
new_version=$((current_version + 1))
echo " Current CURRENT_PROJECT_VERSION: $current_version -> New CURRENT_PROJECT_VERSION: $new_version"
# Replace CURRENT_PROJECT_VERSION with new value
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/CURRENT_PROJECT_VERSION = $current_version;/CURRENT_PROJECT_VERSION = $new_version;/g" "$file"
else
# Linux
sed -i "s/CURRENT_PROJECT_VERSION = $current_version;/CURRENT_PROJECT_VERSION = $new_version;/g" "$file"
fi
done
else
echo " WARNING: No CURRENT_PROJECT_VERSION found in $file"
fi
}
# Update Android build.gradle
if [ -f "android/app/build.gradle" ]; then
increment_android_version "android/app/build.gradle"
else
echo "ERROR: Android build.gradle not found at android/app/build.gradle"
fi
# Update iOS Info.plist files
ios_files=(
"ios/tribe/Info.plist"
"ios/tribe-dev-Info.plist"
)
for file in "${ios_files[@]}"; do
if [ -f "$file" ]; then
increment_ios_version "$file"
else
echo "ERROR: iOS Info.plist not found at $file"
fi
done
# Update iOS project.pbxproj
if [ -f "ios/tribe.xcodeproj/project.pbxproj" ]; then
increment_ios_project_version "ios/tribe.xcodeproj/project.pbxproj"
else
echo "ERROR: iOS project.pbxproj not found at ios/tribe.xcodeproj/project.pbxproj"
fi
echo ""
echo "Build number increment completed!"
echo ""
echo "Summary of changes:"
echo " Android: versionCode incremented in android/app/build.gradle"
echo " iOS: CFBundleVersion incremented in:"
for file in "${ios_files[@]}" "ios/tribe.xcodeproj/project.pbxproj"; do
if [ -f "$file" ]; then
echo " - $file"
fi
done
echo ""
echo "Adding updated files to git..."
# Add all modified files to git
modified_files=(
"android/app/build.gradle"
"ios/tribe/Info.plist"
"ios/tribe-dev-Info.plist"
"ios/tribe.xcodeproj/project.pbxproj"
)
for file in "${modified_files[@]}"; do
if [ -f "$file" ]; then
if git add "$file" 2>/dev/null; then
echo " SUCCESS: Added $file to git"
else
echo " WARNING: Failed to add $file to git (file may not be tracked)"
fi
fi
done
echo ""
echo "Ready for build! Files have been added to git staging area."