上家公司的開發(fā)流程是這樣的,代碼寫完提交到gitlab,會自動在gitlab的runner上跑一遍,以確保這次的提交不會無法編譯通過,然后再合并到相應(yīng)的分支master或release,當合并到這些分支上時,會觸發(fā)fastlane的打包并上傳到fir或testFlight上以供測試。
現(xiàn)在新入職公司iOS就我一個,改了新功能給其他人測時還得手動archive,export,再上傳,感覺十分浪費青春,于是就研究了一下CI是怎么實現(xiàn)的。
1.1 安裝Xcode命令行工具
xcode-select --install
1.2 安裝fastlane
sudo gem install fastlane -NV
或
brew cask install fastlane
1.3 cd到項目目錄并
fastlane init
2.1 在fastlane文件夾里找到Fastfile,改一改
default_platform(:ios)
platform :ios do
desc "beta lane desc"
lane :beta do
build_app(export_method:"enterprise", configuration:"Debug", output_directory:"./ipas", output_name:"testName.ipa")
fir_beta
end
lane :fir_beta do
sh "fir publish ../ipas/testName.ipa -T 你的fir用戶token"
end
lane :release do
build_app(export_method:"enterprise", configuration:"Release", output_directory:"./ipas", output_name:"releaseName.ipa")
fir_release
end
lane :fir_release do
sh "fir publish ../ipas/releaseName.ipa -T fir用戶token"
end
#我這邊因為用的企業(yè)賬號,所以export_method寫了enterprise, 個人賬號應(yīng)該是不用寫的
end
此時在終端上cd到項目,然后fastlane beta或fastlane release就會相應(yīng)的打測試或正式包并上傳到fir了
+------+------------------------+-------------+
| fastlane summary |
+------+------------------------+-------------+
| Step | Action | Time (in s) |
+------+------------------------+-------------+
| 1 | default_platform | 0 |
| 2 | build_app | 111 |
| 3 | Switch to ios | 0 |
| | fir_release lane | |
| 4 | fir publish | 4 |
| | ../ipas/-----------.i | |
| | pa -T | |
| | --------------------- | |
| | 9 | |
+------+------------------------+-------------+
[16:24:01]: fastlane.tools finished successfully ??
3.1 復(fù)制或創(chuàng)建一個.gitlab-ci.yml文件到項目根目錄下,當代碼被push到gitlab上時,如果有這個文件會自動觸發(fā)runner
3.2 注冊Runner
看到每個月有2000分鐘shared runner,不過似乎跑iOS項目時會有問題
https://gitlab.com/help/ci/yaml/README.md
2020-03-06更新
新增了上傳dSYM到聽云的lane,fir由于域名問題目前不可用了,今天打包也出了問題,提示provision證書需要更新,不過我看Xcode上面debug跟release證書都是有效的,還有7個月過期不知道是不是我理解有誤。
error: exportArchive: No profiles for 'com.wlsfa' were found
Error Domain=IDEProfileLocatorErrorDomain Code=1 "No profiles for 'com.wlsfa' were found" UserInfo={IDEDistributionIssueSeverity=3, NSLocalizedDescription=No profiles for 'com.wlsfa' were found, NSLocalizedRecoverySuggestion=Xcode couldn't find any iOS In House provisioning profiles matching 'com.wlsfa'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild.}
** EXPORT FAILED **
[09:00:57]: Exit status: 70
不過既然都提示怎么改了,在build_app時加上xcargs: "-allowProvisioningUpdates"解決問題
default_platform(:ios)
platform :ios do
desc "beta lane desc"
lane :beta do
build_app(export_method:"enterprise", xcargs: "-allowProvisioningUpdates", configuration:"Debug", output_directory:"./ipas", output_name:"Test.ipa")
fir_beta
end
lane :fir_beta do
sh "fir publish ../ipas/Test.ipa -T fir用戶token"
end
lane :release do
clear_derived_data
build_app(export_method:"enterprise", xcargs: "-allowProvisioningUpdates", configuration:"Release", output_directory:"./ipas", output_name:"Release.ipa")
fir_release
upload_dsym
end
lane :fir_release do
sh "fir publish ../ipas/Release.ipa -T fir用戶token"
end
# -o 強制覆蓋 -d 更改解壓目錄
# .dSYM為文件夾,所以需要-r刪除
lane :upload_dsym do
sh "unzip -o ../ipas/Release.app.dSYM.zip -d ../ipas/"
sh "curl -k -F upload=@../ipas/appName.app.dSYM/Contents/Resources/DWARF/appName https://mobile-symbol-upload.tingyun.com/symbol/authkey/agabd376/appkey/tingyunAppKey"
sh "rm -r ../ipas/appName.app.dSYM"
end
end