187 lines
7.3 KiB
Ruby
187 lines
7.3 KiB
Ruby
# This file contains the fastlane.tools configuration
|
|
# You can find the documentation at https://docs.fastlane.tools
|
|
#
|
|
# For a list of all available actions, check out
|
|
#
|
|
# https://docs.fastlane.tools/actions
|
|
#
|
|
# For a list of all available plugins, check out
|
|
#
|
|
# https://docs.fastlane.tools/plugins/available-plugins
|
|
#
|
|
|
|
# Uncomment the line if you want fastlane to automatically update itself
|
|
# update_fastlane
|
|
|
|
default_platform(:android)
|
|
|
|
$env_key_project_root = 'ENV_BUILD_WORKSPACE'
|
|
$env_current_branch = 'ENV_BUILD_BRANCH'
|
|
$env_current_tag = 'ENV_BUILD_TAG'
|
|
$env_next_version = 'NEXT_VERSION'
|
|
|
|
$path_dir_build = File.join(ENV[$env_key_project_root],'')
|
|
$current_branch = ENV[$env_current_branch]
|
|
$current_tag = ENV[$env_current_tag]
|
|
$next_version = ENV[$env_next_version]
|
|
|
|
$path_apk_output_dir = File.join($path_dir_build, 'build/app/outputs/flutter-apk')
|
|
$path_bundle_output_dir = File.join($path_dir_build, 'build/app/outputs/bundle')
|
|
|
|
|
|
def print_header header
|
|
UI.message "~~~~~~~~~~~~~~~~~~~~~~"
|
|
UI.message '📍 ' + header.to_s
|
|
UI.message "~~~~~~~~~~~~~~~~~~~~~~"
|
|
end
|
|
|
|
def print_log(content)
|
|
UI.message '📠 ' + content.to_s
|
|
end
|
|
|
|
platform :android do
|
|
before_all do
|
|
print_header '🏁 Before All'
|
|
print_log $current_branch
|
|
print_log $current_tag
|
|
print_log $path_file_preview_apk_default
|
|
print_log $path_file_release_apk_default
|
|
print_log $path_file_preview_apk_copy
|
|
print_log $path_file_release_apk_copy
|
|
Dir.chdir "../.." do
|
|
sh('pwd')
|
|
end
|
|
end
|
|
|
|
desc "Submit a new Beta Build to Pgy Beta"
|
|
lane :beta do |options|
|
|
flavor = options[:flavor]
|
|
env = options[:env]
|
|
UI.user_error!("flavor is required") unless flavor
|
|
UI.user_error!("env is required") unless env
|
|
print_log "build #{flavor} on #{env}"
|
|
build_number = Time.now.strftime("%Y%m%d%H")
|
|
print_log "BuildNo #{build_number}"
|
|
build_version = $next_version
|
|
print_log "build_version #{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:"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")
|
|
new_file_path = File.join($path_apk_output_dir, "starlock-#{flavor}-preview-#{build_version}.apk")
|
|
File.rename(old_file_path, new_file_path)
|
|
logs = changelog_from_git_commits(
|
|
pretty: '- %s (%cn)',
|
|
commits_count: 5,
|
|
merge_commit_filtering: 'exclude_merges'
|
|
)
|
|
upload_file_to_pgy(directory:$path_apk_output_dir,file_extension:".apk",logs:logs)
|
|
end
|
|
|
|
desc "Build & upload a new version to Gitlab Release"
|
|
lane :release_apk 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:"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}")
|
|
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")
|
|
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}")
|
|
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)
|
|
end
|
|
|
|
lane :upload_file_to_pgy do |options|
|
|
directory = options[:directory]
|
|
file_extension = options[:file_extension]
|
|
logs = options[:logs]
|
|
UI.user_error!("Directory path is required") unless directory
|
|
UI.user_error!("File extension is required") unless file_extension
|
|
# 使用Dir.glob来查找目录下的所有.apk和.ipa文件
|
|
Dir.glob("#{directory}/*#{file_extension}").each do |file|
|
|
# 打印文件名称
|
|
puts "start upload file: #{file}"
|
|
pgyer(api_key: ENV['PGY_API_KEY'],apk:file,update_description: logs)
|
|
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","/android/app/build.gradle","/lib/apm"]
|
|
extensions = [".dart",".gradle"] #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
|