端午闲来无事,搞了下 iOS 的持续集成,技术都是现成的,纯粹记录下整个过程,以作备忘,也希望能帮到别人.
废话不多说,直接上~
技能:
熟悉iOS打包基本流程
熟悉苹果开发证书操作
熟悉命令行基本使用
了解 Dash shell 命令
能看懂 python 基本语法
能看懂 html js 基本语法
工具:
苹果开发帐号
macOS 电脑
终端工具
Pycharm
chrome
实战目标: 在浏览器(包括手机浏览器)上,实现一键打包
准备:
1.在 svn的可直接运行的iOS工程,checkout 到某目录(例子中是目录 /Users/xx/Desktop/iOSTest)
2.在任意目录下新建shell文件,名字随意(例中取名为test.sh)
sh 文件中输入内容如下
#!/bin/sh
say 'start build ipa'
cd /Users/xx/Desktop/iOSTest
#svn更新
svn update
#用 fastlane 打包并上传至蒲公英
bundle exec fastlane beta
其中bundle exec fastlane beta 的 beta 是打包版本的名称.(见条目5中的2小条 )
3.在苹果开发帐号设置好证书和配置文件4.开始安装 fastlane 工具和 pgyer 插件
a. 终端执行 sudo gem install fastlane,如果失败请尝试
sudo gem install -n /usr/local/bin fastlane
b.终端进入工程目录, 执行 fastlane init,执行过程中需做相应输入(如开发帐号等)
c.安装 bundler ,终端执行 sudo gen install -n /usr/local/bin bundler
d.安装fastlane 的蒲公英插件,终端执行 fastlane add_plugin pgyer
5.配置 fastlane 和 pgyer
a.用编辑器打开工程目录下 fastlane 文件夹中的 fastfile, 做如下编辑
1)删除 start del 至 end del 之间的内容
platform :ios do
before_all do
# ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
end
#-------start del--------
#-------end del--------
# You can define as many lanes as you want
2)在 start end 直接输入:
lane :beta do
gym(
scheme: "Lnma",
export_method: "development",
output_directory: "build",
include_bitcode: false
)
pgyer(api_key: "3925178d7908616272d89bd39a0cd9x2", user_key: "d6295cf6f4780cbcaf91c16a4087x7af")
end
其中 beta 为要打包版本的标识
gym 是自动打包工具,括号中是相关参数,具体可见参考帖子中的相关说明
pgyer 是蒲公英中本应用的 apikey 和 userkey(具体见参考帖子2)
6.执行.sh 脚本
终端cd 进工程目录,输入 shell test.sh,如果以上配置均正确,此时可打包发布至 pgy 本应用下.
7.在网页上做打包
a.创建服务工程
打开 Pycharm,新建 flask 工程,用一下代码替换新建的 py 文件内容
from flask import Flask
import os
app = Flask(__name__,static_url_path='')
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/test')
def testBeta():
status = os.system('sh /Users/mac登录名/Desktop/iOSTest/test.sh')
print status
return 'running'
if __name__ == '__main__':
# app.run()
app.run(host='0.0.0.0', port=5000)
b.创建网页文件 index.html
1)在 py 工程static目录下新建 html5文件,命名为 index;
2)用以下代码替换新建的文件内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
</head>
<body>
<h4>test</h4>
<button id='beta' onclick="bundleBeta()">打包beta</button>
<script>
function bundleBeta() {
$("#beta").load("http://192.168.1.107:5000/test");
}
</script>
</body>
</html>
3)运行工程.运行正常,控制台会打印
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
4) 浏览器输入 localhost:5000,即可看到如下页面:
点击打包 beta 按钮即可打包 ipa并上传至蒲公英.
参考帖子:
1.https://zhuanlan.zhihu.com/p/23180455
2.蒲公英插件设置 https://www.pgyer.com/doc/view/fastlane
3.http://www.cocoachina.com/ios/20170519/19317.html
4.http://www.jianshu.com/p/002e1061ee08