上家公司的开发流程是这样的,代码写完提交到gitlab,会自动在gitlab的runner上跑一遍,以确保这次的提交不会无法编译通过,然后再合并到相应的分支master或release,当合并到这些分支上时,会触发fastlane的打包并上传到fir或testFlight上以供测试。
现在新入职公司iOS就我一个,改了新功能给其他人测时还得手动archive,export,再上传,感觉十分浪费青春,于是就研究了一下CI是怎么实现的。
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
#我这边因为用的企业账号,所以export_method写了enterprise, 个人账号应该是不用写的
end
此时在终端上cd到项目,然后fastlane beta或fastlane release就会相应的打测试或正式包并上传到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 复制或创建一个.gitlab-ci.yml文件到项目根目录下,当代码被push到gitlab上时,如果有这个文件会自动触发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