fastlane-plugin-android_versioning_kts 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,92 +1,92 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tempfile'
4
- require 'fileutils'
5
-
6
- module Fastlane
7
- module Actions
8
- module SharedValues
9
- VERSION_CODE = :VERSION_CODE
10
- end
11
-
12
- class IncrementVersionCodeAction < Action
13
- def self.run(params)
14
- current_version_code = GetVersionCodeAction.run(params)
15
-
16
- new_version_code =
17
- if params[:version_code].nil?
18
- current_version_code.to_i + 1
19
- elsif params[:version_code] == -1
20
- ((Time.now.to_f * 1000).to_i / (60 * 1000)).to_i
21
- else
22
- params[:version_code].to_i
23
- end
24
-
25
- SetValueInBuildAction.run(
26
- app_project_dir: params[:app_project_dir],
27
- flavor: params[:flavor],
28
- key: 'versionCode',
29
- value: new_version_code
30
- )
31
- Actions.lane_context[SharedValues::VERSION_CODE] = new_version_code.to_s
32
- new_version_code.to_s
33
- end
34
-
35
- #####################################################
36
- # @!group Documentation
37
- #####################################################
38
- def self.available_options
39
- [
40
- FastlaneCore::ConfigItem.new(
41
- key: :app_project_dir,
42
- env_name: 'ANDROID_VERSIONING_APP_PROJECT_DIR',
43
- description: 'The path to the application source folder
44
- in the Android project (default: android/app)',
45
- optional: true,
46
- type: String,
47
- default_value: 'android/app'
48
- ),
49
- FastlaneCore::ConfigItem.new(
50
- key: :flavor,
51
- env_name: 'ANDROID_VERSIONING_FLAVOR',
52
- description: 'The product flavor name (optional)',
53
- optional: true,
54
- type: String
55
- ),
56
- FastlaneCore::ConfigItem.new(
57
- key: :version_code,
58
- env_name: 'ANDROID_VERSIONING_VERSION_CODE',
59
- description: 'Change to a specific version (optional)',
60
- optional: true,
61
- type: Integer
62
- )
63
- ]
64
- end
65
-
66
- def self.description
67
- 'Increment the version code of your project'
68
- end
69
-
70
- def self.details
71
- [
72
- 'This action will increment the version code directly
73
- in build.gradle.kts'
74
- ].join("\n")
75
- end
76
-
77
- def self.output
78
- [
79
- ['VERSION_CODE', 'The new version code']
80
- ]
81
- end
82
-
83
- def self.authors
84
- ['Manabu OHTAKE']
85
- end
86
-
87
- def self.is_supported?(platform)
88
- platform == :android
89
- end
90
- end
91
- end
92
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
6
+ module Fastlane
7
+ module Actions
8
+ module SharedValues
9
+ VERSION_CODE = :VERSION_CODE
10
+ end
11
+
12
+ class IncrementVersionCodeAction < Action
13
+ def self.run(params)
14
+ current_version_code = GetVersionCodeAction.run(params)
15
+
16
+ new_version_code =
17
+ if params[:version_code].nil?
18
+ current_version_code.to_i + 1
19
+ elsif params[:version_code] == -1
20
+ ((Time.now.to_f * 1000).to_i / (60 * 1000)).to_i
21
+ else
22
+ params[:version_code].to_i
23
+ end
24
+
25
+ SetValueInBuildAction.run(
26
+ app_project_dir: params[:app_project_dir],
27
+ flavor: params[:flavor],
28
+ key: 'versionCode',
29
+ value: new_version_code
30
+ )
31
+ Actions.lane_context[SharedValues::VERSION_CODE] = new_version_code.to_s
32
+ new_version_code.to_s
33
+ end
34
+
35
+ #####################################################
36
+ # @!group Documentation
37
+ #####################################################
38
+ def self.available_options
39
+ [
40
+ FastlaneCore::ConfigItem.new(
41
+ key: :app_project_dir,
42
+ env_name: 'ANDROID_VERSIONING_APP_PROJECT_DIR',
43
+ description: 'The path to the application source folder
44
+ in the Android project (default: android/app)',
45
+ optional: true,
46
+ type: String,
47
+ default_value: 'android/app'
48
+ ),
49
+ FastlaneCore::ConfigItem.new(
50
+ key: :flavor,
51
+ env_name: 'ANDROID_VERSIONING_FLAVOR',
52
+ description: 'The product flavor name (optional)',
53
+ optional: true,
54
+ type: String
55
+ ),
56
+ FastlaneCore::ConfigItem.new(
57
+ key: :version_code,
58
+ env_name: 'ANDROID_VERSIONING_VERSION_CODE',
59
+ description: 'Change to a specific version (optional)',
60
+ optional: true,
61
+ type: Integer
62
+ )
63
+ ]
64
+ end
65
+
66
+ def self.description
67
+ 'Increment the version code of your project'
68
+ end
69
+
70
+ def self.details
71
+ [
72
+ 'This action will increment the version code directly
73
+ in build.gradle.kts'
74
+ ].join("\n")
75
+ end
76
+
77
+ def self.output
78
+ [
79
+ ['VERSION_CODE', 'The new version code']
80
+ ]
81
+ end
82
+
83
+ def self.authors
84
+ ['Manabu OHTAKE']
85
+ end
86
+
87
+ def self.is_supported?(platform)
88
+ platform == :android
89
+ end
90
+ end
91
+ end
92
+ end
@@ -1,125 +1,125 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tempfile'
4
- require 'fileutils'
5
-
6
- module Fastlane
7
- module Actions
8
- module SharedValues
9
- VERSION_NAME = :VERSION_NAME
10
- end
11
-
12
- class IncrementVersionNameAction < Action
13
- def self.run(params)
14
- if params[:version_name].nil? || params[:version_name].empty?
15
- current_version = GetVersionNameAction.run(params)
16
- unless current_version =~ /\d+.\d+.\d+/
17
- UI.user_error!(
18
- "Your current version (#{current_version})
19
- does not respect the format A.B.C"
20
- )
21
- end
22
- version = current_version.split('.').map(&:to_i)
23
- case params[:bump_type]
24
- when 'patch'
25
- version[2] = version[2] + 1
26
- new_version = version.join('.')
27
- when 'minor'
28
- version[1] = version[1] + 1
29
- version[2] = version[2] = 0
30
- new_version = version.join('.')
31
- when 'major'
32
- version[0] = version[0] + 1
33
- version[1] = 0
34
- version[2] = 0
35
- new_version = version.join('.')
36
- end
37
- else
38
- new_version = params[:version_name]
39
- end
40
- SetValueInBuildAction.run(
41
- app_project_dir: params[:app_project_dir],
42
- flavor: params[:flavor],
43
- key: 'versionName',
44
- value: new_version
45
- )
46
- Actions.lane_context[SharedValues::VERSION_NAME] = new_version
47
- new_version
48
- end
49
-
50
- #####################################################
51
- # @!group Documentation
52
- #####################################################
53
- def self.available_options
54
- [
55
- FastlaneCore::ConfigItem.new(
56
- key: :app_project_dir,
57
- env_name: 'ANDROID_VERSIONING_APP_PROJECT_DIR',
58
- description: 'The path to the application source folder
59
- in the Android project (default: android/app)',
60
- optional: true,
61
- type: String,
62
- default_value: 'android/app'
63
- ),
64
- FastlaneCore::ConfigItem.new(
65
- key: :flavor,
66
- env_name: 'ANDROID_VERSIONING_FLAVOR',
67
- description: 'The product flavor name (optional)',
68
- optional: true,
69
- type: String
70
- ),
71
- FastlaneCore::ConfigItem.new(
72
- key: :bump_type,
73
- env_name: 'ANDROID_VERSIONING_BUMP_TYPE',
74
- description: 'Change to a specific type (optional)',
75
- optional: true,
76
- type: String,
77
- default_value: 'patch',
78
- verify_block:
79
- proc do |value|
80
- unless %w[
81
- patch minor major
82
- ].include? value
83
- UI.user_error!(
84
- "Available values are 'patch', 'minor' and 'major'"
85
- )
86
- end
87
- end
88
- ),
89
- FastlaneCore::ConfigItem.new(
90
- key: :version_name,
91
- env_name: 'ANDROID_VERSIONING_VERSION_NAME',
92
- description: 'Change to a specific version (optional)',
93
- optional: true,
94
- type: String
95
- )
96
- ]
97
- end
98
-
99
- def self.description
100
- 'Increment the version name of your project'
101
- end
102
-
103
- def self.details
104
- [
105
- 'This action will increment the version name directly
106
- in build.gradle.kts'
107
- ].join("\n")
108
- end
109
-
110
- def self.output
111
- [
112
- ['VERSION_NAME', 'The new version name']
113
- ]
114
- end
115
-
116
- def self.authors
117
- ['Manabu OHTAKE']
118
- end
119
-
120
- def self.is_supported?(platform)
121
- platform == :android
122
- end
123
- end
124
- end
125
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
6
+ module Fastlane
7
+ module Actions
8
+ module SharedValues
9
+ VERSION_NAME = :VERSION_NAME
10
+ end
11
+
12
+ class IncrementVersionNameAction < Action
13
+ def self.run(params)
14
+ if params[:version_name].nil? || params[:version_name].empty?
15
+ current_version = GetVersionNameAction.run(params)
16
+ unless current_version =~ /\d+.\d+.\d+/
17
+ UI.user_error!(
18
+ "Your current version (#{current_version})
19
+ does not respect the format A.B.C"
20
+ )
21
+ end
22
+ version = current_version.split('.').map(&:to_i)
23
+ case params[:bump_type]
24
+ when 'patch'
25
+ version[2] = version[2] + 1
26
+ new_version = version.join('.')
27
+ when 'minor'
28
+ version[1] = version[1] + 1
29
+ version[2] = version[2] = 0
30
+ new_version = version.join('.')
31
+ when 'major'
32
+ version[0] = version[0] + 1
33
+ version[1] = 0
34
+ version[2] = 0
35
+ new_version = version.join('.')
36
+ end
37
+ else
38
+ new_version = params[:version_name]
39
+ end
40
+ SetValueInBuildAction.run(
41
+ app_project_dir: params[:app_project_dir],
42
+ flavor: params[:flavor],
43
+ key: 'versionName',
44
+ value: new_version
45
+ )
46
+ Actions.lane_context[SharedValues::VERSION_NAME] = new_version
47
+ new_version
48
+ end
49
+
50
+ #####################################################
51
+ # @!group Documentation
52
+ #####################################################
53
+ def self.available_options
54
+ [
55
+ FastlaneCore::ConfigItem.new(
56
+ key: :app_project_dir,
57
+ env_name: 'ANDROID_VERSIONING_APP_PROJECT_DIR',
58
+ description: 'The path to the application source folder
59
+ in the Android project (default: android/app)',
60
+ optional: true,
61
+ type: String,
62
+ default_value: 'android/app'
63
+ ),
64
+ FastlaneCore::ConfigItem.new(
65
+ key: :flavor,
66
+ env_name: 'ANDROID_VERSIONING_FLAVOR',
67
+ description: 'The product flavor name (optional)',
68
+ optional: true,
69
+ type: String
70
+ ),
71
+ FastlaneCore::ConfigItem.new(
72
+ key: :bump_type,
73
+ env_name: 'ANDROID_VERSIONING_BUMP_TYPE',
74
+ description: 'Change to a specific type (optional)',
75
+ optional: true,
76
+ type: String,
77
+ default_value: 'patch',
78
+ verify_block:
79
+ proc do |value|
80
+ unless %w[
81
+ patch minor major
82
+ ].include? value
83
+ UI.user_error!(
84
+ "Available values are 'patch', 'minor' and 'major'"
85
+ )
86
+ end
87
+ end
88
+ ),
89
+ FastlaneCore::ConfigItem.new(
90
+ key: :version_name,
91
+ env_name: 'ANDROID_VERSIONING_VERSION_NAME',
92
+ description: 'Change to a specific version (optional)',
93
+ optional: true,
94
+ type: String
95
+ )
96
+ ]
97
+ end
98
+
99
+ def self.description
100
+ 'Increment the version name of your project'
101
+ end
102
+
103
+ def self.details
104
+ [
105
+ 'This action will increment the version name directly
106
+ in build.gradle.kts'
107
+ ].join("\n")
108
+ end
109
+
110
+ def self.output
111
+ [
112
+ ['VERSION_NAME', 'The new version name']
113
+ ]
114
+ end
115
+
116
+ def self.authors
117
+ ['Manabu OHTAKE']
118
+ end
119
+
120
+ def self.is_supported?(platform)
121
+ platform == :android
122
+ end
123
+ end
124
+ end
125
+ end
@@ -1,115 +1,126 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tempfile'
4
- require 'fileutils'
5
-
6
- module Fastlane
7
- module Actions
8
- class SetValueInBuildAction < Action
9
- def self.run(params)
10
- app_project_dir ||= params[:app_project_dir]
11
- regex = /
12
- (?<key>#{params[:key]}\s*=\s*)
13
- (?<left>['"]?)
14
- (?<value>[a-zA-Z0-9._]*)
15
- (?<right>['"]?)
16
- (?<comment>.*)
17
- /x
18
- flavor = params[:flavor]
19
- flavor_specified = !(flavor.nil? or flavor.empty?)
20
- regex_flavor = /[ \t]create\("#{flavor}"\)[ \t]/
21
- found = false
22
- product_flavors_section = false
23
- flavor_found = false
24
- Dir.glob("#{app_project_dir}/build.gradle.kts") do |path|
25
- temp_file = Tempfile.new('versioning')
26
- File.open(path, 'r') do |file|
27
- file.each_line do |line|
28
- if flavor_specified && !product_flavors_section
29
- unless line.include?('productFlavors') || product_flavors_section
30
- temp_file.puts line
31
- next
32
- end
33
- product_flavors_section = true
34
- end
35
-
36
- if flavor_specified && !flavor_found
37
- unless line.match(regex_flavor)
38
- temp_file.puts line
39
- next
40
- end
41
- flavor_found = true
42
- end
43
-
44
- unless line.match(regex) && !found
45
- temp_file.puts line
46
- next
47
- end
48
- line = line.gsub regex,
49
- "\\k<key>\\k<left>#{params[:value]}\\k<right>\\k<comment>"
50
- found = true
51
- temp_file.puts line
52
- end
53
- file.close
54
- end
55
- temp_file.rewind
56
- temp_file.close
57
- FileUtils.mv(temp_file.path, path)
58
- temp_file.unlink
59
- end
60
- end
61
-
62
- #####################################################
63
- # @!group Documentation
64
- #####################################################
65
- def self.available_options
66
- [
67
- FastlaneCore::ConfigItem.new(
68
- key: :app_project_dir,
69
- env_name: 'ANDROID_VERSIONING_APP_PROJECT_DIR',
70
- description: 'The path to the application source folder
71
- in the Android project (default: android/app)',
72
- optional: true,
73
- type: String,
74
- default_value: 'android/app'
75
- ),
76
- FastlaneCore::ConfigItem.new(
77
- key: :flavor,
78
- env_name: 'ANDROID_VERSIONING_FLAVOR',
79
- description: 'The product flavor name (optional)',
80
- optional: true,
81
- type: String
82
- ),
83
- FastlaneCore::ConfigItem.new(
84
- key: :key,
85
- description: 'The property key',
86
- type: String
87
- ),
88
- FastlaneCore::ConfigItem.new(
89
- key: :value,
90
- description: 'The property value',
91
- type: String
92
- )
93
- ]
94
- end
95
-
96
- def self.description
97
- 'Set the value of your project'
98
- end
99
-
100
- def self.details
101
- [
102
- 'This action will set the value directly in build.gradle.kts '
103
- ].join("\n")
104
- end
105
-
106
- def self.authors
107
- ['Manabu OHTAKE']
108
- end
109
-
110
- def self.is_supported?(platform)
111
- platform == :android
112
- end
113
- end
114
- end
115
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
6
+ module Fastlane
7
+ module Actions
8
+ class SetValueInBuildAction < Action
9
+ def self.run(params)
10
+ app_project_dir ||= params[:app_project_dir]
11
+ regex = /
12
+ (?<key>#{params[:key]}\s*=\s*)
13
+ (?<left>['"]?)
14
+ (?<value>[a-zA-Z0-9._]*)
15
+ (?<right>['"]?)
16
+ (?<comment>.*)
17
+ /x
18
+ flavor = params[:flavor]
19
+ flavor_specified = !(flavor.nil? || flavor.empty?)
20
+ regex_flavor = /[ \t]create\("#{flavor}"\)[ \t]/
21
+ found = false
22
+ product_flavors_section = false
23
+ flavor_found = false
24
+ Dir.glob("#{app_project_dir}/build.gradle.kts") do |path|
25
+ temp_file = Tempfile.new('versioning')
26
+ File.open(path, 'r') do |file|
27
+ file.each_line do |line|
28
+ if flavor_specified && !product_flavors_section
29
+ unless line.include?('productFlavors') || product_flavors_section
30
+ temp_file.puts line
31
+ next
32
+ end
33
+ product_flavors_section = true
34
+ end
35
+
36
+ if flavor_specified && !flavor_found
37
+ unless line.match(regex_flavor)
38
+ temp_file.puts line
39
+ next
40
+ end
41
+ flavor_found = true
42
+ end
43
+
44
+ unless line.match(regex) && !found
45
+ temp_file.puts line
46
+ next
47
+ end
48
+ line = line.gsub regex,
49
+ "\\k<key>\\k<left>#{params[:value]}\\k<right>\\k<comment>"
50
+ found = true
51
+ temp_file.puts line
52
+ end
53
+ file.close
54
+ end
55
+ temp_file.rewind
56
+ temp_file.close
57
+
58
+ begin
59
+ FileUtils.mv(temp_file.path, path)
60
+ rescue => ex
61
+ if ex.message.to_s.include? 'Operation not permitted'
62
+ FileUtils.cp(temp_file.path, path)
63
+ FileUtils.rm(temp_file.path)
64
+ else
65
+ raise ex
66
+ end
67
+ end
68
+
69
+ temp_file.unlink
70
+ end
71
+ end
72
+
73
+ #####################################################
74
+ # @!group Documentation
75
+ #####################################################
76
+ def self.available_options
77
+ [
78
+ FastlaneCore::ConfigItem.new(
79
+ key: :app_project_dir,
80
+ env_name: 'ANDROID_VERSIONING_APP_PROJECT_DIR',
81
+ description: 'The path to the application source folder
82
+ in the Android project (default: android/app)',
83
+ optional: true,
84
+ type: String,
85
+ default_value: 'android/app'
86
+ ),
87
+ FastlaneCore::ConfigItem.new(
88
+ key: :flavor,
89
+ env_name: 'ANDROID_VERSIONING_FLAVOR',
90
+ description: 'The product flavor name (optional)',
91
+ optional: true,
92
+ type: String
93
+ ),
94
+ FastlaneCore::ConfigItem.new(
95
+ key: :key,
96
+ description: 'The property key',
97
+ type: String
98
+ ),
99
+ FastlaneCore::ConfigItem.new(
100
+ key: :value,
101
+ description: 'The property value',
102
+ type: String
103
+ )
104
+ ]
105
+ end
106
+
107
+ def self.description
108
+ 'Set the value of your project'
109
+ end
110
+
111
+ def self.details
112
+ [
113
+ 'This action will set the value directly in build.gradle.kts '
114
+ ].join("\n")
115
+ end
116
+
117
+ def self.authors
118
+ ['Manabu OHTAKE']
119
+ end
120
+
121
+ def self.is_supported?(platform)
122
+ platform == :android
123
+ end
124
+ end
125
+ end
126
+ end