Skip to content

Commit fb028de

Browse files
author
qinhui
committed
Fix issues
1 parent aa97a5c commit fb028de

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

.github/ci/build/build_mac.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,105 @@ apiexample_global_name=Agora_Native_SDK_for_Mac
6565
cn_dir=CN
6666
global_dir=Global
6767

68+
# ===================================
69+
# Version validation logic
70+
# ===================================
71+
echo "=========================================="
72+
echo "Starting branch version validation..."
73+
echo "=========================================="
74+
75+
# Get current branch name (try multiple methods for CI environments)
76+
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"
82+
elif [ ! -z "$BRANCH_NAME" ]; then
83+
echo "Branch from BRANCH_NAME: $BRANCH_NAME"
84+
elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then
85+
BRANCH_NAME="$CI_COMMIT_REF_NAME"
86+
echo "Branch from CI_COMMIT_REF_NAME: $BRANCH_NAME"
87+
# Method 2: Try git command
88+
elif [ -z "$BRANCH_NAME" ]; then
89+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
90+
if [ "$BRANCH_NAME" = "HEAD" ]; then
91+
# In detached HEAD state, try to get branch from remote
92+
BRANCH_NAME=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///')
93+
echo "Branch from git branch -r: $BRANCH_NAME"
94+
else
95+
echo "Branch from git rev-parse: $BRANCH_NAME"
96+
fi
97+
fi
98+
99+
# Remove origin/ prefix if present (but keep the rest of the path)
100+
BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///')
101+
102+
if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then
103+
echo "Warning: Unable to get Git branch name, skipping version validation"
104+
else
105+
echo "Current branch: $BRANCH_NAME"
106+
107+
# Extract version from branch name (format: dev/x.x.x)
108+
if [[ $BRANCH_NAME =~ ^dev/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
109+
BRANCH_VERSION="${BASH_REMATCH[1]}"
110+
echo "Branch version: $BRANCH_VERSION"
111+
echo "Current building project: macOS/APIExample"
112+
echo ""
113+
114+
# Validate the macOS project
115+
PROJECT_PATH="macOS"
116+
PROJECT_NAME="APIExample"
117+
118+
echo "-----------------------------------"
119+
echo "Validating: $PROJECT_PATH"
120+
121+
PBXPROJ_FILE="${PROJECT_PATH}/${PROJECT_NAME}.xcodeproj/project.pbxproj"
122+
123+
if [ ! -f "$PBXPROJ_FILE" ]; then
124+
echo "Error: project.pbxproj file not found: $PBXPROJ_FILE"
125+
exit 1
126+
fi
127+
128+
# Extract MARKETING_VERSION for main target
129+
PLIST_VERSION=$(grep "MARKETING_VERSION" "$PBXPROJ_FILE" | grep -v "//" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ')
130+
131+
if [ -z "$PLIST_VERSION" ]; then
132+
echo "Error: Unable to read MARKETING_VERSION from project.pbxproj"
133+
exit 1
134+
fi
135+
136+
echo "Project version: $PLIST_VERSION"
137+
echo "-----------------------------------"
138+
139+
# Compare versions
140+
if [ "$BRANCH_VERSION" != "$PLIST_VERSION" ]; then
141+
echo ""
142+
echo "=========================================="
143+
echo "Error: Version mismatch!"
144+
echo "=========================================="
145+
echo " Branch version: $BRANCH_VERSION"
146+
echo " Project version: $PLIST_VERSION"
147+
echo " Project path: $PROJECT_PATH"
148+
echo ""
149+
echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist"
150+
echo ""
151+
exit 1
152+
fi
153+
154+
echo "✓ Version validation passed: $BRANCH_VERSION"
155+
else
156+
echo "Warning: Branch name does not match dev/x.x.x format!"
157+
echo "Current branch: $BRANCH_NAME"
158+
echo "Expected format: dev/x.x.x (e.g., dev/4.5.3)"
159+
echo "Skipping version validation for non-version branches..."
160+
fi
161+
fi
162+
163+
echo "Version validation completed"
164+
echo "=========================================="
165+
echo ""
166+
68167
echo zip_name: $zip_name
69168
if [ -z "$sdk_url" -o "$sdk_url" = "none" ]; then
70169
sdk_url_flag=false

0 commit comments

Comments
 (0)