Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/ci/build/build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -135,6 +141,7 @@ fi

echo "✅ All version checks passed!"
echo "=========================================="
fi
echo ""

unzip_name=Shengwang_Native_SDK_for_Android_FULL_DEFAULT
Expand Down
13 changes: 12 additions & 1 deletion .github/ci/build/build_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
13 changes: 12 additions & 1 deletion .github/ci/build/build_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
6 changes: 6 additions & 0 deletions .github/ci/build/build_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%"=="" (
Expand Down
183 changes: 183 additions & 0 deletions .github/ci/build/common_functions.sh
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 6 additions & 2 deletions iOS/APIExample-Audio/cloud_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
81 changes: 1 addition & 80 deletions iOS/APIExample-Audio/cloud_project.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

PROJECT_PATH=$PWD

Expand All @@ -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

8 changes: 6 additions & 2 deletions iOS/APIExample-OC/cloud_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading
Loading