Created
September 1, 2017 02:12
-
-
Save matsuda/f9421a61c56702cf0759879112e88eee to your computer and use it in GitHub Desktop.
CFBundleVersionを更新するためのFastlane action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment