Skip to content

Instantly share code, notes, and snippets.

@g00m
Last active December 5, 2017 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g00m/501c9bfd506078193263a110fcfe90e1 to your computer and use it in GitHub Desktop.
Save g00m/501c9bfd506078193263a110fcfe90e1 to your computer and use it in GitHub Desktop.
module Fastlane
module Actions
module SharedValues
ANDROID_VERSION_UP_CUSTOM_VALUE = :ANDROID_VERSION_UP_CUSTOM_VALUE
end
class AndroidVersionUpAction < Action
def self.run(params)
# fastlane will take care of reading in the parameter and fetching the environment variable:
#UI.message "Parameter API Token: #{params[:api_token]}"
filename = Dir.pwd + params[:filename] #params[:filename]
f = File.open(filename, "r")
content = f.read
content =~ /.*\b(versionName)\b(.*).*/
versionName = $2.gsub("\"", "").gsub(" ","")
content =~ /.*((versionCode)\ (\d+)\n)/
versionCode = $3.to_i
puts "versionCode: #{versionCode}\nversionName: #{versionName} "
newVersionCode = versionCode.to_i + 1
text = content.gsub(/.*(versionCode)\ (\d+)\n/, "\t\tversionCode #{newVersionCode}\n")
puts "increased version from #{versionCode} number to #{newVersionCode}"
File.open(filename, "w") { |file| file << text }
return [versionName, newVersionCode]
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"This action increases your App-VersionCode automatically"
end
def self.details
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :filename,
env_name: "FL_ANDROID_VERSION_UP_FILENAME", # The name of the environment variable
description: "Gradle Filename for AndroidVersionUpAction (default: /app/build.gradle)", # a short description of this parameter
verify_block: proc do |value|
UI.user_error!("No build.gradle token for AndroidVersionUpAction given, pass using `filename: 'path_to_filename'`") unless (value and not value.empty?)
# UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
end)
]
end
def self.output
# Define the shared values you are going to provide
# Example
[
['FL_ANDROID_VERSION_UP_FILENAME', '/app/build.gradle']
]
end
def self.return_value
# If your method provides a return value, you can describe here what it does
"The return values are [versionName, newVersionCode]"
end
def self.authors
# So no one will ever forget your contribution to fastlane :) You are awesome btw!
["g00m"]
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