303 lines
10 KiB
Ruby
303 lines
10 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(:ios)
|
||
|
||
# setup_travis
|
||
|
||
# --- xhj Const ---
|
||
$signing_identity_xhj_distribution = 'iPhone Distribution: Shenzhen Xinhongjia Electronics Co., Ltd. (P8997RW3V8)'
|
||
$app_identifier = 'xhj'
|
||
$provisioning_name_adhoc = 'StarApt Project Mobile Ad Hoc'
|
||
$provisioning_name_distribution = 'StarApt Project Mobile Distribution'
|
||
$gym_config_sky_preview = 'Preview-xhj'
|
||
$gym_config_sky_release = 'Release'
|
||
|
||
# --- sky Const ---
|
||
$signing_identity_sky_distribution = 'iPhone Distribution: Shenzhen Xinhongjia Electronics Co., Ltd. (P8997RW3V8)'
|
||
$app_identifier = 'sky'
|
||
$provisioning_name_adhoc = 'StarApt Project Mobile Ad Hoc'
|
||
$provisioning_name_distribution = 'StarApt Project Mobile Distribution'
|
||
$gym_config_sky_preview = 'Preview-sky'
|
||
$gym_config_sky_release = 'Release'
|
||
|
||
|
||
# --- common Const ---
|
||
$match_type_adhoc = 'adhoc'
|
||
$match_type_appstore = 'appstore'
|
||
$gym_scheme = 'Runner'
|
||
$gym_workspace = 'Runner.xcworkspace'
|
||
|
||
|
||
$env_key_project_root = 'ENV_BUILD_WORKSPACE'
|
||
$env_current_branch = 'ENV_BUILD_BRANCH'
|
||
$env_current_tag = 'ENV_BUILD_TAG'
|
||
$env_key_fastlane_apple_auth_key = 'APPLE_AUTH_CONTENT'
|
||
$env_key_fastlane_apple_auth_issuer_key = 'APPLE_AUTH_ISSUER_ID'
|
||
$env_key_fastlane_apple_auth_id_key = 'APPLE_AUTH_KEY_ID'
|
||
$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]
|
||
|
||
$filename_ipa_default = 'app-starlock.ipa'
|
||
$filename_beta_ipa_copy = 'app-starlock-'+$current_branch+'.ipa'
|
||
$filename_release_ipa_copy = 'app-starlock-'+$current_tag+'.ipa'
|
||
|
||
$path_ipa_output_dir = File.join($path_dir_build, 'build/app/outputs/flutter-ipa')
|
||
# --- Lanes ---
|
||
platform :ios do
|
||
before_all do
|
||
print_header '🏁 Before All'
|
||
print_log $current_branch
|
||
print_log $current_tag
|
||
Dir.chdir "../.." do
|
||
sh('pwd')
|
||
end
|
||
# RubyGems/bundle环境相关日志
|
||
sh('which ruby')
|
||
sh('ruby -v')
|
||
sh('which gem')
|
||
sh('gem -v')
|
||
sh('gem sources -l')
|
||
sh('which bundle')
|
||
sh('bundle -v')
|
||
sh('bundle config')
|
||
sh('env | grep GEM || true')
|
||
sh('env | grep BUNDLE || true')
|
||
sh('env | grep CI_ || true')
|
||
end
|
||
|
||
desc "Build & Deliver to Pgy"
|
||
lane :beta do |options|
|
||
env = options[:env]
|
||
flavor = 'sky'
|
||
UI.user_error!("env is required") unless env
|
||
print_log "build sky on #{env}"
|
||
build_number = Time.now.strftime("%Y%m%d%H%M")
|
||
print_log "Build Commits #{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('pwd')
|
||
sh('ls -lh')
|
||
sh('ls -lh build/app/outputs/flutter-ipa/ || true')
|
||
sh("flutter","pub","get")
|
||
end
|
||
Dir.chdir ".." do
|
||
sh("bundle", "exec" ,"pod", "install")
|
||
end
|
||
Dir.chdir "../.." do
|
||
sh('pwd')
|
||
sh('ls -lh')
|
||
sh('ls -lh build/app/outputs/flutter-ipa/ || true')
|
||
sh("flutter", "build", "ios", "--no-tree-shake-icons", "--no-codesign", "--release", "--flavor", "sky", "-t", "lib/main_sky_#{env}.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
|
||
sh('ls -lh build/app/outputs/flutter-ipa/ || true')
|
||
end
|
||
gym_scheme_preview="sky"
|
||
print_log "gym_scheme_preview sky"
|
||
gym_configuration = "#{env}-release-sky"
|
||
print_log "gym_configuration #{gym_configuration}"
|
||
ipa_default_filename = "starlock-sky-preview-#{build_version}.ipa"
|
||
print_log "ipa_default_filename #{ipa_default_filename}"
|
||
gym(
|
||
scheme: gym_scheme_preview,
|
||
workspace: $gym_workspace,
|
||
configuration: gym_configuration,
|
||
output_directory: $path_ipa_output_dir,
|
||
output_name: ipa_default_filename,
|
||
export_method: "ad-hoc",
|
||
export_options: {
|
||
provisioningProfiles: {
|
||
"com.skychip.lock.dev" => "Adhoc_com.skychip.lock.dev.mobileprovision",
|
||
"com.skychip.lock.pre" => "Adhoc_com.skychip.lock.pre.mobileprovision",
|
||
}
|
||
}
|
||
)
|
||
logs = changelog_from_git_commits(
|
||
pretty: '- %s (%cn)',
|
||
commits_count: 5,
|
||
merge_commit_filtering: 'exclude_merges'
|
||
)
|
||
upload_file_to_pgy(directory:$path_ipa_output_dir,file_extension:".ipa",logs:logs)
|
||
end
|
||
|
||
desc "Build & Deliver to App Store Connect"
|
||
lane :release_ipa do |options|
|
||
flavor = 'sky'
|
||
print_log "build flavor: sky"
|
||
build_number = Time.now.strftime("%Y%m%d%H%M")
|
||
print_log "Build Commits #{build_number}"
|
||
m = $current_tag.match(/^(sky_)?v(\d+\.\d+\.\d+)/)
|
||
if m
|
||
build_version = m.captures.last
|
||
else
|
||
UI.user_error!("Tag格式不正确,无法提取版本号: #{$current_tag}")
|
||
end
|
||
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('pwd')
|
||
sh('ls -lh')
|
||
sh('ls -lh build/app/outputs/flutter-ipa/ || true')
|
||
sh("flutter","pub","get")
|
||
end
|
||
Dir.chdir ".." do
|
||
sh("bundle", "exec" ,"pod", "install")
|
||
end
|
||
Dir.chdir "../.." do
|
||
sh('pwd')
|
||
sh('ls -lh')
|
||
sh('ls -lh build/app/outputs/flutter-ipa/ || true')
|
||
sh("flutter", "build", "ios", "--no-tree-shake-icons", "--no-codesign", "--release", "--flavor", "sky", "-t", "lib/main_sky_lite.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
|
||
sh('ls -lh build/app/outputs/flutter-ipa/ || true')
|
||
end
|
||
gym_scheme_release="sky"
|
||
print_log "gym_scheme_release sky"
|
||
gym_configuration = "Release-sky"
|
||
print_log "gym_configuration #{gym_configuration}"
|
||
ipa_default_filename = "starlock-sky-release-"+$current_tag+".ipa"
|
||
print_log "ipa_default_filename #{ipa_default_filename}"
|
||
gym(
|
||
scheme: gym_scheme_release,
|
||
workspace: $gym_workspace,
|
||
configuration: gym_configuration,
|
||
output_directory: $path_ipa_output_dir,
|
||
output_name: ipa_default_filename,
|
||
export_method: "app-store",
|
||
export_options: {
|
||
provisioningProfiles: {
|
||
"com.skychip.lock" => "Appstore_com.skychip.lock.mobileprovision",
|
||
}
|
||
}
|
||
)
|
||
auth_key_prefix=flavor.upcase
|
||
print_log "auth_key_prefix #{auth_key_prefix}"
|
||
api_key = app_store_connect_api_key(
|
||
key_id: ENV["#{auth_key_prefix}_APPLE_AUTH_KEY_ID"],
|
||
issuer_id: ENV["#{auth_key_prefix}_APPLE_AUTH_ISSUER_ID"],
|
||
key_content: ENV["#{auth_key_prefix}_APPLE_AUTH_CONTENT"],
|
||
is_key_content_base64: true,
|
||
duration: 1200,
|
||
in_house: false
|
||
)
|
||
print_log "api_key #{api_key}"
|
||
ipa_file_path = File.join($path_ipa_output_dir, ipa_default_filename)
|
||
pilot(
|
||
api_key: api_key,
|
||
ipa: ipa_file_path,
|
||
skip_submission: true,
|
||
skip_waiting_for_build_processing: true
|
||
)
|
||
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'],ipa: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","/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
|
||
|
||
|
||
|
||
# --- Prints ---
|
||
def print_title_log(title, content)
|
||
UI.message '📠 ' + title.to_s + ':'
|
||
print_log content
|
||
end
|
||
|
||
def print_log(content)
|
||
UI.message '📠 ' + content.to_s
|
||
end
|
||
|
||
def print_dir(path)
|
||
UI.message '📂📂📂 Print Dir 📂📂📂'
|
||
Dir.chdir(path) do
|
||
sh('ls -lh')
|
||
end
|
||
end
|
||
|
||
def print_header header
|
||
UI.message "~~~~~~~~~~~~~~~~~~~~~~"
|
||
UI.message '📍 ' + header.to_s
|
||
UI.message "~~~~~~~~~~~~~~~~~~~~~~"
|
||
end
|
||
|
||
# --- Methods ---
|
||
def set_bundle_short_version(plist_path, version_string)
|
||
print_header "Set Bundle short version"
|
||
print_log plist_path
|
||
print_log version_string
|
||
set_info_plist_value(path: plist_path, key: 'CFBundleShortVersionString', value: version_string)
|
||
end |