iOS持續(xù)集成之自動(dòng)更新設(shè)備

在iOS開發(fā)中經(jīng)常遇到的問題就是要添加測(cè)試設(shè)備。一般都需要登錄開發(fā)者網(wǎng)站,操作比較麻煩。這里主要是通過腳本的形式添加設(shè)備

這里主要用到的工具是fastlane中的spaceship,不熟悉的可以查看這里

代碼如下:

#!/usr/bin/env ruby

require 'rubygems'
require 'commander/import'
require "spaceship"

global_option('-u', '--username USER', 'Username') { |arg| $username = arg unless arg.nil? }
global_option('-p', '--password PASSWORD', 'Password') { |arg| $password = arg unless arg.nil? }

program :name, 'app profile'
program :version, '1.0.0'
program :description, '證書 Create By Jay'


command :'profiles:download:all' do |c|
  c.syntax = 'ios profiles:download:all'
  c.summary = 'Downloads all the active Provisioning Profiles'

  c.option '--id  [ID]', "" ,"程序包名" 

  c.action do |args, options|
    bundleId =  options.id
    say "開始登陸" + bundleId
    Spaceship.login($username, $password)
    say "登陸成功" 
    say "開始下載證書"
    profiles = Spaceship.provisioning_profile.find_by_bundle_id(bundleId)
    profiles.each do |profile|
        say "下載 " + profile.name
        File.write(profile.name + ".mobileprovision", profile.download)
    end
    say "完成"
  end
end

command :'device:add:dict' do |c|
  c.syntax = 'aa device:add'
  c.summary = '添加設(shè)備'
  c.option '--dict [DICT]', "", "設(shè)備名稱:udid鍵值對(duì)"
  c.option '--id  [ID]', "" ,"程序包名" 
  c.action do |args,options|
    deviceDicts = eval(options.dict)
    bundleId =  options.id
    Spaceship.login($username, $password)
    if deviceDicts.class == Hash
        deviceName = deviceDicts[:name]
        deviceUDID = deviceDicts[:udid]
        registerDevice(deviceName,deviceUDID)
        
    elsif deviceDicts.class == Array
        for dict in deviceDicts
            deviceName = deviceDicts[:name]
            deviceUDID = deviceDicts[:udid]
            registerDevice(deviceName,deviceUDID)
        end

    else
        say "格式不正確"
    end
    say "完成注冊(cè),更新profile"    
    say "獲取profiles"
    profiles = Spaceship.provisioning_profile.find_by_bundle_id(bundleId)
    allDevices =  Spaceship.device.all
    say "開始更新Profile中的Device"
    profiles.each do |profile|
        say "更新" + profile.name + "中的Device"
        profile.devices = allDevices
        profile.update!
    end

  end
end

def registerDevice(deviceName,deviceUDID)
    say "注冊(cè)設(shè)備:" + deviceName + ":" + deviceUDID
    Spaceship.device.create!(name: deviceName, udid: deviceUDID)
end


command :'device:add' do |c|
  c.syntax = 'aa device:add'
  c.summary = '添加設(shè)備'
  c.option '--name [NAME]', "", "設(shè)備名稱"
  c.option '--udid  [UIID]', "" ,"設(shè)備" 
  c.option '--id  [ID]', "" ,"程序包名" 
  c.action do |args,options|
    deviceName = options.name
    deviceUDID = options.udid
    bundleId = options.id
    say "獲取profiles"
    profiles = Spaceship.provisioning_profile.find_by_bundle_id(bundleId)
    say "注冊(cè)Device"
    Spaceship.device.create!(name: deviceName, udid: deviceUDID)
    allDevices =  Spaceship.device.all
    profiles.each do |profile|
        say profile.name
        profile.devices = allDevices
        profile.update!
    end
    say "完成"
  end
end




最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容