Skip to content

Commit 1a92340

Browse files
author
qinhui
committed
Modify script code, test match version from pod file
1 parent fb028de commit 1a92340

File tree

4 files changed

+284
-129
lines changed

4 files changed

+284
-129
lines changed

.github/ci/build/build_ios.sh

Lines changed: 143 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -68,41 +68,138 @@ apiexample_global_name=Agora_Native_SDK_for_iOS
6868
global_dir=Global
6969

7070
# ===================================
71-
# Version validation logic
71+
# Version Validation Functions
7272
# ===================================
73-
echo "=========================================="
74-
echo "Starting branch version validation..."
75-
echo "=========================================="
7673

77-
# Get current branch name (try multiple methods for CI environments)
78-
BRANCH_NAME=""
79-
80-
# Method 1: Try environment variable (Jenkins/GitLab CI)
81-
if [ ! -z "$GIT_BRANCH" ]; then
82-
BRANCH_NAME="$GIT_BRANCH"
83-
echo "Branch from GIT_BRANCH: $BRANCH_NAME"
84-
elif [ ! -z "$BRANCH_NAME" ]; then
85-
echo "Branch from BRANCH_NAME: $BRANCH_NAME"
86-
elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then
87-
BRANCH_NAME="$CI_COMMIT_REF_NAME"
88-
echo "Branch from CI_COMMIT_REF_NAME: $BRANCH_NAME"
89-
# Method 2: Try git command
90-
elif [ -z "$BRANCH_NAME" ]; then
91-
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
92-
if [ "$BRANCH_NAME" = "HEAD" ]; then
93-
# In detached HEAD state, try to get branch from remote
94-
BRANCH_NAME=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///')
95-
echo "Branch from git branch -r: $BRANCH_NAME"
74+
# Function: Get current branch name from various sources
75+
get_branch_name() {
76+
local branch_name=""
77+
78+
# Method 1: Try environment variable (Jenkins/GitLab CI)
79+
if [ ! -z "$GIT_BRANCH" ]; then
80+
branch_name="$GIT_BRANCH"
81+
echo "Branch from GIT_BRANCH: $branch_name" >&2
82+
elif [ ! -z "$BRANCH_NAME" ]; then
83+
branch_name="$BRANCH_NAME"
84+
echo "Branch from BRANCH_NAME: $branch_name" >&2
85+
elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then
86+
branch_name="$CI_COMMIT_REF_NAME"
87+
echo "Branch from CI_COMMIT_REF_NAME: $branch_name" >&2
88+
# Method 2: Try git command
9689
else
97-
echo "Branch from git rev-parse: $BRANCH_NAME"
90+
branch_name=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
91+
if [ "$branch_name" = "HEAD" ]; then
92+
# In detached HEAD state, try to get branch from remote
93+
branch_name=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///')
94+
echo "Branch from git branch -r: $branch_name" >&2
95+
else
96+
echo "Branch from git rev-parse: $branch_name" >&2
97+
fi
9898
fi
99-
fi
99+
100+
# Remove origin/ prefix if present (but keep the rest of the path)
101+
branch_name=$(echo "$branch_name" | sed 's/^origin\///')
102+
103+
echo "$branch_name"
104+
}
100105

101-
# Remove origin/ prefix if present (but keep the rest of the path)
102-
BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///')
106+
# Function: Validate project MARKETING_VERSION against branch version
107+
validate_project_version() {
108+
local project_path="$1"
109+
local project_name="$2"
110+
local branch_version="$3"
111+
112+
echo "-----------------------------------"
113+
echo "Validating project version: $project_path"
114+
115+
local pbxproj_file="${project_path}/${project_name}.xcodeproj/project.pbxproj"
116+
117+
if [ ! -f "$pbxproj_file" ]; then
118+
echo "Error: project.pbxproj file not found: $pbxproj_file"
119+
return 1
120+
fi
121+
122+
# Extract MARKETING_VERSION for main target (skip Extension targets)
123+
local plist_version=$(grep -A 2 "@executable_path/Frameworks" "$pbxproj_file" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ')
124+
125+
if [ -z "$plist_version" ]; then
126+
echo "Error: Unable to read MARKETING_VERSION from project.pbxproj"
127+
return 1
128+
fi
129+
130+
echo "Project version: $plist_version"
131+
132+
# Compare versions
133+
if [ "$branch_version" != "$plist_version" ]; then
134+
echo ""
135+
echo "=========================================="
136+
echo "Error: Version mismatch!"
137+
echo "=========================================="
138+
echo " Branch version: $branch_version"
139+
echo " Project version: $plist_version"
140+
echo " Project path: $project_path"
141+
echo ""
142+
echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist"
143+
echo ""
144+
return 1
145+
fi
146+
147+
echo "✓ Project version matches: $plist_version"
148+
return 0
149+
}
150+
151+
# Function: Validate SDK version in Podfile against branch version
152+
validate_sdk_version() {
153+
local podfile_path="$1"
154+
local branch_version="$2"
155+
156+
echo "-----------------------------------"
157+
echo "Validating SDK version: $podfile_path"
158+
159+
# Extract SDK version from Podfile (support both AgoraRtcEngine_iOS and AgoraAudio_iOS)
160+
# Also support commented lines (lines starting with #)
161+
local sdk_version=$(grep -E "^[[:space:]]*#?[[:space:]]*pod[[:space:]]+'AgoraRtcEngine_iOS'" "$podfile_path" | sed -n "s/.*'\([0-9.]*\)'.*/\1/p" | head -1)
162+
if [ -z "$sdk_version" ]; then
163+
sdk_version=$(grep -E "^[[:space:]]*#?[[:space:]]*pod[[:space:]]+'AgoraAudio_iOS'" "$podfile_path" | sed -n "s/.*'\([0-9.]*\)'.*/\1/p" | head -1)
164+
fi
165+
166+
if [ -z "$sdk_version" ]; then
167+
echo "Error: Unable to extract SDK version from Podfile"
168+
echo "Podfile path: $podfile_path"
169+
return 1
170+
fi
171+
172+
echo "SDK version: $sdk_version"
173+
174+
# Compare versions
175+
if [ "$branch_version" != "$sdk_version" ]; then
176+
echo ""
177+
echo "=========================================="
178+
echo "Error: SDK version mismatch!"
179+
echo "=========================================="
180+
echo " Branch version: $branch_version"
181+
echo " SDK version: $sdk_version"
182+
echo " Podfile path: $podfile_path"
183+
echo ""
184+
echo "Please ensure the SDK version in Podfile matches the branch version."
185+
echo ""
186+
return 1
187+
fi
188+
189+
echo "✓ SDK version matches: $sdk_version"
190+
return 0
191+
}
192+
193+
# Main version validation logic
194+
echo "=========================================="
195+
echo "Starting branch version validation..."
196+
echo "=========================================="
197+
198+
BRANCH_NAME=$(get_branch_name)
103199

104200
if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then
105201
echo "Warning: Unable to get Git branch name, skipping version validation"
202+
BRANCH_VERSION=""
106203
else
107204
echo "Current branch: $BRANCH_NAME"
108205

@@ -113,53 +210,22 @@ else
113210
echo "Current building project: $ios_direction"
114211
echo ""
115212

116-
# Validate the current project based on ios_direction
213+
# Validate project version
117214
PROJECT_PATH="iOS/${ios_direction}"
118215
PROJECT_NAME="${ios_direction}"
119216

120-
echo "-----------------------------------"
121-
echo "Validating: $PROJECT_PATH"
122-
123-
PBXPROJ_FILE="${PROJECT_PATH}/${PROJECT_NAME}.xcodeproj/project.pbxproj"
124-
125-
if [ ! -f "$PBXPROJ_FILE" ]; then
126-
echo "Error: project.pbxproj file not found: $PBXPROJ_FILE"
217+
if ! validate_project_version "$PROJECT_PATH" "$PROJECT_NAME" "$BRANCH_VERSION"; then
127218
exit 1
128219
fi
129220

130-
# Extract MARKETING_VERSION for main target (skip Extension targets)
131-
# Look for the version that appears with @executable_path/Frameworks (main app)
132-
PLIST_VERSION=$(grep -A 2 "@executable_path/Frameworks" "$PBXPROJ_FILE" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ')
133-
134-
if [ -z "$PLIST_VERSION" ]; then
135-
echo "Error: Unable to read MARKETING_VERSION from project.pbxproj"
136-
exit 1
137-
fi
138-
139-
echo "Project version: $PLIST_VERSION"
140221
echo "-----------------------------------"
141-
142-
# Compare versions
143-
if [ "$BRANCH_VERSION" != "$PLIST_VERSION" ]; then
144-
echo ""
145-
echo "=========================================="
146-
echo "Error: Version mismatch!"
147-
echo "=========================================="
148-
echo " Branch version: $BRANCH_VERSION"
149-
echo " Project version: $PLIST_VERSION"
150-
echo " Project path: $PROJECT_PATH"
151-
echo ""
152-
echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist"
153-
echo ""
154-
exit 1
155-
fi
156-
157-
echo "✓ Version validation passed: $BRANCH_VERSION"
222+
echo "✓ All version validations passed: $BRANCH_VERSION"
158223
else
159224
echo "Warning: Branch name does not match dev/x.x.x format!"
160225
echo "Current branch: $BRANCH_NAME"
161226
echo "Expected format: dev/x.x.x (e.g., dev/4.5.3)"
162227
echo "Skipping version validation for non-version branches..."
228+
BRANCH_VERSION=""
163229
fi
164230
fi
165231

@@ -208,9 +274,23 @@ echo $WORKSPACE/with${ios_direction}_${BUILD_NUMBER}_$zip_name
208274
mv result.zip $WORKSPACE/with${ios_direction}_${BUILD_NUMBER}_$zip_name
209275

210276
if [ $compress_apiexample = true ]; then
211-
sdk_version=$(grep "pod 'AgoraRtcEngine_iOS'" ./iOS/${ios_direction}/Podfile | sed -n "s/.*'\([0-9.]*\)'.*/\1/p")
277+
# Extract SDK version from Podfile (support both AgoraRtcEngine_iOS and AgoraAudio_iOS)
278+
# Also support commented lines
279+
sdk_version=$(grep -E "^[[:space:]]*#?[[:space:]]*pod[[:space:]]+'AgoraRtcEngine_iOS'" ./iOS/${ios_direction}/Podfile | sed -n "s/.*'\([0-9.]*\)'.*/\1/p" | head -1)
280+
if [ -z "$sdk_version" ]; then
281+
sdk_version=$(grep -E "^[[:space:]]*#?[[:space:]]*pod[[:space:]]+'AgoraAudio_iOS'" ./iOS/${ios_direction}/Podfile | sed -n "s/.*'\([0-9.]*\)'.*/\1/p" | head -1)
282+
fi
212283
echo "sdk_version: $sdk_version"
213284

285+
# Validate SDK version matches branch version (if on dev/x.x.x branch)
286+
if [ ! -z "$BRANCH_VERSION" ]; then
287+
if ! validate_sdk_version "./iOS/${ios_direction}/Podfile" "$BRANCH_VERSION"; then
288+
exit 1
289+
fi
290+
else
291+
echo "Skipping SDK version validation (not on dev/x.x.x branch)"
292+
fi
293+
214294
cp -rf ./iOS/${ios_direction} $global_dir/
215295

216296
echo "start compress api example"

0 commit comments

Comments
 (0)