使用fastlane升级维护pods库

库官网:https://docs.fastlane.tools

fastlane中有两个比较重要的概念

lane:航道,其实就是一系列actions的组合,实现一个功能

actions:最小执行单元 https://docs.fastlane.tools/actions/


安装看官网

使用方法:

在项目根目录(其它目录也可以,在根目录设置路径的时候会简单些)新建一个fastlane的文件夹,在这个文件夹中新建一个Fastfile的文件,在这个文件中添加类似以下代码(注释使用#开头)

desc'使用这个航道快速对自己的pods库做升级维护'  #这个lane的描述

#lane: 航道名称 do |options| #这个options可以操作参数等

lane:PodsManagerdo|options|  

#增加外部参数 tagName是内部参数,tag是外部参数

tagName=options[:tag]

commitMessage=options[:message]

#actions   具体actions可以在官网搜索到

#1. pod install

cocoapods(

clean:true,

podfile:"Example/Podfile"#相对于根目录

)

#2. git add .    git commit -m "xx"    git push origin master

git_add(path:".")

git_commit(path:".",message:"#{commitMessage}xx")

push_to_git_remote

#判断要添加的tag是否已经存在,如果存在,使用自定义的remove_tag

if git_tag_exists(tag: tagName)

remove_tag(tag: tagName)

end

#3. git tag ""  git push --tags

add_git_tag(

tag:tagName

)

push_git_tags

#4. pod spec lint      pod trunk push

pod_lib_lint(allow_warnings:true)

pod_push

end


文件保存后,cd到项目根目录

fastlane PodsManager tag:0.1.0 message:xx

然后就啥也不用管了(podspec里面的tag还是要手动改一下。。。)


自定义action  源码https://github.com/fastlane/fastlane/tree/master/fastlane/lib/fastlane/actions,可以参考去写

cd 到fastlane所在目录

fastlane new_action

     Name of your action: 定义action名称

cd 到fastlane,会看到里面有了一个actions文件夹,打开里面的remove_tag.rb

module Fastlane

module Actions

module SharedValues

REMOVE_TAG_CUSTOM_VALUE = :REMOVE_TAG_CUSTOM_VALUE

end

class RemoveTagAction < Action

#真正执行的逻辑

def self.run(params)

#取出传递的参数

tag = params[:tag]

rl = params[:rl]

rr = params[:rr]

#拼接命令

cmds = []

if rl

cmds << "git tag -d #{tag}"

end

if rr

cmds << "git push origin :#{tag}"

end

UI.message("removing git tag #{tag}")

resultCmd = cmds.join(" & ")

#执行命令, 接收的是具体命令的字符串

Actions.sh(resultCmd)

end

#描述

def self.description

"remove tag"

end

#详细描述

def self.details

"删除本地&远程tag"

end

#参数

def self.available_options

[

FastlaneCore::ConfigItem.new(key: :tag,

description: "tag name",

is_string: true,

optional: false

),

FastlaneCore::ConfigItem.new(key: :rl,

description: "是否删除本地标签",

optional: true,

is_string: false,

default_value: true),

FastlaneCore::ConfigItem.new(key: :rr,

description: "是否删除原创标签",

is_string: false,

optional: true,

default_value: true

)

]

end

#输出

def self.output

""

end

#返回值

def self.return_value

nil

end

#作者

def self.authors

["Zyj163"]

end

#支持的平台

def self.is_supported?(platform)

[:ios, :mac].include? platform

end

end

end

end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 作为架构师的我们常常要面临的一个难题就是技术选型。现在无论是商业项目也好,开源项目也好,可供选择的方案实在是太多,...
    老邢Thierry阅读 10,350评论 17 52
  • Fastlane简介 Fastlane是用Ruby语言编写的一套自动化工具集和框架,每一个工具实际都对应一个Rub...
    小_夭阅读 12,365评论 2 15
  • 一、环境配置 安装rbenv1.安装rbenvrbenv的源代码托管在github,在终端中,从github上将r...
    叫我公爵大人阅读 4,463评论 0 2
  • 前段时间一直在忙考试,考完最难考的一科之后,正好遇上晴天,心情和天气一样格外晴朗。我把考完的喜悦告诉即将大四毕业的...
    递根烟给路客阅读 2,515评论 0 1
  • 阅读时间:2015.10.256:30-7:30 阅读书本:《冥想》 阅读目标:了解冥想的具体操作方法 阅读进度:...
    赵秀丽2017阅读 1,586评论 0 1