做者:webfrogsios
轉載請註明出處。git
IOS的開發過程當中,當須要給測試人員發佈測試包的時候,直接使用xcode來作的效率是很是低下的。尤爲是當有一點小改動須要從新出包時,那簡直是個折磨的人的工做。經過一番研究後,遂決定寫一系列腳本,以代替人工完成打包和發佈的過程。github
目前腳本已經完成,基本能夠知足我目前的需求。現將其開源,託管在github上,項目地址:點擊這裏web
藉助xcode所附帶的「Command Line Tools」,能夠經過命令行來完成IOS工程的編譯和打包工做。腳本正是基於此完成的。shell
本套腳本分爲三個部分:負責編譯工程並打包的腳本ipa-build,負責生成itms-services協議文件的腳本ipa-publish,以及負責將ipa-publish腳本生成文件上傳到服務器的腳本upload。xcode
其中,因爲我本身的狀況是服務器端的同事給我了內部測試服務器的sftp的上傳權限,因此這個upload腳本主要實現了使用sftp來上傳的功能。具體能夠實際狀況來作修改。服務器
關於itms-services協議的一些內容,能夠參考我以前的文章:《shell腳本實現ipa一鍵安裝(itms-services協議)》併發
注意:默認安裝完的xcode並無自帶「Command Line Tools」,須要在xcode中選擇後下載才能使用app
打開工程後,會發現本套腳本中包含好幾個shell文件。下面對其功能作說明:less
ipa-build: 編譯xcode工程並生成ipa文件 ipa-publish: 生成符合itms-services協議的文件,併發布到服務器。 sendEmail: stmp發送email的腳本。(別人寫的) sftpDownloadFile: 經過sftp協議下載文件 sftpUploadFile: 經過sftp協議上傳文件 updateLocalIndexHtml: 對索引文件進行處理(二進制文件,非shell腳本) uploadItemsServicesFiles: 將itms-services協議文件上傳到服務器
實際使用的腳本,只有"ipa-build"和"ipa-publish"這兩個。其餘文件會被ipa-publish這個腳本調用的依賴文件。其中出 了"updateLocalIndexHtml"是我用objc寫的一個用來進行文本處理的編譯後的二進制文件,其他均爲shell腳本。
shell腳本實現,你們能夠打開腳原本看一下,裏面的註釋算是很詳細了。不須要太多說明。
其中值得一提的就是我在寫sftp協議上傳功能的時候,碰到了一個問題就是使用腳原本自動輸入密碼,也就是交互式腳本的編寫。最後選擇了expect來完成,由於我發現mac系統裏自帶了這個expect命令。
在編寫腳本時,我已經考慮到,要儘可能使這個腳本使用起來簡單方便。若是隻須要打包,那麼只使用ipa-build腳本便可。若是須要用itms- services協議來發布,則再運行ipa-publish腳本便可。在ipa-publish腳本中調用了upload腳本,因此upload腳本不 須要單獨使用。
ipa-build腳本使用方法:
ipa-build腳本絕對路徑 參數1 參數2
其中,參數1是IOS工程的根路徑,是必輸項。參數2能夠不輸入,是可選的,含義是編譯時的工程configuration類型,有4種類型可選:Debug, AdHoc,Release, Distribution。默認是Release。
ipa-build腳本運行後,會在IOS工程根路徑下生成名爲「build」的文件夾,在這個文件夾中又有一個名爲「ipa-build」的文件夾,打包所生成的最新ipa包就在其中。
ipa-publish腳本使用方法:
ipa-publish腳本絕對路徑 參數1 參數2
參數1是IOS工程的根路徑,是必輸項。參數2是可選的,含義是當上傳文件成功後是否發送email通知,y爲發送,n爲不發送,默認的值是不發送。
You can do this by using "ipa-build" shell script.
This ipa-build script is created to compile the xcode project and package the project to an ipa file.
building xcode project
ipa-build <project directory> [-c <project configuration>] [-o <ipa output directory>] [-t <target name>] [-n]
building xcode workspace
ipa-build <workspace directory> -w -s <schemeName> [-c <project configuration>] [-n]
-c NAME the configuration of project used to compile.Default is Release -o PATH output path for ipa file(must be a directory) -t NAME the target which should be compiled -w build xcode workspace -s NAME the schemal to be used for compiling -n clean the project before compling
build project
If you have an iOS project in the path ~/iphone, and the ipa-build script is put in the path ~/xcode-shell.You want to build this project with 'Release' configuration.Just using script like this:
cd ~/iphone ~/xcode-shell/ipa-build .
If you want to assign specific configuration or target, you can add relevant options to the command.
build workspace
If ~/iphone is a xcode workspace and the scheme used for compile named 'test'.The ipa-build script is put in the path ~/xcode-shell.Using script like this:
cd ~/iphone ~/xcode-shell/ipa-build . -w -s test
You can also assign a specific configuration by using -c option.
Note:If script executed successfully,an ipa file is created in the path: <project path>/build/ipa-build.
CocoaPods is an Objective-C library manager.If you use it in your iOS project.You can also use 'ipa-build' script to build by assign workspace and scheme, or you can use the 'cocoapods-build' to build it more easily.
cocoapods-build <cococapods project path> [<build configuration>]
cd ~/iphone ~/xcode-shell/cocoapods-build . Debug
You must configure the script before using at the first time. Open it in any text editor and input you own configurations. Such as ftp address, app download url, email sender and email receiver. After that you can run this script to publish app to your own server. Note that installing app from your own server should respect the protocol named "itms-services". To learn more about "itms-services" you can click blog Wireless AdHoc Distribution(English) or blog ios實現itms-services協議企業內發佈或者越獄發佈(中文).
ipa-publish <project root path> [y <should send notification email>]
~/xcode-shell/ipa-publish . y #publish and send email ~/xcode-shell/ipa-publish . #just publish
This script is similar to "ipa-publish". Both of them are using to publish app to somewhere. But this script will publish app to fir.im. So it is more easier to use, as you don't need a special server and FTP. You can use it without any configration, unless you want to send email to notify somebody.
If you want to send email to notify somebody. Open the script, and changed the value of "email_reciver". This field may contain one or more than one emails.
ipa-publish-fir [-d directory>] [-e] [-l number] [-m message]
-d path the root directory of project -e send email after publishing -l number limit of git log, which will be used as change log. -m message used as chang log
~/xcode-shell/ipa-publish-fir -d . -el20 -m "haha" #Publish and send email. The change log on fir and in email will be "haha"+<last 20 logs of git> ~/xcode-shell/ipa-publish-fir -d . #just publish
When programming for retina device of iOS,the image file you used should add the suffix of @2x. Using the script "add2x" can help you do this automaticly.
add2x: add suffix of @2x to all the image files(just png and jpg file) .This script work in the current directory.
Usage:
1. go to the directory which contains images should be added suffix.
2. execute the add2x script.
note: There is a bug of this script.If your image file name contains blank spaces, script can not work correctly.
ipa-publish腳本運行後,會在「build」文件夾中生成一個以工程的targetname爲名字的文件夾。其中,存放了itms-services協議所需的全部文件。腳本會將裏面內容所有上傳到服務器中。
一、運行腳本須要絕對路徑,不能使用相對路徑。
二、腳本下載後,若要使用,有些腳本須要一些改動。
其中ipa-build腳本無須更改。能夠直接使用。ipa-publish腳本須要配置一些信息後方能正常使用。
用文本打開ipa-publish腳本後,在shell開始的地方,有一段須要配置的地方,以下:
#須配置內容 start #sftp參數設置 sftp_server=192.168.xx.xx sftp_username=xx sftp_password=xx sftp_workpath="/usr/share/xx/xx/xx" #發佈應用的url地址 pulish_url="http://xx.com/xx" #如下是郵箱的相關設置 #收件人 email_reciver=xx@xx.com #發送者郵箱 email_sender=xx@xx.com #郵箱用戶名 email_username=xx #郵箱密碼 email_password=xx #smtp服務器地址 email_smtphost=smtp.exmail.qq.com #可配置內容 end
根據實際狀況配置便可。