# 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 # --- sky Const --- $signing_identity_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_preview = 'Preview-sky' $gym_config_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 end desc "Build & Deliver to Pgy" lane :beta do |options| env = options[:env] 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("flutter","clean") sh("flutter","pub","get") end Dir.chdir ".." do sh("pod", "install") end Dir.chdir "../.." do 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}") end gym_scheme_preview="sky" print_log "gym_scheme_preview #{gym_scheme_preview}" 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", xcargs: "GCC_PREPROCESSOR_DEFINITIONS='USE_CALLKIT=1 $(inherited)'", 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| print_log "build sky" build_number = Time.now.strftime("%Y%m%d%H%M") 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}" remove_zone_pre_build(zone:"com") Dir.chdir "../.." do sh("flutter","pub","get") end Dir.chdir ".." do sh("pod", "install") end Dir.chdir "../.." do 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}") end gym_scheme_release="sky" print_log "gym_scheme_release #{gym_scheme_release}" 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", xcargs: "GCC_PREPROCESSOR_DEFINITIONS='USE_CALLKIT=1 $(inherited)'", export_options: { provisioningProfiles: { "com.skychip.lock" => "Appstore_com.skychip.lock.mobileprovision" } } ) auth_key_prefix="SKY" 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