Guest User

Untitled

a guest
Dec 7th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. module Fastlane
  2. module Actions
  3. module SharedValues
  4. ANDROID_VERSION_UP_CUSTOM_VALUE = :ANDROID_VERSION_UP_CUSTOM_VALUE
  5. end
  6.  
  7. class AndroidVersionUpAction < Action
  8.  
  9. def self.run(params)
  10. # fastlane will take care of reading in the parameter and fetching the environment variable:
  11. #UI.message "Parameter API Token: #{params[:api_token]}"
  12. filename = Dir.pwd + params[:filename] #params[:filename]
  13.  
  14. f = File.open(filename, "r")
  15. content = f.read
  16.  
  17. content =~ /.*\b(versionName)\b(.*).*/
  18. versionName = $2.gsub("\"", "").gsub(" ","")
  19.  
  20. content =~ /.*((versionCode)\ (\d+)\n)/
  21. versionCode = $3.to_i
  22.  
  23. puts "versionCode: #{versionCode}\nversionName: #{versionName} "
  24. newVersionCode = versionCode.to_i + 1
  25.  
  26. text = content.gsub(/.*(versionCode)\ (\d+)\n/, "\t\tversionCode #{newVersionCode}\n")
  27. puts "increased version from #{versionCode} number to #{newVersionCode}"
  28.  
  29. File.open(filename, "w") { |file| file << text }
  30.  
  31. return [versionName, newVersionCode]
  32.  
  33. end
  34.  
  35. #####################################################
  36. # @!group Documentation
  37. #####################################################
  38.  
  39. def self.description
  40. "This action increases your App-VersionCode automatically"
  41. end
  42.  
  43. def self.details
  44.  
  45. end
  46.  
  47. def self.available_options
  48. [
  49. FastlaneCore::ConfigItem.new(key: :filename,
  50. env_name: "FL_ANDROID_VERSION_UP_FILENAME", # The name of the environment variable
  51. description: "Gradle Filename for AndroidVersionUpAction (default: /app/build.gradle)", # a short description of this parameter
  52. verify_block: proc do |value|
  53. UI.user_error!("No build.gradle token for AndroidVersionUpAction given, pass using `filename: 'path_to_filename'`") unless (value and not value.empty?)
  54. # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
  55. end)
  56. ]
  57. end
  58.  
  59. def self.output
  60. # Define the shared values you are going to provide
  61. # Example
  62. [
  63. ['FL_ANDROID_VERSION_UP_FILENAME', '/app/build.gradle']
  64. ]
  65. end
  66.  
  67. def self.return_value
  68. # If your method provides a return value, you can describe here what it does
  69. "The return values are [versionName, newVersionCode]"
  70. end
  71.  
  72. def self.authors
  73. # So no one will ever forget your contribution to fastlane :) You are awesome btw!
  74. ["g00m"]
  75. end
  76.  
  77. def self.is_supported?(platform)
  78. platform == :android
  79. end
  80. end
  81. end
  82. end
Add Comment
Please, Sign In to add comment