iOS自動化腳本上傳IPA包到fir.im

自動化打包直接上代碼,邏輯原理自行百度

自己創(chuàng)建個文件將后綴名改為.py,貼代碼
腳本執(zhí)行方法:

python autobuild.py -w ../schemName.xcworkspace -s schemName

importargparse

importsubprocess

importrequests

import os

#configuration for iOS build setting

PRODUCT_NAME ="schemName"

CONFIGURATION ="Release"

EXPORT_OPTIONS_PLIST ="ExportOptions.plist"

EXPORT_MAIN_DIRECTORY = "~/Desktop/iosMoniArchive"

# firToken

Fir_token = "fir.im上的apiToken"

Fir_aPPId = "應用ID


#檢驗包

defAliasIpaToFirI(ipaPath):

? ? aliasCmd ='fir p %s'%(ipaPath)

? ? process = subprocess.Popen(aliasCmd, shell=True)

? ? process.wait()


? ? aliasReturnCode = process.returncode

? ? ifaliasReturnCode !=0:

? ? ? ? print ("alias faild")

? ? else:

? ? ? ? print ("alias success")

? ? ? ? loginToFirIm(ipaPath)

# login fir account

defloginToFirIm(ipaPath):

? ? loginCmd ='fir login -T %s'%(Fir_token)

? ? process = subprocess.Popen(loginCmd, shell=True)

? ? process.wait()


? ? loginReturnCode = process.returncode

? ? ifloginReturnCode !=0:

? ? ? ? print ("login faild")

? ? else:

? ? ? ? print ("login success")

? ? ? ? publishToFirIm(ipaPath)

# publish

defpublishToFirIm(ipaPath):

? ? publishCmd ='fir publish %s'%(ipaPath)

? ? process = subprocess.Popen(publishCmd, shell=True)

? ? process.wait()


? ? publishReturnCode = process.returncode

? ? ifpublishReturnCode !=0:

? ? ? ? print ("publish faild")

? ? else:

? ? ? ? print ("publish success")


#? ? ? ? des = input("Please input new version description:")

#? ? ? ? send_qq_email(PRODUCT_DISPlayName,des)

defcleanArchiveFile(archiveFile):

? ? cleanCmd ="rm -r %s"%(archiveFile)

? ? process = subprocess.Popen(cleanCmd, shell = True)

? ? process.wait()

? ? print "cleaned archiveFile: %s" %(archiveFile)

defparserUploadResult(jsonResult):

? ? resultCode = jsonResult['code']

? ? ifresultCode ==0:

? ? ? ? downUrl = DOWNLOAD_BASE_URL +"/"+jsonResult['data']['appShortcutUrl']

? ? ? ? print "Upload Success"

? ? ? ? print"DownUrl is:"+ downUrl

? ? else:

? ? ? ? print "Upload Fail!"

? ? ? ? print"Reason:"+jsonResult['message']

defuploadIpaToPgyer(ipaPath):

? ? print"ipaPath:"+ipaPath

#? ? ? ? ipaPath = os.path.expanduser(ipaPath)

#? ? ? ? ipaPath = unicode(ipaPath, "utf-8")

#? ? ? ? files = {'file': open(ipaPath, 'rb')}

#? ? ? ? headers = {'enctype':'multipart/form-data'}

#? ? ? ? payload = {'uKey':USER_KEY,'_api_key':API_KEY,'publishRange':'2','isPublishToPublic':'2', 'password':PYGER_PASSWORD}

? ? print"成功"

#? ? r = requests.post(PGYER_UPLOAD_URL, data = payload ,files=files,headers=headers)

#? ? if r.status_code == requests.codes.ok:

#? ? ? ? result = r.json()

#? ? ? ? parserUploadResult(result)

#? ? else:

#? ? ? ? print 'HTTPError,Code:'+r.status_code

#創(chuàng)建輸出ipa文件路徑: ~/Desktop/{scheme}{2016-12-28_08-08-10}

defbuildExportDirectory(scheme):

? ? dateCmd ='date "+%Y-%m-%d_%H-%M-%S"'

? ? process = subprocess.Popen(dateCmd, stdout=subprocess.PIPE, shell=True)

? ? (stdoutdata, stderrdata) = process.communicate()

? ? exportDirectory ="%s"%(EXPORT_MAIN_DIRECTORY)

? ? returnexportDirectory

defbuildArchivePath(tempName):

? ? process = subprocess.Popen("pwd", stdout=subprocess.PIPE)

? ? (stdoutdata, stderrdata) = process.communicate()

? ? archiveName ="%s.xcarchive"%(tempName)

? ? archivePath = stdoutdata.strip() +'/'+ archiveName

? ? returnarchivePath

defgetIpaPath(exportPath):

? ? cmd ="ls %s"%(exportPath)

? ? process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)

? ? (stdoutdata, stderrdata) = process.communicate()

? ? ipaName = stdoutdata.strip()

? ? ipaPath = exportPath +"/"+"schemName.ipa"

? ? print"ipa 地址 %s"%(ipaPath)

? ? returnipaPath

defexportArchive(scheme, archivePath):

? ? exportDirectory = buildExportDirectory(scheme)

? ? exportCmd ="xcodebuild -allowProvisioningUpdates -exportArchive -archivePath %s -exportPath %s -exportOptionsPlist %s" %(archivePath, exportDirectory, EXPORT_OPTIONS_PLIST)

? ? process = subprocess.Popen(exportCmd, shell=True)

? ? (stdoutdata, stderrdata) = process.communicate()


? ? signReturnCode = process.returncode

? ? ifsignReturnCode !=0:

? ? ? ? print"export %s failed"%(scheme)

? ? ? ? return""

? ? else:

? ? ? ? returnexportDirectory

defbuildProject(project, scheme):

? ? archivePath = buildArchivePath(scheme)

? ? print"archivePath: "+ archivePath

? ? archiveCmd ='xcodebuild -project %s -scheme %s -configuration %s archive -archivePath %s -destination generic/platform=iOS' %(project, scheme, CONFIGURATION, archivePath)

? ? process = subprocess.Popen(archiveCmd, shell=True)

? ? process.wait()


? ? archiveReturnCode = process.returncode

? ? ifarchiveReturnCode !=0:

? ? ? ? print "archive workspace %s failed" %(workspace)

? ? ? ? cleanArchiveFile(archivePath)

? ? else:

? ? ? ? exportDirectory = exportArchive(scheme, archivePath)

? ? ? ? cleanArchiveFile(archivePath)

? ? ? ? ifexportDirectory !="":

? ? ? ? ? ? ipaPath = getIpaPath(exportDirectory)

defbuildWorkspace(workspace, scheme):

? ? archivePath = buildArchivePath(scheme)

? ? print"archivePath: "+ archivePath

? ? archiveCmd ='xcodebuild -workspace %s -scheme %s -configuration %s archive -archivePath %s -destination generic/platform=iOS' %(workspace, scheme, CONFIGURATION, archivePath)

? ? process = subprocess.Popen(archiveCmd, shell=True)

? ? process.wait()


? ? archiveReturnCode = process.returncode

? ? ifarchiveReturnCode !=0:

? ? ? ? print "archive workspace %s failed" %(workspace)

? ? ? ? cleanArchiveFile(archivePath)

? ? else:

? ? ? ? exportDirectory = exportArchive(scheme, archivePath)

? ? ? ? cleanArchiveFile(archivePath)

? ? ? ? ifexportDirectory !="":

? ? ? ? ? ? ipaPath = getIpaPath(exportDirectory)

? ? ? ? ? ? AliasIpaToFirI(ipaPath)

defxcbuild(options):

? ? project = options.project

? ? workspace = options.workspace

? ? scheme = options.scheme


? ? ifprojectisNoneandworkspaceisNone:

? ? ? ? pass

? ? elifprojectisnotNone:

? ? ? ? buildProject(project, scheme)

? ? elifworkspaceisnotNone:

? ? ? ? buildWorkspace(workspace, scheme)

defmain():


? ? parser = argparse.ArgumentParser()

? ? parser.add_argument("-w", "--workspace", help="Build the workspace name.xcworkspace.", metavar="name.xcworkspace")

? ? parser.add_argument("-p", "--project", help="Build the project name.xcodeproj.", metavar="name.xcodeproj")

? ? parser.add_argument("-s", "--scheme", help="Build the scheme specified by schemename. Required if building a workspace.", metavar="schemename")


? ? options = parser.parse_args()

? ? print"options: %s"% (options)


? ? xcbuild(options)

if__name__ =='__main__':

? ? main()

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

相關閱讀更多精彩內容

友情鏈接更多精彩內容