Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment