fastlane-plugin-increment_version_code 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edd96715880ec66e9519c06c6a12ecfb2368cc1f
4
- data.tar.gz: 3d97edd7c01443a6878a5e02af31cfc11044804f
3
+ metadata.gz: 4861466762cdb494bb1be875b90495e1dc4790a3
4
+ data.tar.gz: b894fe24a67f76def65ca74addedb66881a4a498
5
5
  SHA512:
6
- metadata.gz: 998050bf9ed0cff7c7408f5d4ebeb7ede479366e860892d78ca7254e98b4fa128c0b140b3f9d7f8f86322c6490fbd6374481f22d9c8affb5d7f04fc7229ebb68
7
- data.tar.gz: b22c681ea384f2b7c3cb06ea9d83fc9396ee575636778d9c603a9030ab37e3db5cf14432f70782832610317aaf833280d783808abd36eb82f3bda00f49a4ead2
6
+ metadata.gz: 4f23831ca0b39fc26a1ec79211b6cf3b5615c84cd3d407b5e1b4eaf70b6ae087669e78150c26321a789dc92cccb4a2dc3545faca73f9d037f2a8e8ea97a21550
7
+ data.tar.gz: 28c7f16d273aae9cca2c5bfcda199bc98d83cf2f84585fd21af1461373021438ecc237a30300c1dab0b95f7da64262c8f8081596f8dc3a81523fdaa1b1adc244
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Jérémy TOUDIC <jeremy.toudic@aufeminin.com>
3
+ Copyright (c) 2017 Jérémy TOUDIC <jeremy.toudic@gmail.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -5,68 +5,79 @@ module Fastlane
5
5
  module Actions
6
6
  class IncrementVersionCodeAction < Action
7
7
  def self.run(params)
8
- app_folder_name ||= params[:app_folder_name]
9
- UI.message("The get_version_code plugin is looking inside your project folder (#{app_folder_name})!")
10
8
 
11
9
  version_code = "0"
12
10
  new_version_code ||= params[:version_code]
13
- UI.message("new version code = #{new_version_code}")
14
11
 
15
- temp_file = Tempfile.new('fastlaneIncrementVersionCode')
16
- foundVersionCode = "false"
17
- Dir.glob("**/#{app_folder_name}/build.gradle") do |path|
18
- UI.message(" -> Found a build.gradle file at path: (#{path})!")
19
- begin
20
- temp_file = Tempfile.new('fastlaneIncrementVersionCode')
21
- File.open(path, 'r') do |file|
22
- file.each_line do |line|
23
- if line.include? "versionCode " and foundVersionCode=="false"
12
+ constant_name ||= params[:ext_constant_name]
24
13
 
25
- versionComponents = line.strip.split(' ')
26
- version_code = versionComponents[1].tr("\"","")
27
- if new_version_code <= 0
28
- new_version_code = version_code.to_i + 1
29
- end
30
- if !!(version_code =~ /\A[-+]?[0-9]+\z/)
31
- line.replace line.sub(version_code, new_version_code.to_s)
32
- foundVersionCode = "true"
33
- end
34
- temp_file.puts line
35
- else
36
- temp_file.puts line
37
- end
38
- end
39
-
40
- if foundVersionCode=="true"
41
- break
42
- end
43
- file.close
44
- end
45
- temp_file.rewind
46
- temp_file.close
47
- FileUtils.mv(temp_file.path, path)
48
- temp_file.unlink
49
- ensure
50
- if foundVersionCode=="true"
51
-
52
- break
53
- end
14
+ gradle_file_path ||= params[:gradle_file_path]
15
+ if gradle_file_path != nil
16
+ UI.message("The increment_version_code plugin will use gradle file at (#{gradle_file_path})!")
17
+ new_version_code = incrementVersion(gradle_file_path, new_version_code, constant_name)
18
+ else
19
+ app_folder_name ||= params[:app_folder_name]
20
+ UI.message("The get_version_code plugin is looking inside your project folder (#{app_folder_name})!")
54
21
 
22
+ #temp_file = Tempfile.new('fastlaneIncrementVersionCode')
23
+ #foundVersionCode = "false"
24
+ Dir.glob("**/#{app_folder_name}/build.gradle") do |path|
25
+ UI.message(" -> Found a build.gradle file at path: (#{path})!")
26
+ new_version_code = incrementVersion(path, new_version_code, constant_name)
55
27
  end
56
- end
57
28
 
29
+ end
58
30
 
59
- if version_code == "0" || new_version_code == "1"
60
- UI.user_error!("Impossible to find the version code in the current project folder #{app_folder_name} 😭")
31
+ if new_version_code == -1
32
+ UI.user_error!("Impossible to find the version code with the specified properties 😭")
61
33
  else
62
34
  # Store the version name in the shared hash
63
35
  Actions.lane_context["VERSION_CODE"]=new_version_code
64
- UI.success("☝️ Version code has been changed from #{version_code} to #{new_version_code}")
36
+ UI.success("☝️ Version code has been changed to #{new_version_code}")
65
37
  end
66
38
 
67
39
  return new_version_code
68
40
  end
69
41
 
42
+ def self.incrementVersion(path, new_version_code, constant_name)
43
+ if !File.file?(path)
44
+ UI.message(" -> No file exist at path: (#{path})!")
45
+ return -1
46
+ end
47
+ begin
48
+ foundVersionCode = "false"
49
+ temp_file = Tempfile.new('fastlaneIncrementVersionCode')
50
+ File.open(path, 'r') do |file|
51
+ file.each_line do |line|
52
+ if line.include? constant_name and foundVersionCode=="false"
53
+ UI.message(" -> line: (#{line})!")
54
+ versionComponents = line.strip.split(' ')
55
+ version_code = versionComponents[versionComponents.length-1].tr("\"","")
56
+ if new_version_code <= 0
57
+ new_version_code = version_code.to_i + 1
58
+ end
59
+ if !!(version_code =~ /\A[-+]?[0-9]+\z/)
60
+ line.replace line.sub(version_code, new_version_code.to_s)
61
+ foundVersionCode = "true"
62
+ end
63
+ temp_file.puts line
64
+ else
65
+ temp_file.puts line
66
+ end
67
+ end
68
+ file.close
69
+ end
70
+ temp_file.rewind
71
+ temp_file.close
72
+ FileUtils.mv(temp_file.path, path)
73
+ temp_file.unlink
74
+ end
75
+ if foundVersionCode == "true"
76
+ return new_version_code
77
+ end
78
+ return -1
79
+ end
80
+
70
81
  def self.description
71
82
  "Increment the version code of your android project."
72
83
  end
@@ -83,12 +94,24 @@ module Fastlane
83
94
  optional: true,
84
95
  type: String,
85
96
  default_value:"app"),
97
+ FastlaneCore::ConfigItem.new(key: :gradle_file_path,
98
+ env_name: "INCREMENTVERSIONCODE_GRADLE_FILE_PATH",
99
+ description: "The relative path to the gradle file containing the version code parameter (default:app/build.gradle)",
100
+ optional: true,
101
+ type: String,
102
+ default_value: nil),
86
103
  FastlaneCore::ConfigItem.new(key: :version_code,
87
104
  env_name: "INCREMENTVERSIONCODE_VERSION_CODE",
88
105
  description: "Change to a specific version (optional)",
89
106
  optional: true,
90
107
  type: Integer,
91
- default_value: 0)
108
+ default_value: 0),
109
+ FastlaneCore::ConfigItem.new(key: :ext_constant_name,
110
+ env_name: "INCREMENTVERSIONCODE_EXT_CONSTANT_NAME",
111
+ description: "If the version code is set in an ext constant, specify the constant name (optional)",
112
+ optional: true,
113
+ type: String,
114
+ default_value: "versionCode")
92
115
  ]
93
116
  end
94
117
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module IncrementVersionCode
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-increment_version_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry