美文网首页
fastlane脚本

fastlane脚本

作者: SmallHer | 来源:发表于2022-12-29 14:04 被阅读0次

fastlane+蒲公英自动化打包(脚本)

# encoding: utf-8
# .ipa文件输出路径
$ipa_output_directory = "/Users/pengfeizhu/Desktop/fastlaneBuild"
# 上传蒲公英的包 路径
$ipa_output_upload_directory = "/Users/pengfeizhu/.jenkins/workspace/SkyMed/ipa"
# jenkins匹配的包名
$jenkins_name = "SkyMed"


default_platform(:ios)

    # 项目的scheme名称
    scheme_name = "SkyMed"
    # 获取version
    version = get_info_plist_value(path: "./#{scheme_name}/Supporting Files/Info.plist", key: "CFBundleShortVersionString")
    # 获取build版本号
    build = get_info_plist_value(path: "./#{scheme_name}/Supporting Files/Info.plist", key: "CFBundleVersion")
    # 指定xcode打包 这里可选择不要,我们的项目需要用10.1版本xcode
    #xcode_select("/Applications/Xcode_10.1.app")
    # 默认内测打包方式,目前支持app-store, package, ad-hoc, enterprise, development
    ipa_exportMethod = "ad-hoc"
    ipa_exportMethod_appStore = "app-store"
    # 项目的内测描述文件名称
    project_ad_provisioningProfiles = "adHoc_skymed"
    # 项目的发布描述文件名称
    project_release_provisioningProfiles = "0926skymed"
    # 项目bunldID
    project_identifier = "com.skymed.internetHospital"
    #pgyer_APIKey蒲公英APIkey
    pgyer_APIKey = "5b4b097bbde7893a3b4e2a071cce79cc"
    #pgyer_UserKey蒲公英Userkey
    pgyer_UserKey = "9df15e1caa6881a4fa9674f38bacf937"

# 计算buildNumber
def updateProjectBuildNumber
    currentTime = Time.new.strftime("%Y%m%d")
    # 项目的内测scheme名称
    project_scheme = "SkyMed"
    # 获取build版本号
    build = get_info_plist_value(path: "./#{project_scheme}/Supporting Files/Info.plist", key: "CFBundleVersion").to_s
    if build.include?"#{currentTime}."
    # => 为当天版本 计算迭代版本号
    lastStr = build[build.length-2..build.length-1]
    lastNum = lastStr.to_i
    lastNum = lastNum + 1
    lastStr = lastNum.to_s
    if lastNum < 10
    lastStr = lastStr.insert(0,"0")
    end
    build = "#{currentTime}.#{lastStr}"
    else
    # => 非当天版本 build 号重置
    build = "#{currentTime}.01"
    end
    puts("*************| 更新build #{build} |*************")
    # => 更改项目 build 号
    increment_build_number(
        build_number: "#{build}"
    )
end
# 打包成功 jenkins 开始提示上传log
# 使用fastlane上传蒲公英拿不到二维码展示, 所以使用jenkins上传蒲公英
# def archiveSuccessLog(outputName,buildConfig)
    # 打好的包 移动到 jenkins的 workspace的目录下,用于jenkins上传蒲公英匹配包内容。永远只保留一份
  #FileUtils.cp_r("#{$ipa_output_directory}" + "/#{outputName}", "#{$ipa_output_upload_directory}" +  "/#{$jenkins_name}.ipa")
#     puts" --------------------------------------------------------------------------"
#     puts"|                                                                          |"
#     puts"|                                                                          |"
#     puts"|   🎉🎉🎉 --------->>>>>      #{buildConfig}版本_打包成功     <<<<<-----------🎉🎉🎉  |"
#     puts"|                                                                          |"
#     puts"|   🎉🎉🎉 --------->>>>>  Jenkins 可以开始上传蒲公英了  <<<<<-----------🎉🎉🎉  |"
#     puts"|                                                                          |"
#     puts"|                                                                          |"
#     puts" --------------------------------------------------------------------------"
# end

platform :ios do

  # 
  # *************| 上传到测试版本到蒲公英_测试包 |*************
  #
  desc "上传到测试版本到蒲公英_测试包"
  lane :topgyer do|option|
    puts "*************| 开始打包.ipa文件... |*************"
    # 自动增加build
    updateProjectBuildNumber
    # 自动生成证书
     cert
    # 导出名称
    #codesigning_identity = "#{project_ad_provisioningProfiles}"
    output_name = "#{scheme_name}_#{version}_#{option[:desc]}_#{Time.now.strftime('%Y%m%d%H%M')}.ipa"
    gym(
        # 指定输出的ipa名称
        output_name: "#{output_name}",
    scheme:"#{scheme_name}",
    # 是否清空以前的编译信息 true:是
        clean: true,
        # 指定打包方式,Release 或者 Debug 按需修改
        configuration:"Test",
        # 包导出的位置
        output_directory:"#{$ipa_output_directory}",
        export_method:"ad-hoc",
        # 隐藏没有必要的信息
        #silent:true,
        # 手动配置证书,注意打包方式需在export_options内使用method设置,不可使用export_method
        #export_options: {
            #method:"#{ipa_exportMethod}",
            #provisioningProfiles: {
                #{}"#{project_identifier}":"#{project_ad_provisioningProfiles}"
            #},
            #iCloudContainerEnvironment: 'Development',
        #},
    )
    # 使用fastlane上传蒲公英拿不到二维码展示, 所以使用jenkins上传蒲公英
    #archiveSuccessLog(output_name," Debug ")
        # 这里是 fastlane 直接上传蒲公英
    # 如果需要请打开一下注释,并注释掉archiveSuccessLog(output_name," Debug ")
     puts "*************| 开始上传__测试版__本到蒲公英... |*************"
    # 配置蒲公英 api_key 和 user_key
     pgyer(api_key: "#{pgyer_APIKey}", user_key: "#{pgyer_UserKey}", update_description: "#{option[:desc]}")
     puts "*************| 上传__测试版__到蒲公英🎉🎉🎉成功🎉🎉🎉 |*************"
  end
  # 
  # *************| 上传到测试版本到蒲公英_测试包 |*************
  #
  desc "上传到生产版本到蒲公英_生产测试包"
  lane :topgyer_release do|option|
    puts "*************| 开始打包.ipa文件... |*************"
    # 自动增加build
    updateProjectBuildNumber
    # 自动生成证书
     cert
    # 导出名称
    #codesigning_identity = "#{project_ad_provisioningProfiles}"
    output_name = "#{scheme_name}_#{version}_#{option[:desc]}_#{Time.now.strftime('%Y%m%d%H%M')}.ipa"
    gym(
        # 指定输出的ipa名称
        output_name: "#{output_name}",
    scheme:"#{scheme_name}",
    # 是否清空以前的编译信息 true:是
        clean: true,
        # 指定打包方式,Release 或者 Debug 按需修改
        configuration:"Release",
        # 包导出的位置
        output_directory:"#{$ipa_output_directory}",
        export_method:"ad-hoc",
        # 隐藏没有必要的信息
        #silent:true,
        # 手动配置证书,注意打包方式需在export_options内使用method设置,不可使用export_method
        #export_options: {
            #method:"#{ipa_exportMethod}",
            #provisioningProfiles: {
                #{}"#{project_identifier}":"#{project_ad_provisioningProfiles}"
            #},
            #iCloudContainerEnvironment: 'Development',
        #},
    )
    # 使用fastlane上传蒲公英拿不到二维码展示, 所以使用jenkins上传蒲公英
    #archiveSuccessLog(output_name," Debug ")
        # 这里是 fastlane 直接上传蒲公英
    # 如果需要请打开一下注释,并注释掉archiveSuccessLog(output_name," Debug ")
     puts "*************| 开始上传__测试版__本到蒲公英... |*************"
    # 配置蒲公英 api_key 和 user_key
     pgyer(api_key: "#{pgyer_APIKey}", user_key: "#{pgyer_UserKey}", update_description: "#{option[:desc]}")
     puts "*************| 上传__测试版__到蒲公英🎉🎉🎉成功🎉🎉🎉 |*************"
  end
  # ----------------------- 上传AppStore -----------------------
    lane :toappstore do|option|

        puts "*************| 开始上传AppStore... |*************"

        # 更新项目build号
        updateProjectBuildNumber
        codesigning_identity = "#{project_release_provisioningProfiles}"
        output_name = "#{scheme_name}_#{version}_#{option[:desc]}_#{ipa_exportMethod_appStore}_#{Time.now.strftime('%Y%m%d%H%M')}.ipa"
        gym(
            # 指定输出的ipa名称
            output_name:output_name,
            # 指定项目的scheme
            scheme:"#{scheme_name}",
            # 是否清空以前的编译信息 true:是
            clean:true,
            # 指定打包方式,Release 或者 Debug
            configuration:"Release",
            # 指定打包方式,目前支持app-store, package, ad-hoc, enterprise, development
            # 注:由于使用手动配置证书,在export_options指定打包方式
            #export_method:"#{app-store}",
            # 指定输出文件夹
            output_directory:"#{$ipa_output_directory}",
            # Xcode9将不会允许你访问钥匙串里的内容,除非设置allowProvisioningUpdates
            #export_xcargs:"-allowProvisioningUpdates",
            # 隐藏没有必要的信息
            #silent:true,
            # 手动配置证书,注意打包方式需在export_options内使用method设置,不可使用export_method
            export_options: {
                method:"app-store",
                provisioningProfiles: {
                    "#{project_identifier}":"#{project_release_provisioningProfiles}"
                },
            }
         )
        deliver(
                # 选择跳过图片和元数据上传,自己去配置
                skip_screenshots:true,
                skip_metadata:true,
                # 上传完成后提交新版本进行审查
                submit_for_review: false,
                # 上传所有信息到App Store
                force:true,
                )
        puts "*************| 上传AppStore成功🎉 |*************"

        # puts "*************| 开始上传__测试版__本到蒲公英... |*************"
        # 配置蒲公英 api_key 和 user_key
        # pgyer(api_key: "#{pgyer_APIKey}", user_key: "#{pgyer_UserKey}", update_description: "#{option[:desc]}")
        # puts "*************| 上传__测试版__到蒲公英🎉🎉🎉成功🎉🎉🎉 |*************"
        #发布testflight测试
        # pilot
    end

end

相关文章

网友评论

      本文标题:fastlane脚本

      本文链接:https://www.haomeiwen.com/subject/iastcdtx.html