diff --git a/android/build.sh b/android/build.sh index 8e672739..29c3f686 100755 --- a/android/build.sh +++ b/android/build.sh @@ -12,19 +12,23 @@ 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_apk flavor:xhj --verbose + bundle exec fastlane release_apk 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_apk flavor:xhj --verbose + bundle exec fastlane release_apk flavor:sky --verbose + bundle exec fastlane release_bundle flavor:xhj --verbose + bundle exec fastlane release_bundle flavor:sky --verbose elif [[ "${ENV_BUILD_BRANCH}" == "develop" ]]; then echo "===build dev===${NEXT_VERSION}" bundle exec fastlane beta flavor:xhj env:dev --verbose 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 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 fi exit 0 \ No newline at end of file diff --git a/android/fastlane/Fastfile b/android/fastlane/Fastfile index 3930650f..de33726d 100644 --- a/android/fastlane/Fastfile +++ b/android/fastlane/Fastfile @@ -82,7 +82,7 @@ platform :android do end desc "Build & upload a new version to Gitlab Release" - lane :release do |options| + lane :release_apk do |options| flavor = options[:flavor] UI.user_error!("flavor is required") unless flavor print_log "build flavor for: #{flavor}" @@ -93,19 +93,37 @@ 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") Dir.chdir "../.." do - 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","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}") 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") File.rename(old_apk_file_path, new_apk_file_path) + end + + 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") Dir.chdir "../.." do - 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","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}") 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| @@ -122,4 +140,42 @@ platform :android do File.delete(file) 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 = 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, regexp_List) + content = File.read(file_path) + regexp_List.each do |tag| + content = content.gsub(tag) + end + File.write(file_path, content) + UI.message("Processed file: #{file_path},content : #{content}") + end + + pathList.each do |path| + realPath = File.join($path_dir_build, path) + if File.directory?(realPath) + Dir.glob("#{realPath}/**/*").each do |file| + if extensions.include?(File.extname(file)) + process_file(file) + end + end + elsif File.file?(realPath) + process_file(realPath) + else + UI.message("Invalid path: #{realPath}") + end + end + UI.success("All matching content removed from specified files.") + end end