运用fastlane一行命令发布私有组件库:
1、安装fastlane
如果没有安装过fastlane需要手动安装一下
# Using RubyGems
sudo gem install fastlane -NV
# Alternatively using Homebrew
brew install fastlane
2、初始化fastlane
到你的组件开发目录下
# Using objectC
fastlane init
# Using Swift
fastlane init swift
3、编辑Fastfile文件
对应的lane代码:
desc "Pod repo lint&push"
lane :release_pod do |options|
target_repo = options[:repo]
target_project = options[:project]
target_version = options[:version]
#没有repo参数让用户输入
if !target_repo
UI.message("please enter your repo name:")
target_repo = STDIN.gets.chomp
end
#兼容没有传project参数的问题
if !target_project
target_project = File.basename(File.expand_path("..", Dir.pwd))
end
#没有version参数让用户输入
if !target_version
UI.message("please enter your tag_vaersion:")
target_version = STDIN.gets.chomp
end
spec_path = "#{target_project}.podspec"
# git pull
git_pull
# 确认是 master 分支
ensure_git_branch
# 修改 spec 为即将发布的版本
version_bump_podspec(path: spec_path, version_number: target_version)
# 提交代码到远程仓库
git_add(path: '.')
git_commit(path: '.', message: 'release')
push_to_git_remote
# 检查对于 tag 是否已经存在
if git_tag_exists(tag: target_version)
UI.message("tag #{target_version} exists, enter yes to delete:")
isRemoveTag = STDIN.gets.chomp
puts isRemoveTag
if isRemoveTag == 'yes'
# 删除对应 tag
# 最終要執行的東西,在這裡執行
# 2、定義一個數組,準備往數組裡面添加相應的命令
cmds = []
# 刪除本地的標籤
# git tag -d 標籤名稱
cmds << "git tag -d #{target_version}"
# 刪除遠程標籤
# git push origin :標籤名稱
cmds << "git push origin :#{target_version}"
# 3、執行數組裡面的所有的命令
result = Actions.sh(cmds.join('&'))
UI.message("執行完畢 remove_tag的操作 🚀")
else
UI.message("tag 已经存在 已退出🚀")
exit!
end
end
# 添加 tag
add_git_tag(tag: target_version)
# 提交 tag
push_git_tags
# 验证 spec 文件
pod_lib_lint(allow_warnings: true)
# push repo
pod_push(path: spec_path, repo: target_repo, allow_warnings: true, skip_import_validation: true)
end
4、发布命令
编写好Fastfile文件就可以使用命令去发布了,目前支持的命令(2以后的参数都是可选,不填的话可执行过程中输入):
1)fastlane release_pod
2)fastlane release_pod repo:仓库名
3)fastlane release_pod repo:仓库名 project:框架名 version:版本号