Fastlane 自动升级podspec


desc 'ManagerLib 使用这个航道, 可以快速的对自己的私有库, 进行升级维护'
lane :ManagerLib do |options|

tagName = options[:tag]
targetName = options[:target]

# 具体这个巷道上面执行哪些行为

# 1. pod install
cocoapods(
clean: true,
podfile: "./Example/Podfile"
)

# 2. git add .
git_add(path: ".")
#    git commit -m 'xxx'
git_commit(path: ".", message: "版本升级维护")
#    git push origin master
push_to_git_remote

# 验证tag是否存在,如果存在, 应该删除本地标签和远程标签
#if 判断标签是否存在
#    执行删除本地/远程标签
#end

if git_tag_exists(tag: tagName)
    UI.message("发现tag:#{tagName} 已经存在, 即将执行, 删除动作 ")
    remove_tag(tag:tagName)
end


# 3. git tag 标签名称
add_git_tag(
tag: tagName
)
#    git push --tags
push_git_tags

# 4. pod spec lint
# pod_lib_lint(allow_warnings: true)
#    pod repo push XXXX xxx.podspec
pod_push(path: "#{targetName}.podspec", repo: "XMGFMSpecs", allow_warnings: true)


end

自定义action 用于删除本地或远程标签

module Fastlane
  module Actions
    module SharedValues
      REMOVE_TAG_CUSTOM_VALUE = :REMOVE_TAG_CUSTOM_VALUE
    end

    class RemoveTagAction < Action
      def self.run(params)
      
      tagName = params[:tag]
      isRemoveLocalTag = params[:rL]
      isRemoveRemoteTag = params[:rR]
      
      # 1. 先定义一个数组, 用来存储所有需要执行的命令
      
      cmds = []
      
      # 2. 往数组里面, 添加相应的命令
      # 删除本地标签
      # git tag -d 标签名称
      if isRemoveLocalTag
        cmds << "git tag -d #{tagName} "
      end
    
      # 删除远程标签
      # git push origin :标签名称
      if isRemoveRemoteTag
        cmds << " git push origin :#{tagName}"
      end

      #3. 执行数组里面的所有命令
     
      result = Actions.sh(cmds.join('&'));
      return result
      end


      def self.description
        "删除标签"
      end

      def self.details
        # Optional:
        # this is your chance to provide a more detailed description of this action
        "我们可以使用这个action ,来删除本地或者远程标签"
      end

      def self.available_options
        # Define all options your action supports. 
        
        # Below a few examples
        [

                FastlaneCore::ConfigItem.new(key: :tag,
                                             description: "需要被删除的标签名称",
                                             optional: false,
                                             is_string: true),
                FastlaneCore::ConfigItem.new(key: :rL,
                                             description: "是否需要删除本地标签",
                                             optional: true,
                                             is_string: false,
                                             default_value: true),
                FastlaneCore::ConfigItem.new(key: :rR,
                                             description: "是否需要删除远程标签",
                                             optional: true,
                                             is_string: false,
                                             default_value: true)
        ]
      end

      def self.output

      end

      def self.return_value
        nil
      end

      def self.authors
        # So no one will ever forget your contribution to fastlane :) You are awesome btw!
        ["ldh"]
      end

      def self.is_supported?(platform)
        # you can do things like
        # 
        #  true
        # 
        #  platform == :ios
        # 
        #  [:ios, :mac].include?(platform)
        # 

        platform == :ios
      end
    end
  end
end

你可能感兴趣的:(Fastlane 自动升级podspec)