1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
|
fastlane_version "2.28.3"
default_platform :ios
platform :ios do
schemeName = "wanjia2B"
infoPlistDirName = "wanjia"
xcodeprojFile = "#{schemeName}.xcodeproj"
workspaceName = "#{schemeName}.xcworkspace"
basePath = Pathname::new(File::dirname(__FILE__)).realpath.parent
infoPlistFile = "#{basePath}/#{infoPlistDirName}/Info.plist"
pbxprojFilePath = "#{basePath}/#{xcodeprojFile}"
pbxprojFile = "#{pbxprojFilePath}/project.pbxproj"
configFile = "#{basePath}/wanjia/Headers/PAAppConfig.swift"
backupPath = "#{basePath}/.backup_info"
isBackup = false
env = "appstore" displayName = "万家医疗" bundleID = "com.pingan.wanjiaB" debugProfileName="wanjiaBDev" releaseProfileName="wanjiaBDistribution" debugCodeSignIdentity="iPhone Developer: bingyu zhou (ES59BFTTFG)" releaseCodeSignIdentity="iPhone Distribution: PingAn Wanjia Healthcare Investment Management Co., Ltd (6GA5676ZM3)" exportMethod="app-store"
desc "初始化信息" private_lane :setupInfomations do |options| putsB "Begin Get Environment Values" env = String(options[:env] || "appstore") case env when "appstore", "0" env = "appstore" when "adhoc", "1" env = "adhoc" displayName="万家医疗-AdHoc" bundleID="com.pingan.wanjiaB" debugProfileName="wanjiaBDev" releaseProfileName="wanjiaBAdhoc" debugCodeSignIdentity="iPhone Developer: bingyu zhou (ES59BFTTFG)" releaseCodeSignIdentity="iPhone Distribution: PingAn Wanjia Healthcare Investment Management Co., Ltd (6GA5676ZM3)" exportMethod="ad-hoc" when "dev", "2" env = "dev" displayName="万家医疗-开发" bundleID="com.pingan.wanjiaBDev" debugProfileName="wanjiaWildcard" releaseProfileName="wanjiaWildcard" debugCodeSignIdentity="iPhone Developer: bingyu zhou (ES59BFTTFG)" releaseCodeSignIdentity="iPhone Developer: bingyu zhou (ES59BFTTFG)" exportMethod="development" when "test", "3" env = "test" displayName="万家医疗-测试" bundleID="com.pingan.wanjiaBTest" debugProfileName="wanjiaWildcard" releaseProfileName="wanjiaWildcard" debugCodeSignIdentity="iPhone Developer: bingyu zhou (ES59BFTTFG)" releaseCodeSignIdentity="iPhone Developer: bingyu zhou (ES59BFTTFG)" exportMethod="development" else putsE "Error Environment Type" exit 1 end
putsI "\t DisplayName: #{displayName} " putsI "\t BundleID: #{bundleID} " putsI "\t DebugProfileName: #{debugProfileName} " putsI "\t ReleaseProfileName: #{releaseProfileName} " putsI "\t Project Base Path: #{basePath}" putsI "\t Project File: #{pbxprojFilePath} " putsI "\t pbxproj File Path: #{pbxprojFilePath} " putsI "\t Workspace File: #{basePath}/#{workspaceName} " putsI "\t Info.plist File: #{infoPlistFile} " putsI "\t project.pbxproj File: #{pbxprojFile} "
putsS "Success Of Get Environment Values" end
desc "备份信息" private_lane :backupCurrentInfo do putsB "Begin Backup Current Infomation: plist xcodeproj" if File.directory?"#{backupPath}" FileUtils::rm_r backupPath end FileUtils::mkdir backupPath FileUtils::cp_r infoPlistFile, "#{backupPath}/Info.plist.bak" FileUtils::cp_r pbxprojFile, "#{backupPath}/project.pbxproj.bak" FileUtils::cp_r configFile, "#{backupPath}/PAAppConfig.swift.bak" putsS "Success Of Backup Current Infomation" isBackup = true end
desc "删除备份信息" private_lane :removeBackupInfo do putsB "Begin Remove Infomation Folder & File ==> BackupPath: #{backupPath}" if File.directory?"#{backupPath}" FileUtils::rm_r backupPath end putsS "Success Of Remove Infomation Folder & File ==> BackupPath: #{backupPath}" isBackup = false end
desc "修改当前信息" private_lane :changeInfomations do |options|
putsB "Begin Change 'Info.plist' & .pbxproj File ==> Info.plist: #{infoPlistFile} , pbxprojFile: #{pbxprojFile}" update_info_plist( plist_path: "./wanjia/Info.plist", app_identifier: bundleID, display_name: displayName, ) run_rubyFile_script = "ruby 'change_projectpbxproj.rb' '#{pbxprojFilePath}' '#{bundleID}' '#{debugCodeSignIdentity}' '#{debugProfileName}' '#{releaseCodeSignIdentity}' '#{releaseProfileName}'" sh run_rubyFile_script
env = String(options[:env] || "appstore") conf = String(options[:conf] || "debug") isToAppStore = false if (env == "appstore" || env == "0") && conf == "release" isToAppStore = true end change_configFile_script = "sed -i '' 's/^.*static let isToAppStore.*$/ static let isToAppStore = #{isToAppStore}/g' #{configFile}" sh change_configFile_script
putsS "Success Of Change 'Info.plist' & .pbxproj File ==> Info.plist: #{infoPlistFile} , pbxprojFile: #{pbxprojFile}" end
desc "恢复备份信息并删除备份" private_lane :recoverInfoations do putsB "Begin Recover Infomation: plist xcodeproj" FileUtils::cp_r "#{backupPath}/Info.plist.bak", infoPlistFile FileUtils::cp_r "#{backupPath}/project.pbxproj.bak", pbxprojFile FileUtils::cp_r "#{backupPath}/PAAppConfig.swift.bak", configFile putsS "Success Of Recover Infomation"
removeBackupInfo isBackup = false end
desc "输出使用方式" lane :options do puts "\033[32m======================================================================================================================================\033[m" puts "\033[47;30m Environment Configuration: \033[m" puts " It's Need Install: \033[32mXcode & Ruby\033[m, and Install Ruby Library: \033[32mxcodeproj\033[m & \033[32mfastlane\033[m. " puts " How To Install Ruby Library 'xcodeproj' ? " puts " Install Command: \033[35m[sudo] gem install xcodeproj\033[m " puts " Github Link: \033[35mhttps://github.com/CocoaPods/Xcodeproj\033[m " puts " How To Install Ruby Library 'fastlane' ? " puts " Before Install 'fastlane', Make Sure You Have The Latest Version Of The Xcode Command Line Tools Installed: " puts " Xcode Command Line Install Command: \033[35mxcode-select --install\033[m " puts " Then 'fastlane' Install Command: \033[35msudo gem install fastlane -NV\033[m " puts " 'fastlane' Github Link: \033[35mhttps://github.com/fastlane/fastlane\033[m " puts "\033[32m--------------------------------------------------------------------------------------------------------------------------------------\033[m" puts "\033[47;30m Parameter Instructions: \033[m" puts " \033[32m options \033[m" puts " Show how to use this script. " puts " eg: fastlane options " puts " \033[32m setinfo env:'env' conf:'configuration' \033[m" puts " 'env'can use 'appstore/adhoc/dev/test' or '0/1/2/3', default is 'appstore'; If input error, env is 'appstore'." puts " 'configuration' can use 'debug' or 'release', default is 'debug; If input error, configuration is 'debug'. " puts " Change info to 'env' environment & \033[31mSAVE backup\033[m. In the end, will open Xcode. " puts " eg: fastlane setinfo env:test ; fastlane setinfo " puts " \033[32m recoverinfo \033[m" puts " Just recover infomation from the infomation backup, and then, remove backup folder. In the end, will open Xcode. " puts " eg: fastlane recoverinfo " puts " \033[32m resetinfo env:'env' conf:'configuration' \033[m" puts " 'env' default is 'appstore'. Reset infomation to 'env' environment. In the end, will open Xcode. " puts " 'configuration' can use 'debug' or 'release', default is 'debug; If input error, configuration is 'debug'. " puts " \033[31mDON'T SAVE backup and REMOVE ALL backup folder/file\033[m. " puts " eg: fastlane resetinfo env:dev " puts " \033[32m build \033[m" puts " Just build. " puts " eg: fastlane build " puts " \033[32m archive env:'env' conf:'configuration'\033[m" puts " 'env' default is 'appstore'; " puts " 'configuration' can use 'debug' or 'release', default is 'release'; If input error, configuration is 'release'. " puts " eg: fastlane archive env:appstore conf:release ; fastlane archive env:adhoc; fastlane archive" puts "\033[32m======================================================================================================================================\033[m" end
before_all do
end
desc "设置信息,并保存备份;参数 => env:'env'" lane :setinfo do |options| setupInfomations options backupCurrentInfo changeInfomations options end
desc "恢复备份信息并删除备份" lane :recoverinfo do recoverInfoations end
desc "仅设置信息,并删除现有备份;参数 => env:'env'" lane :resetinfo do |options| setupInfomations options changeInfomations options removeBackupInfo end
desc "编译项目" lane :build do cocoapods xcodebuild( silent: true, clean: true, build: true, workspace: workspaceName, scheme: schemeName, configuration: "Release", destination: "generic/platform=iOS", build_settings: { "CODE_SIGN_IDENTITY" => "", "CODE_SIGNING_REQUIRED" => "NO" }, ) end
desc "打包; 参数 => env:'env' conf:debug/release" lane :archive do |options| env = String(options[:env] || "appstore") conf = String(options[:conf] || "release") if conf == "debug" configuration = "Debug" profileName = debugProfileName codeSignIdentity = debugCodeSignIdentity else configuration = "Release" profileName = releaseProfileName codeSignIdentity = releaseCodeSignIdentity end setinfo env:env, conf:conf
time = Time::new currentTime = time.strftime("%Y-%m-%d/%H_%M_%S") buildPath = "#{basePath}/build/#{schemeName}-#{env}/#{currentTime}" exportPath = "~/Desktop/#{schemeName}-#{env}/#{currentTime}" customName = "#{schemeName}-#{env}-#{configuration}" ipaName = "#{customName}.ipa"
cocoapods
gym( silent: true, clean: true, workspace: workspaceName, scheme: schemeName, configuration: configuration, export_method: exportMethod, build_path: buildPath, output_directory: exportPath, output_name: ipaName, )
recoverinfo
putsS "IPA DIR & NAME IS : ipaDir ==> #{exportPath}, ipaName ==> #{ipaName}, archiveDir ==> #{buildPath}" end
after_all do |lane| end
error do |lane, exception, options| putsE "#{lane} Is Failed: Runing Error, is backup? => #{isBackup}" if "#{lane}" == "build" || "#{lane}" == "archive" end
if isBackup == true recoverInfoations end end
def putsI (option) puts "\033[40;37m#{option}\033[m" end def putsB (option) puts "\033[33m#{option}\033[m" puts "" end def putsS (option) puts "\033[32m#{option}\033[m" puts "" end def putsE (option) puts "\033[41;37m #{option} \033[m" puts "" end end
|