feat: 支持android ios不同环境制品包构建

This commit is contained in:
liuyanfeng 2024-10-09 23:13:50 +08:00
parent 1b1c481961
commit d0290d946e
4 changed files with 253 additions and 6 deletions

25
android/build.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
set -e
echo "Build Params Info:Build Dir:$CI_PROJECT_DIR,Build Tag:$CI_COMMIT_TAG,Build Branch:$CI_COMMIT_BRANCH,Build BUILD_REVISION:$CI_RUNNER_REVISION"
export ENV_BUILD_TAG=${CI_COMMIT_TAG}
export ENV_BUILD_BRANCH=${CI_COMMIT_BRANCH}
export ENV_BUILD_WORKSPACE=${CI_PROJECT_DIR}
echo "GITLAB_WORKSPACE: ${CI_PROJECT_DIR}"
cd ${CI_PROJECT_DIR}/android
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_TAG =~ $regex ]]; then
echo "===Building xhj release==="
bundle exec fastlane release flavor:xhj --verbose
bundle exec fastlane release flavor:sky --verbose
elif [[ "${ENV_BUILD_BRANCH}" == "develop" ]]; then
echo "===Building xhj dev==="
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 "===Building xhj pre==="
bundle exec fastlane beta flavor:xhj env:pre --verbose
bundle exec fastlane beta flavor:sky env:pre --verbose
fi
exit 0

View File

@ -88,10 +88,7 @@ platform :android do
short_hash = commit_hash[:abbreviated_commit_hash]
print_log "last_git_commit_short_hash #{short_hash}"
Dir.chdir "../.." do
# sh("sed", "-i", "s/1.0.0+1/#{appSdkVersion}/g", "pubspec.yaml")
# sh("sed", "-i", "s/upload_source_maps: true/upload_source_maps: false/g", "pubspec.yaml")
sh("flutter", "build", "apk", "--no-tree-shake-icons", "--release", "--flavor", "#{flavor}", "-t", "lib/main_#{flavor}.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
#sh('cp',$path_file_release_apk_default,$path_file_release_apk_copy)
end
end

26
ios/build.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
echo "Build Params Info:Build Dir:$CI_PROJECT_DIR,Build Tag:$CI_COMMIT_TAG,Build Branch:$CI_COMMIT_BRANCH,Build BUILD_REVISION:$CI_RUNNER_REVISION"
export ENV_BUILD_TAG=${CI_COMMIT_TAG}
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
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_TAG =~ $regex ]]; then
echo "===Building xhj release==="
bundle exec fastlane release flavor:xhj --verbose
bundle exec fastlane release flavor:sky --verbose
elif [[ "${ENV_BUILD_BRANCH}" == "develop" ]]; then
echo "===Building xhj dev==="
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 "===Building xhj pre==="
bundle exec fastlane beta flavor:xhj env:pre --verbose
bundle exec fastlane beta flavor:sky env:pre --verbose
fi
exit 0

View File

@ -15,9 +15,208 @@
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'
$path_dir_build = File.join(ENV[$env_key_project_root], '')
$current_branch = ENV[$env_current_branch]
$current_tag = ENV[$env_current_tag]
$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
desc "Description of what the lane does"
lane :custom_lane do
# add actions here: https://docs.fastlane.tools/actions
before_all do
print_header '🏁 Before All'
print_log $current_branch
print_log $current_tag
Dir.chdir "../.." do
sh('pwd')
end
end
desc "Build & Deliver to Pgy"
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 "Build Commits #{build_number}"
build_version = '1.0.0'; # Time.now.strftime("%Y%m%d%H%M%S")
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", "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
#set_bundle_short_version('./Runner/Info.plist', $current_branch)
gym_scheme_preview="#{flavor}"
print_log "gym_scheme_preview #{gym_scheme_preview}"
gym_configuration = "#{env}-release-#{flavor}"
print_log "gym_configuration #{gym_configuration}"
ipa_default_filename = "app-starlock-preview-#{flavor}.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.xhjcn.lock.dev" => "Adhoc_com.xhjcn.lock.dev.mobileprovision",
"com.xhjcn.lock.pre" => "Adhoc_com.xhjcn.lock.pre.mobileprovision",
"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 do |options|
flavor = options[:flavor]
UI.user_error!("flavor is required") unless flavor
print_log "build flavor: #{flavor}"
build_number = Time.now.strftime("%Y%m%d%H")
print_log "Build Commits #{build_number}"
build_version = $current_tag.match(/^v(\d+\.\d+\.\d+)/).captures[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", "ios", "--no-tree-shake-icons", "--no-codesign", "--release", "--flavor", "#{flavor}", "-t", "lib/main_#{flavor}.dart", "--build-number=#{build_number}", "--build-name=#{build_version}")
end
gym_scheme_release="#{flavor}"
print_log "gym_scheme_release #{gym_scheme_release}"
gym_configuration = "Release-#{flavor}"
print_log "gym_configuration #{gym_configuration}"
ipa_default_filename = "app-starlock-release-#{flavor}.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.xhjcn.lock" => "Appstore_com.xhjcn.lock.mobileprovision",
"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'],apk:file,update_description: logs)
File.delete(file)
end
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