ci: cn、com区域打包逻辑分离。

This commit is contained in:
Liuyf 2025-01-11 16:05:41 +08:00
parent 037588926f
commit 2b80a68d11
5 changed files with 86 additions and 31 deletions

View File

@ -62,7 +62,7 @@ variables:
before_script:
- ls -li
- export NEXT_VERSION="$(cat app_new.version)"
- flutter pub get
# - flutter pub get
- bundle install --gemfile android/Gemfile --quiet
cache:
paths:
@ -73,7 +73,7 @@ variables:
before_script:
- ls -li
- export NEXT_VERSION="$(cat app_new.version)"
- flutter pub get
# - flutter pub get
- bundle install --gemfile ios/Gemfile --quiet
cache:
paths:

View File

@ -26,9 +26,7 @@ elif [[ "${ENV_BUILD_BRANCH}" == "develop" ]]; then
bundle exec fastlane beta flavor:sky env:dev --verbose
elif [[ "${ENV_BUILD_BRANCH}" == "release" ]] || [[ "${ENV_BUILD_BRANCH}" == "feat_devops" ]] ; then
echo "===build pre===${NEXT_VERSION}"
# bundle exec fastlane beta flavor:xhj env:pre --verbose
# bundle exec fastlane beta flavor:sky env:pre --verbose
bundle exec fastlane release_bundle flavor:xhj --verbose
bundle exec fastlane release_bundle flavor:sky --verbose
bundle exec fastlane beta flavor:xhj env:pre --verbose
bundle exec fastlane beta flavor:sky env:pre --verbose
fi
exit 0

View File

@ -67,7 +67,9 @@ platform :android do
commit_hash = last_git_commit
short_hash = commit_hash[:abbreviated_commit_hash]
print_log "last_git_commit_short_hash #{short_hash}"
remove_zone_pre_build(zone:"com")
Dir.chdir "../.." do
sh("flutter","pub","get")
sh("flutter", "build", "apk", "--no-tree-shake-icons", "--release", "--flavor", "#{flavor}_#{env}", "-t", "lib/main_#{flavor}_#{env}.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
end
old_file_path = File.join($path_apk_output_dir, "app-#{flavor}_#{env}-release.apk")
@ -93,10 +95,10 @@ platform :android do
commit_hash = last_git_commit
short_hash = commit_hash[:abbreviated_commit_hash]
print_log "last_git_commit_short_hash #{short_hash}"
remove_zone_pre_build(zone:"com",extensions:".dart")
remove_zone_pre_build(zone:"com")
Dir.chdir "../.." do
sh("flutter","pub","get")
#sh("flutter", "build", "apk", "--no-tree-shake-icons", "--release", "--flavor", "#{flavor}", "-t", "lib/main_#{flavor}_lite.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
sh("flutter", "build", "apk", "--no-tree-shake-icons", "--release", "--flavor", "#{flavor}", "-t", "lib/main_#{flavor}_lite.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
end
old_apk_file_path = File.join($path_apk_output_dir, "app-#{flavor}-release.apk")
new_apk_file_path = File.join($path_apk_output_dir, "starlock-#{flavor}-release-"+$current_tag+".apk")
@ -105,25 +107,25 @@ platform :android do
desc "Build & upload a new version to Gitlab Release"
lane :release_bundle do |options|
# flavor = options[:flavor]
# UI.user_error!("flavor is required") unless flavor
# print_log "build flavor for: #{flavor}"
# build_number = Time.now.strftime("%Y%m%d%H")
# print_log "BuildNo #{build_number}"
# build_version = $current_tag.match(/^v(\d+\.\d+\.\d+)/).captures[0]
# print_log "buildVersion #{build_version}"
# commit_hash = last_git_commit
# short_hash = commit_hash[:abbreviated_commit_hash]
# print_log "last_git_commit_short_hash #{short_hash}"
remove_zone_pre_build(zone:"cn",extensions:".dart")
flavor = options[:flavor]
UI.user_error!("flavor is required") unless flavor
print_log "build flavor for: #{flavor}"
build_number = Time.now.strftime("%Y%m%d%H")
print_log "BuildNo #{build_number}"
build_version = $current_tag.match(/^v(\d+\.\d+\.\d+)/).captures[0]
print_log "buildVersion #{build_version}"
commit_hash = last_git_commit
short_hash = commit_hash[:abbreviated_commit_hash]
print_log "last_git_commit_short_hash #{short_hash}"
remove_zone_pre_build(zone:"cn")
Dir.chdir "../.." do
sh("flutter","pub","get")
#sh("flutter", "build", "appbundle", "--no-tree-shake-icons", "--release", "--flavor", "#{flavor}", "-t", "lib/main_#{flavor}_lite.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
sh("flutter", "build", "appbundle", "--no-tree-shake-icons", "--release", "--flavor", "#{flavor}", "-t", "lib/main_#{flavor}_lite.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
end
# old_bundle_file_path = File.join($path_bundle_output_dir , "/#{flavor}Release/app-#{flavor}-release.aab")
# new_bundle_file_path = File.join($path_bundle_output_dir , "/#{flavor}Release/starlock-#{flavor}-release-"+$current_tag+".aab")
# File.rename(old_bundle_file_path, new_bundle_file_path)
# sh('cp',new_bundle_file_path,$path_apk_output_dir)
old_bundle_file_path = File.join($path_bundle_output_dir , "/#{flavor}Release/app-#{flavor}-release.aab")
new_bundle_file_path = File.join($path_bundle_output_dir , "/#{flavor}Release/starlock-#{flavor}-release-"+$current_tag+".aab")
File.rename(old_bundle_file_path, new_bundle_file_path)
sh('cp',new_bundle_file_path,$path_apk_output_dir)
end
lane :upload_file_to_pgy do |options|
@ -146,7 +148,7 @@ platform :android do
zone = options[:zone]
UI.user_error!("Please provide valid 'zone'") unless zone
pathList=["pubspec.yaml","/lib/apm"]
extensions = options[:extensions] # 文件扩展名数组
extensions = [".dart"] #options[:extensions]
if pathList.empty? || extensions.empty?
UI.user_error!("Please provide valid 'paths' and 'extensions' arrays.")
end
@ -180,4 +182,5 @@ platform :android do
end
UI.success("All matching content removed from specified files.")
end
end

View File

@ -7,18 +7,18 @@ export ENV_BUILD_BRANCH=${CI_COMMIT_BRANCH}
export ENV_BUILD_WORKSPACE=${CI_PROJECT_DIR}
echo "GITLAB_WORKSPACE: ${CI_PROJECT_DIR}"
cd ${CI_PROJECT_DIR}/ios
bundle exec pod install
#bundle exec pod install
echo "ENV_BUILD_TAG:${ENV_BUILD_TAG},ENV_BUILD_BRANCH:${ENV_BUILD_BRANCH}"
regex='^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z]+\.[0-9]+)?$'
if [[ "${ENV_BUILD_BRANCH}" == "canary_release" ]]; then
echo "===build canary_release: ${NEXT_VERSION}"
export ENV_BUILD_TAG=${NEXT_VERSION}
bundle exec fastlane release flavor:xhj --verbose
bundle exec fastlane release flavor:sky --verbose
bundle exec fastlane release_ipa flavor:xhj --verbose
bundle exec fastlane release_ipa flavor:sky --verbose
elif [[ $ENV_BUILD_TAG =~ $regex ]]; then
echo "===build release===$ENV_BUILD_TAG"
bundle exec fastlane release flavor:xhj --verbose
bundle exec fastlane release flavor:sky --verbose
bundle exec fastlane release_ipa flavor:xhj --verbose
bundle exec fastlane release_ipa flavor:sky --verbose
elif [[ "${ENV_BUILD_BRANCH}" == "develop" ]]; then
echo "===build dev===${NEXT_VERSION}"
bundle exec fastlane beta flavor:xhj env:Dev --verbose

View File

@ -84,6 +84,13 @@ platform :ios do
commit_hash = last_git_commit
short_hash = commit_hash[:abbreviated_commit_hash]
print_log "last_git_commit_short_hash #{short_hash}"
remove_zone_pre_build(zone:"com")
Dir.chdir "../.." do
sh("flutter","pub","get")
end
Dir.chdir ".." do
sh("bundle", "exec" ,"pod", "install")
end
Dir.chdir "../.." do
sh("flutter", "build", "ios", "--no-tree-shake-icons", "--no-codesign", "--release", "--flavor", "#{flavor}", "-t", "lib/main_#{flavor}_#{env}.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
end
@ -119,7 +126,7 @@ platform :ios do
end
desc "Build & Deliver to App Store Connect"
lane :release do |options|
lane :release_ipa do |options|
flavor = options[:flavor]
UI.user_error!("flavor is required") unless flavor
print_log "build flavor: #{flavor}"
@ -130,6 +137,13 @@ platform :ios do
commit_hash = last_git_commit
short_hash = commit_hash[:abbreviated_commit_hash]
print_log "last_git_commit_short_hash #{short_hash}"
remove_zone_pre_build(zone:"com")
Dir.chdir "../.." do
sh("flutter","pub","get")
end
Dir.chdir ".." do
sh("bundle", "exec" ,"pod", "install")
end
Dir.chdir "../.." do
sh("flutter", "build", "ios", "--no-tree-shake-icons", "--no-codesign", "--release", "--flavor", "#{flavor}", "-t", "lib/main_#{flavor}_lite.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
end
@ -188,6 +202,46 @@ platform :ios do
end
end
lane :remove_zone_pre_build do |options|
sh("git", "reset", "--hard")
zone = options[:zone]
UI.user_error!("Please provide valid 'zone'") unless zone
pathList=["pubspec.yaml","/lib/apm"]
extensions = [".dart"] #options[:extensions]
if pathList.empty? || extensions.empty?
UI.user_error!("Please provide valid 'paths' and 'extensions' arrays.")
end
puts "start prepare zone: #{zone},pathList:#{pathList},extensions:#{extensions}"
regexp_List = [/#<#{zone}>.*?#<\/#{zone}>/m,/\/\/\<#{zone}\>.*?\/\/\<\/#{zone}\>/m]
UI.message("Processed RegExpList: #{regexp_List}")
def process_file(file_path, regexpList)
content = File.read(file_path)
regexpList.each do |tag|
content = content.gsub(tag,'')
end
File.write(file_path, content)
UI.message("Processed file: #{file_path},content :\n #{content}")
end
pathList.each do |path|
realPath = File.join($path_dir_build, path)
if File.directory?(realPath)
Dir.glob("#{realPath}/**/*").each do |file|
if File.directory?(file)
UI.message("Find child dir path: #{file}")
elsif extensions.include?(File.extname(file))
process_file(file,regexp_List)
end
end
elsif File.file?(realPath)
process_file(realPath,regexp_List)
else
UI.message("Invalid path: #{realPath}")
end
end
UI.success("All matching content removed from specified files.")
end
end