Fastlane自動化打包到蒲公英搭配釘釘機器人webhook通知

打包腳本集成

  1. 定義好可配置項,方便修改
# 先定義好全局變量 
SCHEME = "xxx"
WORKSPACE = "xxx.xcworkspace"
XCODEPROJ = "xxx.xcodeproj"
BundleId = "com.xxx.ooo"
dingding_token = "xxxxoooo" #電腦端釘釘建羣羣助手添加機器人webhook設置好獲取token即可 發消息得帶tag不然可能失敗

  1. 打包到Testflight

    desc "打包到Testflight"
      lane :beta do
        increment_build_number_in_plist(target: SCHEME) #build號自增
        build_app(
          workspace: WORKSPACE,
          scheme: SCHEME,
          silent: true,
          clean: true,
          output_directory: '.ipa/Testflight',
          output_name: 'app.ipa',
          export_xcargs: "-allowProvisioningUpdates",
          export_options: {
            method: 'app-store',
            manifest: {
              appURL: 'https://example.com/MyApp.ipa',
              displayImageURL: 'http://xxxxxx',#小圖標
              fullSizeImageURL: 'http://xxxxx'#大圖標1024x1024
            }
          }
        )
        upload_to_testflight(
          ipa: '.ipa/Testflight/app.ipa'
        )
     end
    
  2. 打包到App Store

    desc "部署到App Store"
      lane :release do |options|
        sigh(
          output_path: '.certificates',
          force: true
        )
    
        increment_version_number_in_plist(
          target: SCHEME,
          version_number: options[:version_number]
        )
        increment_build_number_in_plist(target: SCHEME)
    
        gym(
          scheme: SCHEME,
          clean: true,
          silent: true,
          output_directory: '.ipa/AppStore',
          output_name: 'app.ipa',
          configuration: 'Release',
          export_xcargs: "-allowProvisioningUpdates"
        )
        upload_to_app_store(
          force: true,
          ipa: '.ipa/AppStore/app.ipa',
          skip_screenshots: true,
          automatic_release: true
        )
      end
    
  3. 打AdHoc分發包

    cert #獲取證書
    #驗證簽名
    sigh(
      adhoc: true,
      output_path: '.certificates',
      app_identifier: BundleId
     )
    #自增build號
    increment_build_number_in_plist(target: SCHEME)
    time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
    #編譯打包
    gym(
      scheme: SCHEME,
      clean: true,
      output_directory: ".ipa/#{SCHEME}/#{time}",
      output_name: 'app.ipa',
      configuration: "Release",
      export_xcargs: "-allowProvisioningUpdates"
     )
    # 上傳蒲公英 
    upload_ipa_to_pgyer(scheme: SCHEME, time: time)
    
    # 發送釘釘消息
    send_dingding_msg()
    
  4. 上傳至蒲公英分發平臺 (這個平時用的比較多)

    private_lane :upload_ipa_to_pgyer do |options|
        pgyer(
          api_key: "xxxxx",
          user_key: "xxxxx",
          ipa: ".ipa/#{options[:scheme]}/#{options[:time]}/app.ipa"
        )
     end
    
  5. 發送釘釘機器人消息

      desc "發送機器人🤖消息到釘釘羣"
      lane :send_dingding_msg do |options|
        version = get_version_number(target: SCHEME)
       text = "🚀🚀🚀測試包v#{version} Release環境打包更新啦,下載地址:https://www.pgyer.com/xxx ,請查收~ "
       ding_talk_msg_push(token:dingding_token, text:text, at_all: true)
      end
    
  6. 發送更新日誌到釘釘羣

    # 打包之前準備好更新內容 log.txt 存放在fastlane同一目錄層級
    desc "獲取更新日誌併發送至釘釘機器人🤖"
        lane :send_log_to_dingding do  |options|
        log_text = File.new("../log.txt", "r:utf-8").sysread(2000) #讀取文本2000字
        ding_talk_msg_push(token:dingding_token, text:log_text, at_all: true)
    end 
    
  7. 可能用到的插件,在Pluginfile中添加

    gem 'fastlane-plugin-pgyer'
    gem 'fastlane-plugin-versioning'
    gem 'fastlane-plugin-ding_talk_msg_push'
    

fastlane自動化腳本打包,至此就告一段落了,持續集成下次再弄~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章