diff --git a/.github/ci/build/build_android.sh b/.github/ci/build/build_android.sh index 4bb0e7fba..74ba6527b 100644 --- a/.github/ci/build/build_android.sh +++ b/.github/ci/build/build_android.sh @@ -75,6 +75,12 @@ echo "==========================================" echo "Checking version consistency..." echo "==========================================" +# Skip version check for main branch (we trust main when building from it) +api_examples_shengwang_branch_stripped=$(echo "$api_examples_shengwang_branch" | sed 's|^origin/||') +if [ "$api_examples_shengwang_branch_stripped" = "main" ]; then + echo "Branch is main, skipping version consistency check (main branch is trusted)" +else + # Extract version number from branch name (supports formats like dev/4.6.2, release/4.6.2, etc.) BRANCH_VERSION=$(echo $api_examples_shengwang_branch | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1) @@ -135,6 +141,7 @@ fi echo "✅ All version checks passed!" echo "==========================================" +fi echo "" unzip_name=Shengwang_Native_SDK_for_Android_FULL_DEFAULT diff --git a/.github/ci/build/build_ios.sh b/.github/ci/build/build_ios.sh index d8848889d..1d20fc91f 100644 --- a/.github/ci/build/build_ios.sh +++ b/.github/ci/build/build_ios.sh @@ -118,9 +118,20 @@ echo $WORKSPACE/with${ios_direction}_${BUILD_NUMBER}_$zip_name mv result.zip $WORKSPACE/with${ios_direction}_${BUILD_NUMBER}_$zip_name if [ $compress_apiexample = true ]; then - sdk_version=$(grep "pod 'ShengwangRtcEngine_iOS'" ./iOS/${ios_direction}/Podfile | sed -n "s/.*'\([0-9.]*\)'.*/\1/p") + # Extract SDK version from Podfile (support both commented and uncommented lines) + # Try ShengwangRtcEngine_iOS first, then ShengwangAudio_iOS + sdk_version=$(grep -E "Shengwang(RtcEngine|Audio)_iOS" ./iOS/${ios_direction}/Podfile | sed -n "s/.*'\([0-9.]*\)'.*/\1/p" | head -1) echo "sdk_version: $sdk_version" + # Source common functions for version validation + source ./.github/ci/build/common_functions.sh + + # Validate SDK version against branch version + validate_sdk_version "$sdk_version" || exit 1 + + # Validate project version against branch version + validate_version "./iOS/${ios_direction}/${ios_direction}.xcodeproj/project.pbxproj" "" "ios" || exit 1 + mkdir -p $cn_dir cp -rf ./iOS/${ios_direction} $cn_dir/ cd $cn_dir/${ios_direction} diff --git a/.github/ci/build/build_mac.sh b/.github/ci/build/build_mac.sh index b8e9ba2be..6f215b93d 100644 --- a/.github/ci/build/build_mac.sh +++ b/.github/ci/build/build_mac.sh @@ -105,9 +105,20 @@ echo $WORKSPACE/with${BUILD_NUMBER}_$zip_name mv result.zip $WORKSPACE/with_${BUILD_NUMBER}_$zip_name if [ $compress_apiexample = true ]; then - sdk_version=$(grep "pod 'ShengwangRtcEngine_macOS'" ./macOS/Podfile | sed -n "s/.*'\([0-9.]*\)'.*/\1/p") + # Extract SDK version from Podfile (support both commented and uncommented lines) + # Try ShengwangRtcEngine_macOS first, then ShengwangAudio_macOS + sdk_version=$(grep -E "Shengwang(RtcEngine|Audio)_macOS" ./macOS/Podfile | sed -n "s/.*'\([0-9.]*\)'.*/\1/p" | head -1) echo "sdk_version: $sdk_version" + # Source common functions for version validation + source ./.github/ci/build/common_functions.sh + + # Validate SDK version against branch version + validate_sdk_version "$sdk_version" || exit 1 + + # Validate project version against branch version + validate_version "./macOS/APIExample.xcodeproj/project.pbxproj" "" "macos" || exit 1 + mkdir -p $cn_dir echo "cn_dir: $cn_dir" cp -rf ./macOS $cn_dir/ diff --git a/.github/ci/build/build_windows.bat b/.github/ci/build/build_windows.bat index 1fd3f166f..5aa78ee2a 100644 --- a/.github/ci/build/build_windows.bat +++ b/.github/ci/build/build_windows.bat @@ -49,12 +49,18 @@ echo sdk_url: %sdk_url% REM Version validation: branch name vs install.ps1 SDK version for /f "tokens=*" %%a in ('powershell -Command "(Get-Content 'windows\APIExample\install.ps1' -Raw) -match '_v([0-9]+\.[0-9]+\.[0-9]+)' | Out-Null; $matches[1]"') do set SDK_VER=%%a +set "BRANCH_STRIP=%api_examples_shengwang_branch:origin/=%" +if "%BRANCH_STRIP%"=="main" ( + echo Branch is main, skipping version validation ^(main branch is trusted^) + goto :skip_version_validation +) for /f "tokens=*" %%b in ('powershell -Command "'%api_examples_shengwang_branch%' -match '([0-9]+\.[0-9]+\.[0-9]+)' | Out-Null; $matches[1]"') do set BRANCH_VER=%%b if not "%SDK_VER%"=="%BRANCH_VER%" ( echo ERROR: Version mismatch - Branch: %BRANCH_VER%, install.ps1: %SDK_VER% exit /b 1 ) echo Version validated: %BRANCH_VER% +:skip_version_validation REM If sdk_url has a value, replace the URL in install.ps1 if not "%sdk_url%"=="" ( diff --git a/.github/ci/build/common_functions.sh b/.github/ci/build/common_functions.sh new file mode 100755 index 000000000..a4bef08dd --- /dev/null +++ b/.github/ci/build/common_functions.sh @@ -0,0 +1,183 @@ +#!/usr/bin/env bash + +# Common functions for iOS/macOS build scripts +# This file contains reusable functions for version validation + +# Function: Get current git branch name +# Tries multiple methods to determine the branch name in CI environments +# Returns: Branch name (without origin/ prefix) +get_branch_name() { + local branch_name="" + + # Method 1: Try environment variables (Jenkins/GitLab CI) + if [ ! -z "$GIT_BRANCH" ]; then + branch_name="$GIT_BRANCH" + echo "Branch from GIT_BRANCH: $branch_name" >&2 + elif [ ! -z "$BRANCH_NAME" ]; then + branch_name="$BRANCH_NAME" + echo "Branch from BRANCH_NAME: $branch_name" >&2 + elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then + branch_name="$CI_COMMIT_REF_NAME" + echo "Branch from CI_COMMIT_REF_NAME: $branch_name" >&2 + # Method 2: Try git command + else + branch_name=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) + if [ "$branch_name" = "HEAD" ]; then + # In detached HEAD state, try to get branch from remote + branch_name=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///') + echo "Branch from git branch -r: $branch_name" >&2 + else + echo "Branch from git rev-parse: $branch_name" >&2 + fi + fi + + # Remove origin/ prefix if present (but keep the rest of the path) + branch_name=$(echo "$branch_name" | sed 's/^origin\///') + + echo "$branch_name" +} + +# Function: Extract version from branch name +# Args: +# $1 - Branch name +# Returns: Version string (e.g., "4.6.2") or empty if not in dev/x.x.x format +extract_branch_version() { + local branch_name="$1" + + if [[ $branch_name =~ ^dev/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + echo "${BASH_REMATCH[1]}" + else + echo "" + fi +} + +# Function: Validate version between branch name and project file +# Args: +# $1 - Path to project.pbxproj file +# $2 - Branch name (optional, will auto-detect if not provided) +# $3 - Platform (optional: "ios" or "macos", defaults to "ios") +# Returns: 0 on success, 1 on failure +validate_version() { + local pbxproj_file="$1" + local branch_name="${2:-$(get_branch_name)}" + local platform="${3:-ios}" + + echo "Starting branch version validation..." + + if [ -z "$branch_name" ] || [ "$branch_name" = "HEAD" ]; then + echo "Warning: Unable to get Git branch name, skipping version validation" + return 0 + fi + + # Skip version check for main branch (we trust main when building from it) + if [ "$branch_name" = "main" ]; then + echo "Branch is main, skipping version validation (main branch is trusted)" + return 0 + fi + + echo "Current branch: $branch_name" + + # Extract version from branch name (format: dev/x.x.x) + local branch_version=$(extract_branch_version "$branch_name") + + if [ -z "$branch_version" ]; then + echo "Error: Branch name does not match dev/x.x.x format!" + echo "Current branch: $branch_name" + echo "Required format: dev/x.x.x (e.g., dev/4.6.2)" + return 1 + fi + + echo "Branch version: $branch_version" + + # Check if project.pbxproj file exists + if [ ! -f "$pbxproj_file" ]; then + echo "Error: project.pbxproj file not found: $pbxproj_file" + return 1 + fi + + # Extract MARKETING_VERSION for main target (skip Extension targets) + # iOS uses @executable_path/Frameworks, macOS uses @executable_path/../Frameworks + local plist_version="" + if [ "$platform" = "macos" ]; then + plist_version=$(grep -A 2 "@executable_path/../Frameworks" "$pbxproj_file" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ') + else + plist_version=$(grep -A 2 "@executable_path/Frameworks" "$pbxproj_file" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ') + fi + + if [ -z "$plist_version" ]; then + echo "Error: Unable to read MARKETING_VERSION from project.pbxproj" + return 1 + fi + + echo "Info.plist version: $plist_version" + + # Compare versions + if [ "$branch_version" != "$plist_version" ]; then + echo "Error: Version mismatch!" + echo " Branch version: $branch_version" + echo " Info.plist version: $plist_version" + echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist" + return 1 + fi + + echo "✓ Version validation passed: $branch_version" + echo "Version validation completed" + echo "-----------------------------------" + return 0 +} + +# Function: Validate SDK version against branch version +# Args: +# $1 - SDK version (e.g., "4.6.2") +# $2 - Branch name (optional, will auto-detect if not provided) +# Returns: 0 on success, 1 on failure +validate_sdk_version() { + local sdk_version="$1" + local branch_name="${2:-$(get_branch_name)}" + + echo "Starting SDK version validation..." + + if [ -z "$sdk_version" ]; then + echo "Warning: SDK version is empty, skipping SDK version validation" + return 0 + fi + + if [ -z "$branch_name" ] || [ "$branch_name" = "HEAD" ]; then + echo "Warning: Unable to get Git branch name, skipping SDK version validation" + return 0 + fi + + # Skip version check for main branch (we trust main when building from it) + if [ "$branch_name" = "main" ]; then + echo "Branch is main, skipping SDK version validation (main branch is trusted)" + return 0 + fi + + echo "Current branch: $branch_name" + echo "SDK version from Podfile: $sdk_version" + + # Extract version from branch name + local branch_version=$(extract_branch_version "$branch_name") + + if [ -z "$branch_version" ]; then + echo "Warning: Branch name does not match dev/x.x.x format, skipping SDK version validation" + echo "Current branch: $branch_name" + return 0 + fi + + echo "Branch version: $branch_version" + + # Compare SDK version with branch version + if [ "$sdk_version" != "$branch_version" ]; then + echo "Error: SDK version mismatch!" + echo " SDK version (Podfile): $sdk_version" + echo " Branch version: $branch_version" + echo "Please ensure the SDK version in Podfile matches the branch version" + return 1 + fi + + echo "✓ SDK version validation passed: $sdk_version" + echo "SDK version validation completed" + echo "-----------------------------------" + return 0 +} diff --git a/iOS/APIExample-Audio/cloud_build.sh b/iOS/APIExample-Audio/cloud_build.sh index 309aad7e2..a04fedb8c 100755 --- a/iOS/APIExample-Audio/cloud_build.sh +++ b/iOS/APIExample-Audio/cloud_build.sh @@ -41,8 +41,12 @@ fi # Remove origin/ prefix if present (but keep the rest of the path) BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" +if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ] || [ "$BRANCH_NAME" = "main" ]; then + if [ "$BRANCH_NAME" = "main" ]; then + echo "Branch is main, skipping version validation (main branch is trusted)" + else + echo "Warning: Unable to get Git branch name, skipping version validation" + fi else echo "Current branch: $BRANCH_NAME" diff --git a/iOS/APIExample-Audio/cloud_project.sh b/iOS/APIExample-Audio/cloud_project.sh index 2b3675852..3617dd1a1 100755 --- a/iOS/APIExample-Audio/cloud_project.sh +++ b/iOS/APIExample-Audio/cloud_project.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash PROJECT_PATH=$PWD @@ -9,84 +9,5 @@ if [ "$BUILD_NUMBER" = "" ]; then BUILD_NUMBER=888 fi -# Version validation logic -echo "Starting branch version validation..." - -# Get current branch name (try multiple methods for CI environments) -BRANCH_NAME="" - -# Method 1: Try environment variable (Jenkins/GitLab CI) -if [ ! -z "$GIT_BRANCH" ]; then - BRANCH_NAME="$GIT_BRANCH" - echo "Branch from GIT_BRANCH: $BRANCH_NAME" -elif [ ! -z "$BRANCH_NAME" ]; then - echo "Branch from BRANCH_NAME: $BRANCH_NAME" -elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then - BRANCH_NAME="$CI_COMMIT_REF_NAME" - echo "Branch from CI_COMMIT_REF_NAME: $BRANCH_NAME" -# Method 2: Try git command -elif [ -z "$BRANCH_NAME" ]; then - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) - if [ "$BRANCH_NAME" = "HEAD" ]; then - # In detached HEAD state, try to get branch from remote - BRANCH_NAME=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///') - echo "Branch from git branch -r: $BRANCH_NAME" - else - echo "Branch from git rev-parse: $BRANCH_NAME" - fi -fi - -# Remove origin/ prefix if present (but keep the rest of the path) -BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') - -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" -else - echo "Current branch: $BRANCH_NAME" - - # Extract version from branch name (format: dev/x.x.x) - if [[ $BRANCH_NAME =~ ^dev/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then - BRANCH_VERSION="${BASH_REMATCH[1]}" - echo "Branch version: $BRANCH_VERSION" - - # Read MARKETING_VERSION from project.pbxproj - PBXPROJ_FILE="${PROJECT_PATH}/APIExample-Audio.xcodeproj/project.pbxproj" - if [ ! -f "$PBXPROJ_FILE" ]; then - echo "Error: project.pbxproj file not found: $PBXPROJ_FILE" - exit 1 - fi - - # Extract MARKETING_VERSION for main target - PLIST_VERSION=$(grep -A 2 "@executable_path/Frameworks" "$PBXPROJ_FILE" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ') - - if [ -z "$PLIST_VERSION" ]; then - echo "Error: Unable to read MARKETING_VERSION from project.pbxproj" - exit 1 - fi - - echo "Info.plist version: $PLIST_VERSION" - - # Compare versions - if [ "$BRANCH_VERSION" != "$PLIST_VERSION" ]; then - echo "Error: Version mismatch!" - echo " Branch version: $BRANCH_VERSION" - echo " Info.plist version: $PLIST_VERSION" - echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist" - exit 1 - fi - - echo "✓ Version validation passed: $BRANCH_VERSION" - else - echo "Error: Branch name does not match dev/x.x.x format!" - echo "Current branch: $BRANCH_NAME" - echo "Required format: dev/x.x.x (e.g., dev/4.6.2)" - exit 1 - fi -fi - -echo "Version validation completed" -echo "-----------------------------------" - - cd ${PROJECT_PATH} && pod install || exit 1 diff --git a/iOS/APIExample-OC/cloud_build.sh b/iOS/APIExample-OC/cloud_build.sh index 2f2a561c5..ecb5e285c 100755 --- a/iOS/APIExample-OC/cloud_build.sh +++ b/iOS/APIExample-OC/cloud_build.sh @@ -41,8 +41,12 @@ fi # Remove origin/ prefix if present (but keep the rest of the path) BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" +if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ] || [ "$BRANCH_NAME" = "main" ]; then + if [ "$BRANCH_NAME" = "main" ]; then + echo "Branch is main, skipping version validation (main branch is trusted)" + else + echo "Warning: Unable to get Git branch name, skipping version validation" + fi else echo "Current branch: $BRANCH_NAME" diff --git a/iOS/APIExample-OC/cloud_project.sh b/iOS/APIExample-OC/cloud_project.sh index 4a019e782..3617dd1a1 100755 --- a/iOS/APIExample-OC/cloud_project.sh +++ b/iOS/APIExample-OC/cloud_project.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash PROJECT_PATH=$PWD @@ -9,84 +9,5 @@ if [ "$BUILD_NUMBER" = "" ]; then BUILD_NUMBER=888 fi -# Version validation logic -echo "Starting branch version validation..." - -# Get current branch name (try multiple methods for CI environments) -BRANCH_NAME="" - -# Method 1: Try environment variable (Jenkins/GitLab CI) -if [ ! -z "$GIT_BRANCH" ]; then - BRANCH_NAME="$GIT_BRANCH" - echo "Branch from GIT_BRANCH: $BRANCH_NAME" -elif [ ! -z "$BRANCH_NAME" ]; then - echo "Branch from BRANCH_NAME: $BRANCH_NAME" -elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then - BRANCH_NAME="$CI_COMMIT_REF_NAME" - echo "Branch from CI_COMMIT_REF_NAME: $BRANCH_NAME" -# Method 2: Try git command -elif [ -z "$BRANCH_NAME" ]; then - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) - if [ "$BRANCH_NAME" = "HEAD" ]; then - # In detached HEAD state, try to get branch from remote - BRANCH_NAME=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///') - echo "Branch from git branch -r: $BRANCH_NAME" - else - echo "Branch from git rev-parse: $BRANCH_NAME" - fi -fi - -# Remove origin/ prefix if present (but keep the rest of the path) -BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') - -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" -else - echo "Current branch: $BRANCH_NAME" - - # Extract version from branch name (format: dev/x.x.x) - if [[ $BRANCH_NAME =~ ^dev/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then - BRANCH_VERSION="${BASH_REMATCH[1]}" - echo "Branch version: $BRANCH_VERSION" - - # Read MARKETING_VERSION from project.pbxproj - PBXPROJ_FILE="${PROJECT_PATH}/APIExample-OC.xcodeproj/project.pbxproj" - if [ ! -f "$PBXPROJ_FILE" ]; then - echo "Error: project.pbxproj file not found: $PBXPROJ_FILE" - exit 1 - fi - - # Extract MARKETING_VERSION for main target - PLIST_VERSION=$(grep -A 2 "@executable_path/Frameworks" "$PBXPROJ_FILE" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ') - - if [ -z "$PLIST_VERSION" ]; then - echo "Error: Unable to read MARKETING_VERSION from project.pbxproj" - exit 1 - fi - - echo "Info.plist version: $PLIST_VERSION" - - # Compare versions - if [ "$BRANCH_VERSION" != "$PLIST_VERSION" ]; then - echo "Error: Version mismatch!" - echo " Branch version: $BRANCH_VERSION" - echo " Info.plist version: $PLIST_VERSION" - echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist" - exit 1 - fi - - echo "✓ Version validation passed: $BRANCH_VERSION" - else - echo "Error: Branch name does not match dev/x.x.x format!" - echo "Current branch: $BRANCH_NAME" - echo "Required format: dev/x.x.x (e.g., dev/4.6.2)" - exit 1 - fi -fi - -echo "Version validation completed" -echo "-----------------------------------" - - cd ${PROJECT_PATH} && pod install || exit 1 diff --git a/iOS/APIExample-SwiftUI/cloud_build.sh b/iOS/APIExample-SwiftUI/cloud_build.sh index 2a6ce4d4d..4160bf4e2 100755 --- a/iOS/APIExample-SwiftUI/cloud_build.sh +++ b/iOS/APIExample-SwiftUI/cloud_build.sh @@ -41,8 +41,12 @@ fi # Remove origin/ prefix if present (but keep the rest of the path) BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" +if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ] || [ "$BRANCH_NAME" = "main" ]; then + if [ "$BRANCH_NAME" = "main" ]; then + echo "Branch is main, skipping version validation (main branch is trusted)" + else + echo "Warning: Unable to get Git branch name, skipping version validation" + fi else echo "Current branch: $BRANCH_NAME" diff --git a/iOS/APIExample-SwiftUI/cloud_project.sh b/iOS/APIExample-SwiftUI/cloud_project.sh index 301d514b9..3617dd1a1 100755 --- a/iOS/APIExample-SwiftUI/cloud_project.sh +++ b/iOS/APIExample-SwiftUI/cloud_project.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash PROJECT_PATH=$PWD @@ -9,84 +9,5 @@ if [ "$BUILD_NUMBER" = "" ]; then BUILD_NUMBER=888 fi -# Version validation logic -echo "Starting branch version validation..." - -# Get current branch name (try multiple methods for CI environments) -BRANCH_NAME="" - -# Method 1: Try environment variable (Jenkins/GitLab CI) -if [ ! -z "$GIT_BRANCH" ]; then - BRANCH_NAME="$GIT_BRANCH" - echo "Branch from GIT_BRANCH: $BRANCH_NAME" -elif [ ! -z "$BRANCH_NAME" ]; then - echo "Branch from BRANCH_NAME: $BRANCH_NAME" -elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then - BRANCH_NAME="$CI_COMMIT_REF_NAME" - echo "Branch from CI_COMMIT_REF_NAME: $BRANCH_NAME" -# Method 2: Try git command -elif [ -z "$BRANCH_NAME" ]; then - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) - if [ "$BRANCH_NAME" = "HEAD" ]; then - # In detached HEAD state, try to get branch from remote - BRANCH_NAME=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///') - echo "Branch from git branch -r: $BRANCH_NAME" - else - echo "Branch from git rev-parse: $BRANCH_NAME" - fi -fi - -# Remove origin/ prefix if present (but keep the rest of the path) -BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') - -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" -else - echo "Current branch: $BRANCH_NAME" - - # Extract version from branch name (format: dev/x.x.x) - if [[ $BRANCH_NAME =~ ^dev/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then - BRANCH_VERSION="${BASH_REMATCH[1]}" - echo "Branch version: $BRANCH_VERSION" - - # Read MARKETING_VERSION from project.pbxproj - PBXPROJ_FILE="${PROJECT_PATH}/APIExample-SwiftUI.xcodeproj/project.pbxproj" - if [ ! -f "$PBXPROJ_FILE" ]; then - echo "Error: project.pbxproj file not found: $PBXPROJ_FILE" - exit 1 - fi - - # Extract MARKETING_VERSION for main target - PLIST_VERSION=$(grep -A 2 "@executable_path/Frameworks" "$PBXPROJ_FILE" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ') - - if [ -z "$PLIST_VERSION" ]; then - echo "Error: Unable to read MARKETING_VERSION from project.pbxproj" - exit 1 - fi - - echo "Info.plist version: $PLIST_VERSION" - - # Compare versions - if [ "$BRANCH_VERSION" != "$PLIST_VERSION" ]; then - echo "Error: Version mismatch!" - echo " Branch version: $BRANCH_VERSION" - echo " Info.plist version: $PLIST_VERSION" - echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist" - exit 1 - fi - - echo "✓ Version validation passed: $BRANCH_VERSION" - else - echo "Error: Branch name does not match dev/x.x.x format!" - echo "Current branch: $BRANCH_NAME" - echo "Required format: dev/x.x.x (e.g., dev/4.6.2)" - exit 1 - fi -fi - -echo "Version validation completed" -echo "-----------------------------------" - - cd ${PROJECT_PATH} && pod install || exit 1 diff --git a/iOS/APIExample/cloud_build.sh b/iOS/APIExample/cloud_build.sh index 243fed4f3..e2bb82ad6 100755 --- a/iOS/APIExample/cloud_build.sh +++ b/iOS/APIExample/cloud_build.sh @@ -41,8 +41,12 @@ fi # Remove origin/ prefix if present (but keep the rest of the path) BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" +if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ] || [ "$BRANCH_NAME" = "main" ]; then + if [ "$BRANCH_NAME" = "main" ]; then + echo "Branch is main, skipping version validation (main branch is trusted)" + else + echo "Warning: Unable to get Git branch name, skipping version validation" + fi else echo "Current branch: $BRANCH_NAME" diff --git a/iOS/APIExample/cloud_project.sh b/iOS/APIExample/cloud_project.sh index 0f330026c..5a666e417 100755 --- a/iOS/APIExample/cloud_project.sh +++ b/iOS/APIExample/cloud_project.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash PROJECT_PATH=$PWD @@ -9,85 +9,6 @@ if [ "$BUILD_NUMBER" = "" ]; then BUILD_NUMBER=888 fi -# Version validation logic -echo "Starting branch version validation..." - -# Get current branch name (try multiple methods for CI environments) -BRANCH_NAME="" - -# Method 1: Try environment variable (Jenkins/GitLab CI) -if [ ! -z "$GIT_BRANCH" ]; then - BRANCH_NAME="$GIT_BRANCH" - echo "Branch from GIT_BRANCH: $BRANCH_NAME" -elif [ ! -z "$BRANCH_NAME" ]; then - echo "Branch from BRANCH_NAME: $BRANCH_NAME" -elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then - BRANCH_NAME="$CI_COMMIT_REF_NAME" - echo "Branch from CI_COMMIT_REF_NAME: $BRANCH_NAME" -# Method 2: Try git command -elif [ -z "$BRANCH_NAME" ]; then - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) - if [ "$BRANCH_NAME" = "HEAD" ]; then - # In detached HEAD state, try to get branch from remote - BRANCH_NAME=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///') - echo "Branch from git branch -r: $BRANCH_NAME" - else - echo "Branch from git rev-parse: $BRANCH_NAME" - fi -fi - -# Remove origin/ prefix if present (but keep the rest of the path) -BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') - -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" -else - echo "Current branch: $BRANCH_NAME" - - # Extract version from branch name (format: dev/x.x.x) - if [[ $BRANCH_NAME =~ ^dev/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then - BRANCH_VERSION="${BASH_REMATCH[1]}" - echo "Branch version: $BRANCH_VERSION" - - # Read MARKETING_VERSION from project.pbxproj - PBXPROJ_FILE="${PROJECT_PATH}/APIExample.xcodeproj/project.pbxproj" - if [ ! -f "$PBXPROJ_FILE" ]; then - echo "Error: project.pbxproj file not found: $PBXPROJ_FILE" - exit 1 - fi - - # Extract MARKETING_VERSION for main target (skip Extension targets) - # Look for the version that appears with @executable_path/Frameworks (main app) - PLIST_VERSION=$(grep -A 2 "@executable_path/Frameworks" "$PBXPROJ_FILE" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ') - - if [ -z "$PLIST_VERSION" ]; then - echo "Error: Unable to read MARKETING_VERSION from project.pbxproj" - exit 1 - fi - - echo "Info.plist version: $PLIST_VERSION" - - # Compare versions - if [ "$BRANCH_VERSION" != "$PLIST_VERSION" ]; then - echo "Error: Version mismatch!" - echo " Branch version: $BRANCH_VERSION" - echo " Info.plist version: $PLIST_VERSION" - echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist" - exit 1 - fi - - echo "✓ Version validation passed: $BRANCH_VERSION" - else - echo "Error: Branch name does not match dev/x.x.x format!" - echo "Current branch: $BRANCH_NAME" - echo "Required format: dev/x.x.x (e.g., dev/4.6.2)" - exit 1 - fi -fi - -echo "Version validation completed" -echo "-----------------------------------" - #下载美颜资源 echo "start download bytedance resource : $bytedance_lib" curl -L -O "$bytedance_lib" diff --git a/macOS/APIExample.xcodeproj/project.pbxproj b/macOS/APIExample.xcodeproj/project.pbxproj index 0454b17ea..9f4810d95 100644 --- a/macOS/APIExample.xcodeproj/project.pbxproj +++ b/macOS/APIExample.xcodeproj/project.pbxproj @@ -1823,7 +1823,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 4.5.3; + MARKETING_VERSION = 4.6.2; PRODUCT_BUNDLE_IDENTIFIER = io.agora.api.examples; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1855,7 +1855,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 4.5.3; + MARKETING_VERSION = 4.6.2; PRODUCT_BUNDLE_IDENTIFIER = io.agora.api.examples; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/macOS/cloud_build.sh b/macOS/cloud_build.sh index a79372a7f..56d25f95f 100755 --- a/macOS/cloud_build.sh +++ b/macOS/cloud_build.sh @@ -41,8 +41,12 @@ fi # Remove origin/ prefix if present (but keep the rest of the path) BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" +if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ] || [ "$BRANCH_NAME" = "main" ]; then + if [ "$BRANCH_NAME" = "main" ]; then + echo "Branch is main, skipping version validation (main branch is trusted)" + else + echo "Warning: Unable to get Git branch name, skipping version validation" + fi else echo "Current branch: $BRANCH_NAME" diff --git a/macOS/cloud_project.sh b/macOS/cloud_project.sh index 8c78505ed..8b42c6d71 100755 --- a/macOS/cloud_project.sh +++ b/macOS/cloud_project.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash PROJECT_PATH=$PWD @@ -9,85 +9,5 @@ if [ "$BUILD_NUMBER" = "" ]; then BUILD_NUMBER=888 fi -# Version validation logic -echo "Starting branch version validation..." - -# Get current branch name (try multiple methods for CI environments) -BRANCH_NAME="" - -# Method 1: Try environment variable (Jenkins/GitLab CI) -if [ ! -z "$GIT_BRANCH" ]; then - BRANCH_NAME="$GIT_BRANCH" - echo "Branch from GIT_BRANCH: $BRANCH_NAME" -elif [ ! -z "$BRANCH_NAME" ]; then - echo "Branch from BRANCH_NAME: $BRANCH_NAME" -elif [ ! -z "$CI_COMMIT_REF_NAME" ]; then - BRANCH_NAME="$CI_COMMIT_REF_NAME" - echo "Branch from CI_COMMIT_REF_NAME: $BRANCH_NAME" -# Method 2: Try git command -elif [ -z "$BRANCH_NAME" ]; then - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) - if [ "$BRANCH_NAME" = "HEAD" ]; then - # In detached HEAD state, try to get branch from remote - BRANCH_NAME=$(git branch -r --contains HEAD | grep -v HEAD | head -1 | sed 's/^[[:space:]]*origin\///') - echo "Branch from git branch -r: $BRANCH_NAME" - else - echo "Branch from git rev-parse: $BRANCH_NAME" - fi -fi - -# Remove origin/ prefix if present (but keep the rest of the path) -BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/^origin\///') - -if [ -z "$BRANCH_NAME" ] || [ "$BRANCH_NAME" = "HEAD" ]; then - echo "Warning: Unable to get Git branch name, skipping version validation" -else - echo "Current branch: $BRANCH_NAME" - - # Extract version from branch name (format: dev/x.x.x) - if [[ $BRANCH_NAME =~ ^dev/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then - BRANCH_VERSION="${BASH_REMATCH[1]}" - echo "Branch version: $BRANCH_VERSION" - - # Read MARKETING_VERSION from project.pbxproj - PBXPROJ_FILE="${PROJECT_PATH}/APIExample.xcodeproj/project.pbxproj" - if [ ! -f "$PBXPROJ_FILE" ]; then - echo "Error: project.pbxproj file not found: $PBXPROJ_FILE" - exit 1 - fi - - # Extract MARKETING_VERSION for main target (skip Extension targets) - # Look for the version that appears with @executable_path/../Frameworks (main app) - PLIST_VERSION=$(grep -A 2 "@executable_path/../Frameworks" "$PBXPROJ_FILE" | grep "MARKETING_VERSION" | head -1 | sed 's/.*MARKETING_VERSION = \([^;]*\);/\1/' | tr -d ' ') - - if [ -z "$PLIST_VERSION" ]; then - echo "Error: Unable to read MARKETING_VERSION from project.pbxproj" - exit 1 - fi - - echo "Info.plist version: $PLIST_VERSION" - - # Compare versions - if [ "$BRANCH_VERSION" != "$PLIST_VERSION" ]; then - echo "Error: Version mismatch!" - echo " Branch version: $BRANCH_VERSION" - echo " Info.plist version: $PLIST_VERSION" - echo "Please ensure the version in branch name matches MARKETING_VERSION in Info.plist" - exit 1 - fi - - echo "✓ Version validation passed: $BRANCH_VERSION" - else - echo "Error: Branch name does not match dev/x.x.x format!" - echo "Current branch: $BRANCH_NAME" - echo "Required format: dev/x.x.x (e.g., dev/4.6.2)" - exit 1 - fi -fi - -echo "Version validation completed" -echo "-----------------------------------" - - -cd ${PROJECT_PATH} && pod install || exit 1 +cd "${PROJECT_PATH}" && pod install || exit 1