Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
versionNameを指定したstage名で更新していくactionです
module Fastlane
module Actions
class CommitVersionNameStageBumpAction < Action
PATH = 'app/build.gradle'
def self.run(params)
UI.message "Stage Name: #{params[:stage_name]}"
stage_name = params[:stage_name]
file_string = File.read(PATH)
pattern = /versionName\ "([A-Za-z0-9\-.]+)"/
version_name = file_string[pattern, 1]
UI.message "current version name: #{version_name}"
new_version_name = get_bumped_version_name(version_name, stage_name)
UI.message "new version name: #{new_version_name}"
file_string[pattern, 1] = new_version_name
new_file_string = File.new(PATH, 'w')
new_file_string.write(file_string)
new_file_string.close
commit(new_version_name)
end
def self.get_bumped_version_name(version_name, stage_name)
pattern = /(\d+).(\d+).(\d+)[A-Za-z\-.]*(\d+)?$/
major = version_name[pattern, 1].to_i
minor = version_name[pattern, 2].to_i
patch = version_name[pattern, 3].to_i
# 値が取れなかった場合はnilが返り、to_iで0になる
stage = version_name[pattern, 4].to_i
unless version_name.include? stage_name
stage = 0
end
stage += 1
"#{major}.#{minor}.#{patch}-#{stage_name}.#{stage}"
end
def self.commit(version_name)
Actions.sh("git add #{PATH}")
Actions.sh("git commit -m 'VersionName Bump to #{version_name}'")
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :stage_name,
description: "alphaやbetaなどの名前です",
verify_block: proc do |value|
UI.user_error!("stage_nameを設定して下さい") unless (value and not value.empty?)
end)
]
end
def self.authors
["@mapyo"]
end
def self.is_supported?(platform)
platform == :android
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.