美文网首页
iOS自动化构建 - fastlane持续集成(蒲公英、钉钉)

iOS自动化构建 - fastlane持续集成(蒲公英、钉钉)

作者: AntKing | 来源:发表于2019-10-29 09:36 被阅读0次

    iOS自动化构建 - fastlane持续集成(蒲公英、钉钉)

    fastlane自动构建魔板

    
    
    default_platform(:ios)
    
    # 网络请求依赖
    require 'net/http'
    require 'uri'
    require 'json'
    
    platform :ios do
      
      # release发布包
      desc "Push a new release build to the App Store"
      lane :release do
        increment_build_number(xcodeproj: "TestFastLane.xcodeproj")
        build_app(workspace: "TestFastLane.xcworkspace", scheme: "TestFastLane")
        upload_to_app_store
      end
    
      # debug测试包
      desc "Push a new debug build to the pgyer.com"
      ipa_dir  = "fastlane_build/"
      ipa_name = "TestFastLane" + Time.new.strftime('%Y-%m-%d_%H:%M')
    
      lane :pgyer_debug do |options|
      gym(
        # 打包前clean项目
        clean: true, 
        # 构建时,隐藏不必要的信息  
        silent: true,           
        # bitcode
        include_bitcode: false,                             
        # 导出方式 app-store、ad-hoc、enterprise、development
        export_method: "development",        
        # scheme    
        scheme: "TestFastLane",                 
        # 环境 Debug、Release
        configuration: "Debug",             
        # ipa的存放目录
        output_directory: ipa_dir,          
        # 输出ipa的文件名为当前的build号
        output_name: ipa_name                 
        )
    
      # 蒲公英
      pgyer(
        api_key: "ab70746d7c5a4b0dd782b841584e9a9d", 
        user_key: "01dac7593f06912c4205b892a255385e",
        update_description: 
        options[:desc]
        )
    
      # 钉钉机器人
      app_patch   = ipa_dir + "/#{ipa_name}.ipa"
      app_version = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleShortVersionString")
      app_build_version = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleVersion")
      app_name    = get_ipa_info_plist_value(ipa: app_patch, key: "CFBundleDisplayName")
      app_url = "[******]"
      app_icon = "[******]"
      dingTalk_url = "[******]"
      
      markdown = 
      {
        msgtype: "link", 
        link: {
            text: "已经更新啦,快来试试吧!", 
            title: "iOS #{app_name} #{app_version} (#{app_build_version}) 内测版", 
            picUrl: "#{app_icon}", 
            messageUrl: "#{app_url}"
        }
      }
    
      uri = URI.parse(dingTalk_url)
      https = Net::HTTP.new(uri.host, uri.port)
      https.use_ssl = true
    
      request = Net::HTTP::Post.new(uri.request_uri)
      request.add_field('Content-Type', 'application/json')
      request.body = markdown.to_json
    
      response = https.request(request)
      puts "------------------------------"
      puts "Response #{response.code} #{response.message}: #{response.body}"
    
      end
    
    end
    
    
    

    相关文章

      网友评论

          本文标题:iOS自动化构建 - fastlane持续集成(蒲公英、钉钉)

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