Skip to content

Commit c6b79ee

Browse files
author
zhangwei
committed
refactor(ci): optimize Android CI version check logic
1 parent bb3cc3e commit c6b79ee

File tree

1 file changed

+60
-62
lines changed

1 file changed

+60
-62
lines changed

.github/ci/build/build_android.sh

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -63,77 +63,83 @@ echo compile_project: $compile_project
6363
echo compress_apiexample: $compress_apiexample
6464
echo api_examples_branch: $api_examples_branch
6565

66-
# Validate required variables
67-
if [ -z "$android_direction" ]; then
68-
echo "Error: android_direction variable is not set"
69-
exit 1
70-
fi
71-
7266
# ===== Version Consistency Check =====
7367
echo ""
7468
echo "=========================================="
7569
echo "Checking version consistency..."
7670
echo "=========================================="
7771

78-
# Extract version number from branch name (supports formats like dev/4.6.2, release/4.6.2, etc.)
79-
BRANCH_VERSION=$(echo $api_examples_branch | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)
72+
# Read version from gradle.properties based on android_direction
73+
GRADLE_FILE="Android/${android_direction}/gradle.properties"
8074

81-
if [ -z "$BRANCH_VERSION" ]; then
75+
if [ ! -f "$GRADLE_FILE" ]; then
8276
echo ""
8377
echo "=========================================="
84-
echo "❌ CI BUILD FAILED: CANNOT EXTRACT VERSION"
78+
echo "❌ CI BUILD FAILED: GRADLE FILE NOT FOUND"
8579
echo "=========================================="
86-
echo "Cannot extract version from branch name: $api_examples_branch"
87-
echo "Branch name must contain version number (e.g., dev/4.6.2, release/4.6.2)"
80+
echo "Cannot find: $GRADLE_FILE"
8881
echo "=========================================="
8982
exit 1
9083
fi
9184

92-
echo "Branch version: $BRANCH_VERSION"
93-
echo ""
94-
95-
# Check all gradle.properties files
96-
GRADLE_FILES=(
97-
"Android/APIExample/gradle.properties"
98-
"Android/APIExample-Audio/gradle.properties"
99-
"Android/APIExample-Compose/gradle.properties"
100-
)
101-
102-
VERSION_MISMATCH=false
85+
SDK_VERSION=$(grep "rtc_sdk_version" "$GRADLE_FILE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
86+
echo "Using version from $GRADLE_FILE: $SDK_VERSION"
10387

104-
for gradle_file in "${GRADLE_FILES[@]}"; do
105-
if [ -f "$gradle_file" ]; then
106-
GRADLE_VERSION=$(grep "rtc_sdk_version" "$gradle_file" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
107-
echo "Checking $gradle_file: $GRADLE_VERSION"
108-
109-
if [ "$GRADLE_VERSION" != "$BRANCH_VERSION" ]; then
110-
echo "❌ ERROR: Version mismatch in $gradle_file"
111-
echo " Branch version: $BRANCH_VERSION"
112-
echo " Gradle version: $GRADLE_VERSION"
113-
VERSION_MISMATCH=true
114-
else
115-
echo "✅ Version matched: $GRADLE_VERSION"
116-
fi
117-
else
118-
echo "⚠️ Warning: $gradle_file not found"
119-
fi
120-
echo ""
121-
done
122-
123-
if [ "$VERSION_MISMATCH" = true ]; then
88+
if [ -z "$SDK_VERSION" ]; then
12489
echo ""
12590
echo "=========================================="
126-
echo "❌ CI BUILD FAILED: VERSION MISMATCH"
91+
echo "❌ CI BUILD FAILED: CANNOT EXTRACT VERSION"
12792
echo "=========================================="
128-
echo "Branch name contains version: $BRANCH_VERSION"
129-
echo "But gradle.properties has different version(s)"
130-
echo ""
131-
echo "Please update rtc_sdk_version in all gradle.properties files to: $BRANCH_VERSION"
93+
echo "Cannot extract rtc_sdk_version from $GRADLE_FILE"
94+
echo "Please ensure rtc_sdk_version is set in gradle.properties"
13295
echo "=========================================="
13396
exit 1
13497
fi
13598

136-
echo "✅ All version checks passed!"
99+
echo ""
100+
101+
# Skip version check for main branch (we trust main when building from it)
102+
api_examples_branch_stripped=$(echo "$api_examples_branch" | sed 's|^origin/||')
103+
if [ "$api_examples_branch_stripped" = "main" ]; then
104+
echo "Branch is main, skipping version consistency check (main branch is trusted)"
105+
echo "Using version: $SDK_VERSION"
106+
else
107+
# Extract version number from branch name (supports formats like dev/4.6.2, release/4.6.2, etc.)
108+
BRANCH_NAME_VERSION=$(echo $api_examples_branch | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)
109+
110+
if [ -z "$BRANCH_NAME_VERSION" ]; then
111+
echo ""
112+
echo "=========================================="
113+
echo "❌ CI BUILD FAILED: CANNOT EXTRACT VERSION FROM BRANCH"
114+
echo "=========================================="
115+
echo "Cannot extract version from branch name: $api_examples_branch"
116+
echo "Branch name must contain version number (e.g., dev/4.6.2, release/4.6.2)"
117+
echo "=========================================="
118+
exit 1
119+
fi
120+
121+
echo "Branch name version: $BRANCH_NAME_VERSION"
122+
echo ""
123+
124+
# Check gradle.properties for consistency with branch name
125+
GRADLE_VERSION=$(grep "rtc_sdk_version" "$GRADLE_FILE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
126+
echo "Checking $GRADLE_FILE: $GRADLE_VERSION"
127+
128+
if [ "$GRADLE_VERSION" != "$BRANCH_NAME_VERSION" ]; then
129+
echo ""
130+
echo "=========================================="
131+
echo "❌ CI BUILD FAILED: VERSION MISMATCH"
132+
echo "=========================================="
133+
echo "Branch name contains version: $BRANCH_NAME_VERSION"
134+
echo "But $GRADLE_FILE has version: $GRADLE_VERSION"
135+
echo ""
136+
echo "Please update rtc_sdk_version in $GRADLE_FILE to: $BRANCH_NAME_VERSION"
137+
echo "=========================================="
138+
exit 1
139+
fi
140+
141+
echo "✅ Version check passed: $GRADLE_VERSION"
142+
fi
137143
echo "=========================================="
138144
echo ""
139145

@@ -198,7 +204,7 @@ if [ "$compress_apiexample" = true ]; then
198204
echo "✅ Code-only package created"
199205

200206
# Generate final output zip name with version
201-
OUTPUT_ZIP_NAME="Agora_Native_SDK_for_Android_v${BRANCH_VERSION}_${android_direction}_${BUILD_NUMBER}.zip"
207+
OUTPUT_ZIP_NAME="Agora_Native_SDK_for_Android_v${SDK_VERSION}_${android_direction}_${BUILD_NUMBER}.zip"
202208
echo "Output zip name: $OUTPUT_ZIP_NAME"
203209
mv $TEMP_ZIP_NAME $WORKSPACE/$OUTPUT_ZIP_NAME
204210

@@ -212,7 +218,7 @@ else
212218
echo "✅ Full package created"
213219

214220
# Generate final output zip name with version (with SDK)
215-
OUTPUT_ZIP_NAME="withSDK_Agora_Native_SDK_for_Android_v${BRANCH_VERSION}_${android_direction}_${BUILD_NUMBER}.zip"
221+
OUTPUT_ZIP_NAME="withSDK_Agora_Native_SDK_for_Android_v${SDK_VERSION}_${android_direction}_${BUILD_NUMBER}.zip"
216222
echo "Output zip name: $OUTPUT_ZIP_NAME"
217223
mv $TEMP_ZIP_NAME $WORKSPACE/$OUTPUT_ZIP_NAME
218224

@@ -224,20 +230,12 @@ echo ""
224230
if [ $compile_project = true ]; then
225231
echo "Starting project compilation..."
226232
cd ./$unzip_name/rtc/samples/${android_direction} || exit 1
227-
228-
# Try to compile, but don't fail the build if compilation fails
229233
if [ -z "$sdk_url" ] || [ "$sdk_url" = "none" ]; then
230-
./cloud_build.sh false || echo "⚠️ Warning: Project compilation failed, but continuing..."
231-
else
232-
./cloud_build.sh true || echo "⚠️ Warning: Project compilation failed, but continuing..."
233-
fi
234-
235-
# Check if compilation was successful
236-
if [ $? -eq 0 ]; then
237-
echo "✅ Project compiled successfully"
234+
./cloud_build.sh false || exit 1
238235
else
239-
echo "⚠️ Project compilation had issues, but package was created successfully"
236+
./cloud_build.sh true || exit 1
240237
fi
238+
echo "✅ Project compiled successfully"
241239
echo ""
242240
fi
243241

0 commit comments

Comments
 (0)