116 lines
4.2 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'
$path_dir_build = File.join(ENV[$env_key_project_root],'')
$current_branch = ENV[$env_current_branch]
$current_tag = ENV[$env_current_tag]
$path_apk_output_dir = File.join($path_dir_build, 'build/app/outputs/flutter-apk')
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 = '1.0.0'
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}"
Dir.chdir "../.." do
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}-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 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}"
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}")
end
old_file_path = File.join($path_apk_output_dir, "app-#{flavor}-release.apk")
new_file_path = File.join($path_apk_output_dir, "starlock-#{flavor}-release-"+$current_tag+".apk")
File.rename(old_file_path, new_file_path)
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
end