Skip to content

Commit c4c52a9

Browse files
committed
buiild: Update build script to include Cocoapods trunk push and GitHub tag update functionality
* Added Cocoapods trunk push command to clean cache, retrieve current version, delete existing version (if any), and push the new version to the CocoaPods trunk. * Added GitHub tag update command to delete existing tags for the current version (if any) and create a new tag for the current version in the local repository and push it to the remote repository. * Modified the script to check if the current branch is 'main' before performing these actions.
1 parent d477e1c commit c4c52a9

File tree

1 file changed

+80
-13
lines changed

1 file changed

+80
-13
lines changed

run.sh

+80-13
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ local option_list=(
2020
" "
2121
"Xcode - Initialize project"
2222
"Xcode - Clean all build cache"
23-
# " "
24-
# "Carthage - Update all platforms"
25-
# "Cocoapods - Clean all cache"
26-
# "Public Suffix List - Download latest data"
23+
" "
24+
"Carthage - Update all platforms"
25+
"Cocoapods - Clean all cache"
26+
"Cocoapods - Trunk push"
27+
" "
28+
"Github - Update tag"
29+
" "
30+
"Public Suffix List - Download latest data"
2731
)
2832

2933
local fastlane_command() {
@@ -45,14 +49,6 @@ local xcode_init() {
4549
# psl_download;
4650
}
4751

48-
local cocoapods_clean() {
49-
pod cache clean --all;
50-
}
51-
52-
local psl_download() {
53-
python update-psl.py;
54-
}
55-
5652
local carthage_update() {
5753
carthage update --platform macos;
5854
carthage update --platform ios;
@@ -61,6 +57,75 @@ local carthage_update() {
6157
carthage update --platform visionos;
6258
}
6359

60+
local cocoapods_clean() {
61+
pod cache clean --all;
62+
}
63+
64+
local cocoapods_trunk_push() {
65+
# Enable error handling and exit the script on pipe failures
66+
set -eo pipefail
67+
# Check if the current branch is 'main'
68+
if [[ $(git rev-parse --abbrev-ref HEAD) != "main" ]]; then
69+
echo "Warning: You are not on the main branch. Please switch to the main branch and run again."
70+
exit 1
71+
fi
72+
# Find the project name and podspec name
73+
project_name=$(find . -maxdepth 1 -name "*.xcodeproj" -exec basename {} .xcodeproj \;)
74+
podspec_name=$(find . -maxdepth 1 -name "*.podspec" -exec basename {} .podspec \;)
75+
# Retrieve the current version from the project file
76+
current_version=$(grep -m1 'MARKETING_VERSION' "${project_name}.xcodeproj/project.pbxproj" | sed 's/.*= //;s/;//')
77+
echo "Current version: $current_version"
78+
# Check if the current version is a valid semantic version
79+
if [[ ! "$current_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
80+
echo "Error: Invalid version number"
81+
exit 1
82+
fi
83+
# Check if the current version already exists in the CocoaPods trunk
84+
if pod trunk info ${podspec_name} | grep -q "$current_version"; then
85+
echo "Start deleting $current_version"
86+
# Delete the existing version from the CocoaPods trunk
87+
echo "y" | pod trunk delete ${podspec_name} $current_version || true
88+
fi
89+
echo "Start pushing $current_version"
90+
# Push the new version to the CocoaPods trunk
91+
pod trunk push ${podspec_name}.podspec --allow-warnings
92+
}
93+
94+
local github_update_tag() {
95+
# Enable error handling and exit the script on pipe failures
96+
set -eo pipefail
97+
# Check if the current branch is 'main'
98+
if [[ $(git rev-parse --abbrev-ref HEAD) != "main" ]]; then
99+
echo "Warning: You are not on the main branch. Please switch to the main branch and run again."
100+
exit 1
101+
fi
102+
# Find the project name and podspec name
103+
project_name=$(find . -maxdepth 1 -name "*.xcodeproj" -exec basename {} .xcodeproj)
104+
podspec_name=$(find . -maxdepth 1 -name "*.podspec" -exec basename {} .podspec)
105+
# Retrieve build settings and execute a command to filter MARKETING_VERSION
106+
current_version=$(grep -m1 'MARKETING_VERSION' "${project_name}.xcodeproj/project.pbxproj" | sed 's/.*= //;s/;//')
107+
echo "Current version: $current_version"
108+
# If the current version is found
109+
if [[ $current_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
110+
# Check if a tag for the current version already exists
111+
if git tag -l | grep -q "$current_version"; then
112+
# If the tag exists, delete it from both local and remote
113+
git tag -d "$current_version"
114+
git push origin ":refs/tags/$current_version"
115+
fi
116+
# Create a new tag for the current version and push it to the remote repository
117+
git tag "$current_version"
118+
git push origin "$current_version"
119+
else
120+
# If the version could not be retrieved, display an error message
121+
echo "Error: Could not retrieve the version."
122+
fi
123+
}
124+
125+
local psl_download() {
126+
python update-psl.py;
127+
}
128+
64129
local bundle_init() {
65130
rm -rf .bundle;
66131
rm -rf Gemfile.lock;
@@ -75,8 +140,10 @@ case "$selected_option" in
75140
fastlane*) fastlane_command $selected_option;;
76141
"Xcode - Initialize project") xcode_init;;
77142
"Xcode - Clean all build cache") xcode_clean;;
78-
"Cocoapods - Clean all cache") cocoapods_clean;;
79143
"Carthage - Update all platforms") carthage_update;;
144+
"Cocoapods - Clean all cache") cocoapods_clean;;
145+
"Cocoapods - Trunk push") cocoapods_trunk_push;;
146+
"Github - Update tag") github_update_tag;;
80147
"Public Suffix List - Download latest data") psl_download;;
81148
*) echo "Invalid option $selected_option" && exit 1;;
82149
esac

0 commit comments

Comments
 (0)