ruby CFBundleVersionを更新するためのFastlane行动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby CFBundleVersionを更新するためのFastlane行动相关的知识,希望对你有一定的参考价值。

module Fastlane
  module Actions
    module SharedValues
      UPDATE_BUNDLE_VERSION = :UPDATE_BUNDLE_VERSION
    end

    class UpdateBundleVersionAction < Action
      def self.run(params)
        begin
          path = File.expand_path(params[:path])
          bundle_version = other_action.get_info_plist_value(
            path: path,
            key: "CFBundleVersion"
          )
          UI.message "Current CFBundleVersion is #{bundle_version}"

          build_number = params[:version_number] || (bundle_version.to_i + 1).to_s

          other_action.set_info_plist_value(
            path: path,
            # output_file_name: "./build/#{path}",
            key: "CFBundleVersion",
            value: build_number
          )
          UI.success "Update CFBundleVersion to #{build_number}"
          Actions.lane_context[SharedValues::UPDATE_BUNDLE_VERSION] = build_number
        rescue => ex
          UI.error(ex)
          UI.user_error!("Unable to set value to plist file at '#{path}'")
        end
      end

      #####################################################
      # @!group Documentation
      #####################################################

      def self.description
        "Update CFBundleVersion in Info.plist"
      end

      def self.details
        "You can use this action to do cool things..."
        [
          "This action will increment the CFBundleVersion.",
          "If you want to remain the original Info.plist, call `backup_file` and `restore_file` actions"
        ].join("\n")
      end

      def self.available_options
        [
          FastlaneCore::ConfigItem.new(key: :path,
                                       env_name: "FL_UPDATE_BUNDLE_VERSION_PATH",
                                       description: "Path to plist file you want to read",
                                       optional: false,
                                       verify_block: proc do |value|
                                         UI.user_error!("Couldn't find plist file at path '#{value}'") unless File.exist?(value)
                                       end),
          FastlaneCore::ConfigItem.new(key: :version_number,
                                       env_name: "FL_UPDATE_BUNDLE_VERSION_VERSION_NUMBER",
                                       description: "Change to a specific version",
                                       optional: true,
                                       is_string: false)
        ]
      end

      def self.output
        [
          ['UPDATE_BUNDLE_VERSION', 'The new CFBundleVersion number']
        ]
      end

      def self.return_value
        'The new CFBundleVersion number'
      end

      def self.authors
        "matsuda"
      end

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

        platform == :ios
      end

      def self.example_code
        [
          'update_bundle_version # Automatically increment CFBundleVersion number',
          'update_bundle_version(path: "./Info.plist") # Automatically increment CFBundleVersion number',
          'update_bundle_version(version_number: 5) # set a specific number',
        ]
      end
    end
  end
end

以上是关于ruby CFBundleVersionを更新するためのFastlane行动的主要内容,如果未能解决你的问题,请参考以下文章

ruby 写真ファイルの作成日/更新日のメタ情报をファイル名から置换する

ruby 动的に方法を追加する模块

ruby 标准出力に変数の内容を展开する

ruby ブロックを处理する关数を书く

ruby RubyでWindowsとUNIXの标准出力とエラー出力を抑止する

ruby lambdaと&演算子でブロック部分を分离する