fastlane-plugin-wpmreleasetoolkit 9.0.0 → 9.1.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_update_metadata_source_action.rb +7 -5
  3. data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/copy_branch_protection_action.rb +80 -0
  4. data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb +3 -1
  5. data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/{removebranchprotection_action.rb → remove_branch_protection_action.rb} +24 -17
  6. data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_branch_protection_action.rb +153 -0
  7. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb +49 -4
  8. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/metadata_block.rb +20 -0
  9. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/release_note_metadata_block.rb +72 -0
  10. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/release_note_short_metadata_block.rb +23 -0
  11. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/standard_metadata_block.rb +47 -0
  12. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/unknown_metadata_block.rb +13 -0
  13. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata/whats_new_metadata_block.rb +53 -0
  14. data/lib/fastlane/plugin/wpmreleasetoolkit/models/app_version.rb +36 -0
  15. data/lib/fastlane/plugin/wpmreleasetoolkit/models/build_code.rb +27 -0
  16. data/lib/fastlane/plugin/wpmreleasetoolkit/version.rb +1 -1
  17. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/abstract_version_calculator.rb +85 -0
  18. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/date_build_code_calculator.rb +32 -0
  19. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/date_version_calculator.rb +37 -0
  20. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/marketing_version_calculator.rb +26 -0
  21. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/semantic_version_calculator.rb +21 -0
  22. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/simple_build_code_calculator.rb +22 -0
  23. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb +76 -0
  24. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/ios_version_file.rb +64 -0
  25. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/abstract_version_formatter.rb +27 -0
  26. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/derived_build_code_formatter.rb +33 -0
  27. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/four_part_build_code_formatter.rb +22 -0
  28. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/four_part_version_formatter.rb +35 -0
  29. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/rc_notation_version_formatter.rb +65 -0
  30. data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/simple_build_code_formatter.rb +20 -0
  31. data/lib/fastlane/plugin/wpmreleasetoolkit.rb +1 -1
  32. metadata +41 -6
  33. data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setbranchprotection_action.rb +0 -63
  34. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/an_metadata_update_helper.rb +0 -152
  35. data/lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_update_helper.rb +0 -182
@@ -0,0 +1,36 @@
1
+ module Fastlane
2
+ module Models
3
+ # The AppVersion model represents a version of an app with major, minor, patch, and build number components.
4
+ class AppVersion
5
+ attr_accessor :major, :minor, :patch, :build_number
6
+
7
+ # Initializes a new AppVersion instance.
8
+ #
9
+ # @param [Integer] major The major version number.
10
+ # @param [Integer] minor The minor version number.
11
+ # @param [Integer] patch The patch version number.
12
+ # @param [Integer] build_number The build number.
13
+ #
14
+ def initialize(major, minor, patch = 0, build_number = 0)
15
+ # Validate that the major and minor version numbers are not nil
16
+ UI.user_error!('Major version cannot be nil') if major.nil?
17
+ UI.user_error!('Minor version cannot be nil') if minor.nil?
18
+
19
+ @major = major
20
+ @minor = minor
21
+ @patch = patch
22
+ @build_number = build_number
23
+ end
24
+
25
+ # Converts the AppVersion object to a string representation.
26
+ # This should only be used for internal debugging/testing purposes, not to write versions in version files
27
+ # In order to format an `AppVersion` into a `String`, you should use the appropriate `VersionFormatter` for your project instead.
28
+ #
29
+ # @return [String] a string in the format "major.minor.patch.build_number".
30
+ #
31
+ def to_s
32
+ "#{@major}.#{@minor}.#{@patch}.#{@build_number}"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ module Fastlane
2
+ module Models
3
+ # The `BuildCode` model represents a build code for an app. This could be the Version Code for an Android app or
4
+ # the VERSION_LONG/BUILD_NUMBER for an iOS/Mac app.
5
+ class BuildCode
6
+ attr_accessor :build_code
7
+
8
+ # Initializes a new BuildCode instance with the provided build code value.
9
+ #
10
+ # @param build_code [String] The build code value.
11
+ #
12
+ def initialize(build_code)
13
+ UI.user_error!('Build code cannot be nil') if build_code.nil?
14
+
15
+ @build_code = build_code
16
+ end
17
+
18
+ # Returns the build code as a string.
19
+ #
20
+ # @return [String] The build code represented as a string.
21
+ #
22
+ def to_s
23
+ @build_code.to_s
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fastlane
4
4
  module Wpmreleasetoolkit
5
- VERSION = '9.0.0'
5
+ VERSION = '9.1.0'
6
6
  end
7
7
  end
@@ -0,0 +1,85 @@
1
+ module Fastlane
2
+ module Wpmreleasetoolkit
3
+ module Versioning
4
+ # The `AbstractVersionCalculator` class is responsible for performing version calculations and transformations. It can be used
5
+ # as a base class for version calculations that use different versioning schemes. It contains calculation and
6
+ # transformation methods that are shared by all platforms. It has the abstract suffix because it should not be
7
+ # instantiated directly.
8
+ class AbstractVersionCalculator
9
+ # This method increments the major version component and resets minor, patch, and build number
10
+ # components to zero.
11
+ #
12
+ # @param version [AppVersion] The version to calculate the next major version for.
13
+ #
14
+ # @return [AppVersion] The next major version.
15
+ #
16
+ def next_major_version(version:)
17
+ new_version = version.dup
18
+ new_version.major += 1
19
+ new_version.minor = 0
20
+ new_version.patch = 0
21
+ new_version.build_number = 0
22
+
23
+ new_version
24
+ end
25
+
26
+ # This method increments the minor version component and resets patch and build number components
27
+ # to zero.
28
+ #
29
+ # @param version [AppVersion] The version to calculate the next minor version for.
30
+ #
31
+ # @return [AppVersion] The next minor version.
32
+ #
33
+ def next_minor_version(version:)
34
+ new_version = version.dup
35
+ new_version.minor += 1
36
+ new_version.patch = 0
37
+ new_version.build_number = 0
38
+
39
+ new_version
40
+ end
41
+
42
+ # This method increments the patch version component and resets the build number component to zero.
43
+ #
44
+ # @param version [AppVersion] The version to calculate the next patch version for.
45
+ #
46
+ # @return [AppVersion] The next patch version.
47
+ #
48
+ def next_patch_version(version:)
49
+ new_version = version.dup
50
+ new_version.patch += 1
51
+ new_version.build_number = 0
52
+
53
+ new_version
54
+ end
55
+
56
+ # This method increments the build number component.
57
+ #
58
+ # @param version [AppVersion] The version to calculate the next build number for.
59
+ #
60
+ # @return [AppVersion] The next version with an incremented build number.
61
+ #
62
+ def next_build_number(version:)
63
+ new_version = version.dup
64
+ new_version.build_number += 1
65
+
66
+ new_version
67
+ end
68
+
69
+ # Calculate the previous patch version by decrementing the patch version if it's not zero.
70
+ #
71
+ # @param [AppVersion] version The version to calculate the previous patch version for.
72
+ #
73
+ # @return [AppVersion] The previous patch version.
74
+ #
75
+ def previous_patch_version(version:)
76
+ new_version = version.dup
77
+ new_version.patch -= 1 unless version.patch.zero?
78
+ new_version.build_number = 0
79
+
80
+ new_version
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,32 @@
1
+ module Fastlane
2
+ module Wpmreleasetoolkit
3
+ module Versioning
4
+ # The `DateBuildCodeCalculator` class is a build code calculator for apps that use date-based
5
+ # build codes.
6
+ class DateBuildCodeCalculator
7
+ # Calculate the next internal build code by setting the build number to the current date.
8
+ #
9
+ # @param [AppVersion] version The version to calculate the next internal version for.
10
+ #
11
+ # @return [AppVersion] The next version with the build number set to the current date.
12
+ #
13
+ def next_build_code(version:)
14
+ new_version = version.dup
15
+ new_version.build_number = today_date
16
+
17
+ new_version
18
+ end
19
+
20
+ private
21
+
22
+ # Get the current date in the format 'YYYYMMDD'.
23
+ #
24
+ # @return [String] The current date in 'YYYYMMDD' format.
25
+ #
26
+ def today_date
27
+ DateTime.now.strftime('%Y%m%d')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'abstract_version_calculator'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `DateVersionCalculator` class is a specialized version calculator for date-based versions
7
+ # of an app, extending the `AbstractVersionCalculator` class.
8
+ class DateVersionCalculator < AbstractVersionCalculator
9
+ # Calculate the next date-based release version.
10
+ #
11
+ # If the current month is December, the method prompts the user to determine if the next
12
+ # release will be the first release of the next year. If so, it increments the major version
13
+ # and sets the minor version to 1, resetting the patch and build number components to zero.
14
+ # Otherwise, it calculates the next minor version.
15
+ #
16
+ # @param [AppVersion] version The version to calculate the next date-based release version for.
17
+ #
18
+ # @return [AppVersion] The next date-based release version.
19
+ #
20
+ def next_release_version(version:)
21
+ new_version = version.dup
22
+ first_release_of_year = FastlaneCore::UI.confirm('Is this release the first release of next year?') if Time.now.month == 12
23
+ if first_release_of_year
24
+ new_version.major += 1
25
+ new_version.minor = 1
26
+ new_version.patch = 0
27
+ new_version.build_number = 0
28
+
29
+ new_version
30
+ else
31
+ next_minor_version(version: version)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'abstract_version_calculator'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `MarketingVersionCalculator` class is a specialized version calculator for marketing versions
7
+ # of an app, extending the `AbstractVersionCalculator` class.
8
+ class MarketingVersionCalculator < AbstractVersionCalculator
9
+ # Calculate the next marketing release version.
10
+ #
11
+ # This method checks if the minor version is 9. If it is, it calculates the next major version.
12
+ # Otherwise, it calculates the next minor version. The patch and build number components are reset to zero.
13
+ #
14
+ # @param [AppVersion] version The version to calculate the next marketing release version for.
15
+ #
16
+ # @return [AppVersion] The next marketing release version.
17
+ #
18
+ def next_release_version(version:)
19
+ UI.user_error!('Marketing Versioning: The minor version cannot be greater than 9') if version.minor > 9
20
+
21
+ version.minor == 9 ? next_major_version(version: version) : next_minor_version(version: version)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'abstract_version_calculator'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `SemanticVersionCalculator` class is a specialized version calculator for semantic versions
7
+ # of an app, extending the `AbstractVersionCalculator` class.
8
+ class SemanticVersionCalculator < AbstractVersionCalculator
9
+ # Calculate the next semantic release version.
10
+ #
11
+ # @param [AppVersion] version The version to calculate the next semantic release version from.
12
+ #
13
+ # @return [AppVersion] The next semantic release version.
14
+ #
15
+ def next_release_version(version:)
16
+ next_minor_version(version: version)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module Fastlane
2
+ module Wpmreleasetoolkit
3
+ module Versioning
4
+ # The `SimpleBuildCodeCalculator` class is a build code calculator for apps that use simple integer
5
+ # build codes.
6
+ class SimpleBuildCodeCalculator
7
+ # Calculate the next build code.
8
+ #
9
+ # This method increments the build code value by 1.
10
+ #
11
+ # @param [BuildCode] version The build code to increment.
12
+ #
13
+ # @return [BuildCode] The next build code.
14
+ #
15
+ def next_build_code(build_code:)
16
+ new_build_code = build_code.dup
17
+ new_build_code.build_code += 1
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,76 @@
1
+ require 'java-properties'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `AndroidVersionFile` class takes in a version.properties file path and reads/writes values to/from the file.
7
+ class AndroidVersionFile
8
+ attr_reader :version_properties_path
9
+
10
+ # Initializes a new instance of AndroidVersionFile with the specified version.properties file path.
11
+ #
12
+ # @param [String] version_properties_path The path to the version.properties file.
13
+ #
14
+ def initialize(version_properties_path: 'version.properties')
15
+ UI.user_error!("version.properties not found at this path: #{version_properties_path}") unless File.exist?(version_properties_path)
16
+
17
+ @version_properties_path = version_properties_path
18
+ end
19
+
20
+ # Reads the version name from a version.properties file.
21
+ #
22
+ # @return [String] The version name read from the file.
23
+ #
24
+ # @raise [UI::Error] If the file_path is nil or the version name is not found.
25
+ #
26
+ def read_version_name
27
+ # Read the version name from the version.properties file
28
+ file_content = JavaProperties.load(version_properties_path)
29
+ version_name = file_content[:versionName]
30
+ UI.user_error!('Version name not found in version.properties') if version_name.nil?
31
+
32
+ version_name
33
+ end
34
+
35
+ # Reads the version code from a version.properties file.
36
+ #
37
+ # @param [String] file_path The path to the version.properties file.
38
+ #
39
+ # @return [BuildCode] An instance of `BuildCode` representing the version code read from the file.
40
+ #
41
+ # @raise [UI::Error] If the file_path is nil or the version code is not found.
42
+ #
43
+ def read_version_code
44
+ # Read the version code from the version.properties file
45
+ file_content = JavaProperties.load(version_properties_path)
46
+ version_code = file_content[:versionCode]
47
+ UI.user_error!('Version code not found in version.properties') if version_code.nil?
48
+
49
+ # Create a BuildCode object
50
+ Fastlane::Models::BuildCode.new(version_code.to_i)
51
+ end
52
+
53
+ # Writes the provided version name and version code to the version.properties file.
54
+ #
55
+ # @param [String] version_name The version name to write to the file.
56
+ # @param [String] version_code The version code to write to the file.
57
+ #
58
+ # @raise [UI::Error] If the version name or version code is nil.
59
+ #
60
+ def write_version(version_name:, version_code:)
61
+ # Create the version name and version code hash
62
+ version = {
63
+ versionName: version_name,
64
+ versionCode: version_code
65
+ }
66
+
67
+ # Write the version name and version code hash to the version.properties file
68
+ JavaProperties.write(
69
+ version,
70
+ version_properties_path
71
+ )
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,64 @@
1
+ require 'xcodeproj'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `IOSVersionFile` class takes in an .xcconfig file path and reads/writes values to/from the file.
7
+ class IOSVersionFile
8
+ attr_reader :xcconfig_path
9
+
10
+ # Initializes a new instance of IOSVersionFile with the specified .xcconfig file path.
11
+ #
12
+ # @param [String] xcconfig_path The path to the .xcconfig file.
13
+ #
14
+ def initialize(xcconfig_path:)
15
+ UI.user_error!(".xcconfig file not found at this path: #{xcconfig_path}") unless File.exist?(xcconfig_path)
16
+
17
+ @xcconfig_path = xcconfig_path
18
+ end
19
+
20
+ # Reads the release version from the .xcconfig file and returns it as a String.
21
+ #
22
+ # @return [String] The release version.
23
+ #
24
+ def read_release_version
25
+ config = Xcodeproj::Config.new(xcconfig_path)
26
+ config.attributes['VERSION_SHORT']
27
+ end
28
+
29
+ # Reads the build code from the .xcconfig file and returns it String.
30
+ #
31
+ # Some apps store the build code in the VERSION_LONG attribute, while others store it in the BUILD_NUMBER attribute.
32
+ #
33
+ # @param [String] attribute_name The name of the attribute to read.
34
+ #
35
+ # @return [String] The build code.
36
+ #
37
+ def read_build_code(attribute_name:)
38
+ UI.user_error!('attribute_name must be `VERSION_LONG` or `BUILD_NUMBER`') unless attribute_name.eql?('VERSION_LONG') || attribute_name.eql?('BUILD_NUMBER')
39
+
40
+ config = Xcodeproj::Config.new(xcconfig_path)
41
+ config.attributes[attribute_name]
42
+ end
43
+
44
+ # Writes the provided version numbers to the .xcconfig file.
45
+ #
46
+ # @param [String, nil] version_short The short version string (optional).
47
+ # @param [String, nil] version_long The long version string (optional).
48
+ # @param [String, nil] build_number The build number (optional).
49
+ #
50
+ # version_long is optional because there are times when it won't be updated, such as a new beta build.
51
+ # version_short is optional because some apps (such as Day One iOS/Mac or Simplenote Mac) don't use it.
52
+ # build_number is optional because some apps (such as WP/JP iOS or WCiOS) don't use it.
53
+ #
54
+ def write(version_short: nil, version_long: nil, build_number: nil)
55
+ config = Xcodeproj::Config.new(xcconfig_path)
56
+ config.attributes['VERSION_SHORT'] = version_short.to_s unless version_short.nil?
57
+ config.attributes['VERSION_LONG'] = version_long.to_s unless version_long.nil?
58
+ config.attributes['BUILD_NUMBER'] = build_number.to_s unless build_number.nil?
59
+ config.save_as(Pathname.new(xcconfig_path))
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,27 @@
1
+ require_relative '../calculators/abstract_version_calculator'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `VersionFormatter` class is a generic version formatter that can be used as a base class
7
+ # for formatting version objects used by for different platforms. It contains formatting methods that
8
+ # are shared by all platforms. It has the abstract suffix because it should not be instantiated directly.
9
+ class AbstractVersionFormatter
10
+ # Get the release version string for the app.
11
+ #
12
+ # This method constructs the release version string based on the major, minor, and
13
+ # patch components of the provided `@version`. If the patch component is zero, it returns
14
+ # a version string in the format "major.minor" (e.g., '1.2'). Otherwise, it returns a
15
+ # version string in the format "major.minor.patch" (e.g., '1.2.3').
16
+ #
17
+ # @param [AppVersion] version The version object to format
18
+ #
19
+ # @return [String] The formatted release version string.
20
+ #
21
+ def release_version(version)
22
+ version.patch.zero? ? "#{version.major}.#{version.minor}" : "#{version.major}.#{version.minor}.#{version.patch}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module Fastlane
2
+ module Wpmreleasetoolkit
3
+ module Versioning
4
+ # The `DerivedBuildCodeFormatter` class is a specialized build code formatter for derived build codes.
5
+ # It takes in an AppVersion object and derives a build code from it.
6
+ class DerivedBuildCodeFormatter
7
+ # Calculate the next derived build code.
8
+ #
9
+ # This method derives a new build code from the given AppVersion object by concatenating the digit 1,
10
+ # the major version, the minor version, the patch version, and the build number.
11
+ #
12
+ # @param [AppVersion] version The AppVersion object to derive the next build code from.
13
+ #
14
+ # @param [BuildCode] build_code A BuildCode object. This parameter is ignored but is included
15
+ # to have a consistent signature with other build code formatters.
16
+ #
17
+ # @return [String] The formatted build code string.
18
+ #
19
+ def build_code(build_code = nil, version:)
20
+ format(
21
+ # 1 is appended to the beginning of the string in case there needs to be additional platforms or
22
+ # extensions that could then use a different digit prefix such as 2, etc.
23
+ '1%<major>.2i%<minor>.2i%<patch>.2i%<build_number>.2i',
24
+ major: version.major,
25
+ minor: version.minor,
26
+ patch: version.patch,
27
+ build_number: version.build_number
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../formatters/four_part_version_formatter'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `FourPartBuildCodeFormatter` is a specialized build code formatter for apps that use
7
+ # build codes in the format of `major.minor.patch.build_number`.
8
+ class FourPartBuildCodeFormatter
9
+ # @param [AppVersion] version The AppVersion object to format
10
+ #
11
+ # @param [BuildCode] build_code A BuildCode object. This parameter is ignored but is included
12
+ # to have a consistent signature with other build code formatters.
13
+ #
14
+ # @return [String] The formatted build code string.
15
+ #
16
+ def build_code(build_code = nil, version:)
17
+ FourPartVersionFormatter.new.to_s(version)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'abstract_version_formatter'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `FourPartVersionFormatter` class extends the `VersionFormatter` class. It is a specialized version formatter for
7
+ # apps that use versions in the format of `1.2.3.4`.
8
+ class FourPartVersionFormatter < AbstractVersionFormatter
9
+ # Parse the version string into an AppVersion instance
10
+ #
11
+ # @param [String] version The version string to parse
12
+ #
13
+ # @return [AppVersion] The parsed version
14
+ #
15
+ def parse(version)
16
+ # Split the version string into its components
17
+ components = version.split('.').map(&:to_i)
18
+
19
+ # Create a new AppVersion instance from the version string components
20
+ Fastlane::Models::AppVersion.new(*components)
21
+ end
22
+
23
+ # Return the formatted version string
24
+ #
25
+ # @param [AppVersion] version The version object to format
26
+ #
27
+ # @return [String] The formatted version string
28
+ #
29
+ def to_s(version)
30
+ "#{version.major}.#{version.minor}.#{version.patch}.#{version.build_number}"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,65 @@
1
+ require_relative 'abstract_version_formatter'
2
+
3
+ module Fastlane
4
+ module Wpmreleasetoolkit
5
+ module Versioning
6
+ # The `RCNotationVersionFormatter` class extends the `VersionFormatter` class. It is a specialized version
7
+ # formatter for apps that may use versions in the format of `1.2.3-rc-4`.
8
+ class RCNotationVersionFormatter < AbstractVersionFormatter
9
+ # The string identifier used for beta versions in Android.
10
+ RC_SUFFIX = 'rc'.freeze
11
+
12
+ # Parse the version string into an AppVersion instance
13
+ #
14
+ # @param [String] version_name The version string to parse
15
+ #
16
+ # @return [AppVersion] The parsed version
17
+ #
18
+ def parse(version_name)
19
+ # Set the build number to 0 by default so that it will be set correctly for non-beta version numbers
20
+ build_number = 0
21
+
22
+ if version_name.include?(RC_SUFFIX)
23
+ # Extract the build number from the version name
24
+ build_number = version_name.split('-')[2].to_i
25
+ # Extract the version name without the build number and drop the RC suffix
26
+ version_name = version_name.split(RC_SUFFIX)[0]
27
+ end
28
+
29
+ # Split the version name into its components
30
+ version_number_parts = version_name.split('.').map(&:to_i)
31
+ # Fill the array with 0 if needed to ensure array has at least 3 components
32
+ version_number_parts.fill(0, version_number_parts.length...3)
33
+
34
+ # Map version_number_parts to AppVersion model
35
+ major = version_number_parts[0]
36
+ minor = version_number_parts[1]
37
+ patch = version_number_parts[2]
38
+
39
+ # Create an AppVersion object
40
+ Fastlane::Models::AppVersion.new(major, minor, patch, build_number)
41
+ end
42
+
43
+ # Get the formatted beta version of the Android app
44
+ #
45
+ # This method constructs a beta version string by combining the release version
46
+ # with the beta identifier and the build number. It ensures that the build number is
47
+ # 1 or higher, as beta versions must have a build number greater than or equal to 1.
48
+ #
49
+ # @param [AppVersion] version The version object to format
50
+ #
51
+ # @return [String] The formatted beta version of the Android app
52
+ #
53
+ # @raise [UI::Error] If the build number of the beta version is not 1 or higher
54
+ #
55
+ def beta_version(version)
56
+ # Ensure that the build number is 1 or higher for a beta version
57
+ UI.user_error!('The build number of a beta version must be 1 or higher') unless version.build_number.positive?
58
+
59
+ # Construct and return the formatted beta version string.
60
+ "#{release_version(version)}-#{RC_SUFFIX}-#{version.build_number}"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,20 @@
1
+ module Fastlane
2
+ module Wpmreleasetoolkit
3
+ module Versioning
4
+ # The `IntegerBuildCodeFormatter` is a specialized build code formatter for apps that use simple
5
+ # integer build codes in the format of `build_number`.
6
+ class SimpleBuildCodeFormatter
7
+ # @param version [AppVersion] An AppVersion object. This parameter is ignored but is included
8
+ # to have a consistent signature with other build code formatters.
9
+ #
10
+ # @param [BuildCode] build_code The BuildCode object to format
11
+ #
12
+ # @return [String] The formatted build code string.
13
+ #
14
+ def build_code(version = nil, build_code:)
15
+ build_code.to_s
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -4,7 +4,7 @@ module Fastlane
4
4
  module Wpmreleasetoolkit
5
5
  # Return all .rb files inside the "actions", "helper" and "models" directories
6
6
  def self.all_classes
7
- Dir[File.expand_path('**/{actions,helper,models}/**/*.rb', File.dirname(__FILE__))]
7
+ Dir[File.expand_path('**/{actions,helper,models,versioning}/**/*.rb', File.dirname(__FILE__))]
8
8
  end
9
9
  end
10
10
  end