在组件化中把某些ruby命令改成自动化脚本,优化相应的流程。
把一下的几步流程简化:

在fastlane中执行的命令:
中文:快航道。
fastlane是一个ruby脚本集合,lane其实就是航道的意思,action是行为的意思,每一个lane中包含很多很多action,体现在fastlane中其实就是很多小小的命令(fastlane命令)。
首先我们需要知道fastlane中的命令都包括什么,附上相应的链接:相关的fastlane命令,源码链接
接下来,我们开始fastlane脚本的转化:
1.安装fastlane
sudo gem install -n /usr/local/bin fastlane
2.可以查看当前的命令到底有多少(可选)
fastlane actions
3.查看当前的fastlane版本(可选)
fastlane --version
4.pod安装可以测试/直接管理组件的工程(如果你想放到桌面那么,先cd到当前桌面Desktop,再执行当前的命令)
pod lib create 项目名称
5.项目中添加组件代码,修改podspec文件,然后cd到当前的项目中
6.接下来,开始按照非自动化时我们的命令,改成相应的fastline脚本代码
fastlane init - 项目中生成一个fastlane(其中会生成一个Fastfile文件,如果没有可以在fastlane文件下自己用命令 touch Fastfile,记的放到fastlane文件下)、build上传文件(应该是上传到appStore,不过现在没用到,如果有人用到的化,记的告诉我哦,😄),这个过程将appID 或者iturns等相关的信息都可以获取到(可能会让你输入appID账号密码)。
修改Fastfile文件,按照我们需要的命令,修改成相应的fastlane命令。


抱歉,在Fastfile中第八行,不能用//注掉相应的无用信息,应该用#。编辑完之后,我们就可以利用脚本进行自动化的安装了。
default_platform(:ios)
platform :ios do
desc "ManagerLib 使用这个航道,可以快速的对自己的私有库,进行升级维护"
lane :ManagerLib do |options|
tagName = options[:tag]
targetName = options[:target]
#具体航道上执行那些命令
#1.pod install
cocoapods(
clean: true,
podfile: "./Example/podfile"
)
#2.pod add .
git_add(path: ".")
#3.git commit -m 'xx'
git_commit(path: ".", message: "fastlane进行自动化生成组件")
#4.git push origin master
push_to_git_remote
#5.git tag
add_git_tag(
tag: tagName
)
#6.git push --tags
push_git_tags
#7.pod spec lint
pod_lib_lint(allow_warnings: true)
#8.pod repo push xxxx XX.podspec
pod_push(path: "#{targetName}.podspec", repo: "WKFMBase")
end
end
这是具体的代码,可以直接使用,别忘了修改本地私有库的名称
7.进行自动化安装
首先cd到文件根目录
可选命令:fastlane --help - 这个命令是教我们如何查看fastlane中的命令的
可选命令:fastlane lanes - 查看航道的数量和名称
自动化安装命令:
fastlane ManagerLib(航道名称) tag:0.1.0 target:WKPlayer(podspec文件名称)
如果提示是由于WARN失败,那么你需要在相应的fastlane命令中加入allow-warning参数进行相应的处理。

8.自定义action(如果在自动化过程中,发现最后一步验证spec文件验证失败,但是tag 标签已经上传到远程,那么我们需要重新执行脚本,但是tag已经还需要重新修改,针对这个问题我们进行自定义action,删除老的远端/本地tag,并且上传新的代码打上原来的tag)
在根目录下执行
fastlane new_action
接下来会让你输入行的action的name,我输入的action_tag

接下来,在remove_action中编辑,
self.authors-作者名称
self.description -描述
self.details - 详细信息
key 是我们要传的参数名称,description:描述这个参数是用来干什么的,自定义填写
is_string 是否是字符串,默认是true,default_value 默认值是false,这个参数不用的化可以删除 optional:是否是可选类型,true是可选,false不是可选
我们现在设置三个参数:tagName:标签名 rL:移除本地标签,默认是true
rR:移除远程标签,默认是true

我们可以在源码地址中,看某些脚本语言的源码是如何写的。

我们在Fastlane中加入自定义的action

这就是自定义action了,哈哈,收获打的化就给给好评呗😄
网友评论