-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush-beta.sh
More file actions
executable file
·226 lines (187 loc) · 6.68 KB
/
Copy pathpush-beta.sh
File metadata and controls
executable file
·226 lines (187 loc) · 6.68 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
#!/bin/bash
# Set Script Variables
project="DocB.xcodeproj"
target="DocB"
branch="beta" # Default branch
dry_run=false # Default dry run setting
# Function to get the version number from the Xcode project
getVersion() {
xcodeproj=$1
target=$2
# Command to extract the version number from the Xcode project
version=$(xcrun xcodebuild -project "$xcodeproj" -target "$target" -showBuildSettings | grep "MARKETING_VERSION" | awk '{print $3}')
# Output the message to the terminal without altering $version
echo "Project Version: $version"
}
# Function to get the current build number from the Xcode project
getOldBuild() {
xcodeproj=$1
# Replace with appropriate command to extract build number from Xcode project
build_number=$(agvtool what-version | grep -o '[0-9]\+')
echo "Previous Project Build Number: $build_number"
}
getBuild() {
xcodeproj=$1
# Replace with appropriate command to extract build number from Xcode project
build_number=$(agvtool what-version | grep -o '[0-9]\+')
echo "Project Build Number: $build_number"
}
# Function to update the version number
updateVersion() {
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <path_to_pbxproj> <new_marketing_version>"
exit 1
fi
new_version="$1"
pbxproj_file="$2/project.pbxproj"
# Check if the file exists
if [ ! -f "$pbxproj_file" ]; then
echo "Error: File '$pbxproj_file' not found."
exit 1
fi
# Update MARKETING_VERSION
echo "Updating MARKETING_VERSION to '$new_version' in '$pbxproj_file'..."
sed -i "" "s/\(MARKETING_VERSION = \).*/\1$new_version;/g" "$pbxproj_file"
# Verify if the update was successful
if grep -q "MARKETING_VERSION = $new_version;" "$pbxproj_file"; then
echo "Successfully updated MARKETING_VERSION to '$new_version'."
else
echo "Error: Failed to update MARKETING_VERSION."
fi
}
# Function to increment the build number
increment_build_number() {
build_number=$1
xcodeproj=$2
# Increment the build number and update the Xcode project
agvtool new-version -all "$build_number"
}
# Function to copy non-git files to temporary directory
copy_files_to_temp() {
temp_dir="$1"
echo "Creating temporary directory: $temp_dir"
mkdir -p "$temp_dir"
echo "Copying non-git files to temporary directory..."
# Use rsync to copy all files except .git directory
rsync -aq --exclude='.git' --exclude='.gitmodules' ./ "$temp_dir/"
if [ $? -eq 0 ]; then
echo "Successfully copied files to $temp_dir"
else
echo "Error: Failed to copy files to temporary directory"
exit 1
fi
}
# Function to clean non-git files from working directory
clean_working_directory() {
echo "Cleaning non-git files from working directory..."
# Find all files and directories except .git and remove them
find . -mindepth 1 -maxdepth 1 -name ".git" -prune -o -print0 | xargs -0 rm -rf
if [ $? -eq 0 ]; then
echo "Successfully cleaned working directory"
else
echo "Error: Failed to clean working directory"
exit 1
fi
}
# Function to copy files back from temporary directory
copy_files_from_temp() {
temp_dir="$1"
echo "Copying files back from temporary directory..."
# Copy everything except .git from temp directory back to current directory
rsync -aq --exclude='.git' "$temp_dir/" ./
if [ $? -eq 0 ]; then
echo "Successfully copied files back from $temp_dir"
else
echo "Error: Failed to copy files back from temporary directory"
exit 1
fi
}
# Function to cleanup temporary directory
cleanup_temp_directory() {
temp_dir="$1"
if [ -d "$temp_dir" ]; then
echo "Cleaning up temporary directory: $temp_dir"
rm -rf "$temp_dir"
echo "Temporary directory cleaned up"
fi
}
# Parse command-line arguments (support short options and long options with
# either `--opt=value` or `--opt value` forms)
while [[ $# -gt 0 ]]; do
case "$1" in
--branch=*) branch="${1#*=}" ;;
--branch) shift; branch="$1" ;;
--build=*|--build-number=*) build_number="${1#*=}"; build_number_provided=true ;;
--build|--build-number) shift; build_number="$1"; build_number_provided=true ;;
--version=*) new_version="${1#*=}" ;;
--version) shift; new_version="$1" ;;
--dry-run) dry_run=true ;;
-b) shift; branch="$1" ;;
-v) shift; new_version="$1" ;;
-d) dry_run=true ;;
--) shift; break ;;
*)
echo "Invalid option: $1" >&2
echo "Usage: $0 [-b branch] [-v version] [--build build-number] [-d]" >&2
exit 1
;;
esac
shift
done
# Get the initial version and build number
getVersion "$project" "$target"
# Get the build number if one to set is not provided
if [ -z "$build_number" ]; then
getOldBuild "$project"
fi
# Update version if provided
if [ ! -z "$new_version" ]; then
echo "Updating version to: $new_version"
updateVersion "$new_version" "$project"
# Get the updated version
getVersion "$project" "$target"
fi
# Update build number
if [ "$build_number_provided" = true ]; then
increment_build_number "$build_number" "$project"
else
increment_build_number $(($build_number + 1)) "$project"
fi
getBuild "$project"
# Commit the change
if [ "$dry_run" = true ]; then
echo "[DRY RUN] Would commit build number change"
echo "[DRY RUN] Would perform git operations"
else
echo "Committing the build number change"
git commit -a -m "Bumped Build Number"
git push
# Commit and push the build number change
commit_message="$version($build_number)"
commit_description="This is the beta release for $version($build_number)"
# Get the original branch
original_branch=$(git rev-parse --abbrev-ref HEAD)
# Create temporary directory for file storage based on current folder name
folder_name=$(basename "$(pwd)")
temp_dir="/tmp/${folder_name}_files_$(date +%s)"
# Copy all non-git files to temporary directory
copy_files_to_temp "$temp_dir"
# Switch to the target branch (using the value from --branch or -b flag)
git switch "$branch"
git pull
# Clean all non-git files from working directory
clean_working_directory
# Copy files back from temporary directory
copy_files_from_temp "$temp_dir"
# Stage all files and commit
git add .
git commit -m "$commit_message" -m "$commit_description"
# Push the changes
git push
# Clean up temporary directory
cleanup_temp_directory "$temp_dir"
# Switch back to the original branch
git checkout "$original_branch"
fi
echo ""
echo "Beta push complete!"