fastlane-plugin-wpmreleasetoolkit 9.0.1 → 9.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/copy_branch_protection_action.rb +80 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/{removebranchprotection_action.rb → remove_branch_protection_action.rb} +24 -17
- data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_branch_protection_action.rb +153 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb +49 -4
- data/lib/fastlane/plugin/wpmreleasetoolkit/models/app_version.rb +36 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/models/build_code.rb +27 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/version.rb +1 -1
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/abstract_version_calculator.rb +85 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/date_build_code_calculator.rb +32 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/date_version_calculator.rb +37 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/marketing_version_calculator.rb +26 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/semantic_version_calculator.rb +21 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/simple_build_code_calculator.rb +22 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb +76 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/ios_version_file.rb +64 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/abstract_version_formatter.rb +27 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/derived_build_code_formatter.rb +33 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/four_part_build_code_formatter.rb +22 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/four_part_version_formatter.rb +35 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/rc_notation_version_formatter.rb +65 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/simple_build_code_formatter.rb +20 -0
- data/lib/fastlane/plugin/wpmreleasetoolkit.rb +1 -1
- metadata +35 -4
- data/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setbranchprotection_action.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e26f9a48b802c79f4ac19eafc0f3da18b717202ab42d01ca2b2735df4b4abd5d
|
4
|
+
data.tar.gz: ee567a664e7831629f4a0886fc574eec192ef214c47468211a99aa679e98685b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 993ef98974907a12d687e1558f9134038bf9e746a24c98e35dec4d230c87971e3342cd485d398b80076a20d03626ae4bf3b4c8b09f8f4fed316fc4ec7dcd0f8c
|
7
|
+
data.tar.gz: 3c6bebdb6b77966315088ea774e9a9275035b35abf87fcbf53b3ddfdadcdbd604c59a3ea2fe0d63082a6e572ead59e96cef851c0ec3c8d6187ed6f36326fb6e4
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../../helper/github_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
class CopyBranchProtectionAction < Action
|
7
|
+
def self.run(params)
|
8
|
+
repository = params[:repository]
|
9
|
+
from_branch = params[:from_branch]
|
10
|
+
to_branch = params[:to_branch]
|
11
|
+
|
12
|
+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
|
13
|
+
|
14
|
+
response = begin
|
15
|
+
github_helper.get_branch_protection(
|
16
|
+
repository: repository,
|
17
|
+
branch: from_branch
|
18
|
+
)
|
19
|
+
rescue Octokit::NotFound
|
20
|
+
UI.user_error!("Branch `#{from_branch}` of repository `#{repository}` was not found.")
|
21
|
+
end
|
22
|
+
UI.user_error!("Branch `#{from_branch}` does not have any branch protection set up.") if response.nil?
|
23
|
+
settings = Fastlane::Helper::GithubHelper.branch_protection_api_response_to_normalized_hash(response)
|
24
|
+
|
25
|
+
response = begin
|
26
|
+
github_helper.set_branch_protection(
|
27
|
+
repository: repository,
|
28
|
+
branch: to_branch,
|
29
|
+
**settings
|
30
|
+
)
|
31
|
+
rescue Octokit::NotFound
|
32
|
+
UI.user_error!("Branch `#{to_branch}` of repository `#{repository}` was not found.")
|
33
|
+
end
|
34
|
+
|
35
|
+
Fastlane::Helper::GithubHelper.branch_protection_api_response_to_normalized_hash(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.description
|
39
|
+
'Copies the branch protection settings of one branch onto another branch'
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.details
|
43
|
+
description
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.return_value
|
47
|
+
'The hash corresponding to the response returned by the API request, and containing the applied protection settings'
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.available_options
|
51
|
+
[
|
52
|
+
FastlaneCore::ConfigItem.new(key: :repository,
|
53
|
+
env_name: 'GHHELPER_REPOSITORY',
|
54
|
+
description: 'The remote path of the GH repository on which we work',
|
55
|
+
optional: false,
|
56
|
+
type: String),
|
57
|
+
FastlaneCore::ConfigItem.new(key: :from_branch,
|
58
|
+
env_name: 'GHHELPER_FROM_BRANCH',
|
59
|
+
description: 'The branch to copy the protection settings from',
|
60
|
+
optional: false,
|
61
|
+
type: String),
|
62
|
+
FastlaneCore::ConfigItem.new(key: :to_branch,
|
63
|
+
env_name: 'GHHELPER_TO_BRANCH',
|
64
|
+
description: 'The branch to copy the protection settings to',
|
65
|
+
optional: false,
|
66
|
+
type: String),
|
67
|
+
Fastlane::Helper::GithubHelper.github_token_config_item,
|
68
|
+
]
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.authors
|
72
|
+
['Automattic']
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.is_supported?(platform)
|
76
|
+
true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -3,42 +3,34 @@ require_relative '../../helper/github_helper'
|
|
3
3
|
|
4
4
|
module Fastlane
|
5
5
|
module Actions
|
6
|
-
class
|
6
|
+
class RemoveBranchProtectionAction < Action
|
7
7
|
def self.run(params)
|
8
8
|
repository = params[:repository]
|
9
9
|
branch_name = params[:branch]
|
10
10
|
|
11
|
-
branch_url = "https://api.github.com/repos/#{repository}/branches/#{branch_name}"
|
12
|
-
restrictions = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] }
|
13
|
-
required_pull_request_reviews = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false }
|
14
|
-
|
15
11
|
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
|
16
12
|
github_helper.remove_branch_protection(
|
17
13
|
repository: repository,
|
18
|
-
branch: branch_name
|
19
|
-
restrictions: restrictions,
|
20
|
-
enforce_admins: nil,
|
21
|
-
required_pull_request_reviews: required_pull_request_reviews
|
14
|
+
branch: branch_name
|
22
15
|
)
|
16
|
+
rescue Octokit::NotFound
|
17
|
+
UI.user_error!("Branch `#{branch_name}` of repository `#{repository}` was not found.")
|
18
|
+
rescue Octokit::BranchNotProtected
|
19
|
+
UI.message("Note: Branch `#{branch_name}` was not protected in the first place.")
|
23
20
|
end
|
24
21
|
|
25
22
|
def self.description
|
26
|
-
|
23
|
+
'Removes the protection settings for the specified branch'
|
27
24
|
end
|
28
25
|
|
29
|
-
def self.
|
30
|
-
|
26
|
+
def self.details
|
27
|
+
description
|
31
28
|
end
|
32
29
|
|
33
30
|
def self.return_value
|
34
31
|
# If your method provides a return value, you can describe here what it does
|
35
32
|
end
|
36
33
|
|
37
|
-
def self.details
|
38
|
-
# Optional:
|
39
|
-
"Sets the 'release branch' protection state for the specified branch"
|
40
|
-
end
|
41
|
-
|
42
34
|
def self.available_options
|
43
35
|
[
|
44
36
|
FastlaneCore::ConfigItem.new(key: :repository,
|
@@ -55,9 +47,24 @@ module Fastlane
|
|
55
47
|
]
|
56
48
|
end
|
57
49
|
|
50
|
+
def self.authors
|
51
|
+
['Automattic']
|
52
|
+
end
|
53
|
+
|
58
54
|
def self.is_supported?(platform)
|
59
55
|
true
|
60
56
|
end
|
61
57
|
end
|
58
|
+
|
59
|
+
# For backwards compatibility
|
60
|
+
class RemovebranchprotectionAction < RemoveBranchProtectionAction
|
61
|
+
def self.category
|
62
|
+
:deprecated
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.deprecated_notes
|
66
|
+
"This action has been renamed `#{superclass.action_name}`"
|
67
|
+
end
|
68
|
+
end
|
62
69
|
end
|
63
70
|
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../../helper/github_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
class SetBranchProtectionAction < Action
|
7
|
+
def self.run(params)
|
8
|
+
repository = params[:repository]
|
9
|
+
branch_name = params[:branch]
|
10
|
+
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
|
11
|
+
|
12
|
+
settings = if params[:keep_existing_settings_unchanged]
|
13
|
+
Fastlane::Helper::GithubHelper.branch_protection_api_response_to_normalized_hash(
|
14
|
+
github_helper.get_branch_protection(repository: repository, branch: branch_name)
|
15
|
+
)
|
16
|
+
else
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
|
20
|
+
# `required_status_checks` field — only override existing `checks` subfield if param provided
|
21
|
+
unless params[:required_ci_checks].nil?
|
22
|
+
if params[:required_ci_checks].empty?
|
23
|
+
settings[:required_status_checks] = nil # explicitly completely delete existing check requirement
|
24
|
+
else
|
25
|
+
settings[:required_status_checks] ||= { strict: false }
|
26
|
+
settings[:required_status_checks][:checks] = params[:required_ci_checks].map { |ctx| { context: ctx } }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# `enforce_admins` field — only override existing value if param provided
|
31
|
+
if params[:enforce_admins].nil?
|
32
|
+
settings[:enforce_admins] ||= nil # parameter is required to be provided, even if nil (aka false) value
|
33
|
+
else
|
34
|
+
settings[:enforce_admins] = params[:enforce_admins]
|
35
|
+
end
|
36
|
+
|
37
|
+
# `required_pull_request_reviews` field — only override `required_approving_review_count` subfield if param provided
|
38
|
+
settings[:required_pull_request_reviews] ||= {
|
39
|
+
dismiss_stale_reviews: false,
|
40
|
+
require_code_owner_reviews: false
|
41
|
+
}
|
42
|
+
unless params[:required_approving_review_count].nil?
|
43
|
+
settings[:required_pull_request_reviews][:required_approving_review_count] = params[:required_approving_review_count]
|
44
|
+
end
|
45
|
+
|
46
|
+
# `restrictions` field
|
47
|
+
settings[:restrictions] ||= { users: [], teams: [] }
|
48
|
+
|
49
|
+
# `allow_force_pushes` field — only override existing value if param provided
|
50
|
+
unless params[:allow_force_pushes].nil?
|
51
|
+
settings[:allow_force_pushes] = params[:allow_force_pushes]
|
52
|
+
end
|
53
|
+
|
54
|
+
# `lock_branch` field — only override existing value if param provided
|
55
|
+
unless params[:lock_branch].nil?
|
56
|
+
settings[:lock_branch] = params[:lock_branch]
|
57
|
+
end
|
58
|
+
|
59
|
+
# API Call - See https://docs.github.com/en/rest/branches/branch-protection#update-branch-protection
|
60
|
+
response = github_helper.set_branch_protection(
|
61
|
+
repository: repository,
|
62
|
+
branch: branch_name,
|
63
|
+
**settings
|
64
|
+
)
|
65
|
+
|
66
|
+
Fastlane::Helper::GithubHelper.branch_protection_api_response_to_normalized_hash(response)
|
67
|
+
rescue Octokit::NotFound => e
|
68
|
+
UI.user_error!("Branch `#{branch_name}` of repository `#{repository}` was not found.\n#{e.message}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.description
|
72
|
+
'Sets the protection state for the specified branch'
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.details
|
76
|
+
description
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.return_value
|
80
|
+
'The hash corresponding to the response returned by the API request, and containing the applied protection settings'
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.available_options
|
84
|
+
[
|
85
|
+
FastlaneCore::ConfigItem.new(key: :repository,
|
86
|
+
env_name: 'GHHELPER_REPOSITORY',
|
87
|
+
description: 'The slug of the GH repository on which we work',
|
88
|
+
optional: false,
|
89
|
+
type: String),
|
90
|
+
# NOTE: GitHub branch protection API doesn't allow wildcard characters for the branch parameter
|
91
|
+
FastlaneCore::ConfigItem.new(key: :branch,
|
92
|
+
env_name: 'GHHELPER_BRANCH',
|
93
|
+
description: 'The branch to protect',
|
94
|
+
optional: false,
|
95
|
+
type: String),
|
96
|
+
FastlaneCore::ConfigItem.new(key: :keep_existing_settings_unchanged,
|
97
|
+
description: 'If set to true, will only change the settings that are explicitly provided to the action, ' \
|
98
|
+
+ 'while keeping the values of other existing protection settings (if any) unchanged. If false, it will ' \
|
99
|
+
+ 'discard any existing branch protection setting if any before setting just the ones provided ' \
|
100
|
+
+ '(and leaving the rest with default GitHub values)',
|
101
|
+
default_value: true,
|
102
|
+
type: Boolean),
|
103
|
+
FastlaneCore::ConfigItem.new(key: :required_ci_checks,
|
104
|
+
description: 'If provided, specifies the list of CI status checks to mark as required. If not provided (nil), will keep existing ones',
|
105
|
+
optional: true,
|
106
|
+
default_value: nil,
|
107
|
+
type: Array),
|
108
|
+
FastlaneCore::ConfigItem.new(key: :required_approving_review_count,
|
109
|
+
description: 'If not nil, change the number of approving reviews required to merge the PR. ' \
|
110
|
+
+ 'Acceptable values are `nil` (do not change), 0 (disable) or a number between 1–6',
|
111
|
+
optional: true,
|
112
|
+
default_value: nil,
|
113
|
+
type: Integer),
|
114
|
+
FastlaneCore::ConfigItem.new(key: :enforce_admins,
|
115
|
+
description: 'If provided, will update the setting of whether admins can bypass restrictions (false) or not (true)',
|
116
|
+
optional: true,
|
117
|
+
default_value: nil,
|
118
|
+
type: Boolean),
|
119
|
+
FastlaneCore::ConfigItem.new(key: :allow_force_pushes,
|
120
|
+
description: 'If provided, will update the setting of whether to allow force pushes on the branch',
|
121
|
+
optional: true,
|
122
|
+
default_value: nil,
|
123
|
+
type: Boolean),
|
124
|
+
FastlaneCore::ConfigItem.new(key: :lock_branch,
|
125
|
+
description: 'If provided, will update the locked (aka readonly) state of the branch',
|
126
|
+
optional: true,
|
127
|
+
default_value: nil,
|
128
|
+
type: Boolean),
|
129
|
+
Fastlane::Helper::GithubHelper.github_token_config_item,
|
130
|
+
]
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.authors
|
134
|
+
['Automattic']
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.is_supported?(platform)
|
138
|
+
true
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# For backwards compatibility
|
143
|
+
class SetbranchprotectionAction < SetBranchProtectionAction
|
144
|
+
def self.category
|
145
|
+
:deprecated
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.deprecated_notes
|
149
|
+
"This action has been renamed `#{superclass.action_name}`"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -244,11 +244,20 @@ module Fastlane
|
|
244
244
|
#
|
245
245
|
# @param [String] repository The repository name (including the organization)
|
246
246
|
# @param [String] branch The branch name
|
247
|
-
# @
|
248
|
-
#
|
247
|
+
# @see https://docs.github.com/en/rest/branches/branch-protection#delete-branch-protection
|
248
|
+
#
|
249
|
+
def remove_branch_protection(repository:, branch:)
|
250
|
+
client.unprotect_branch(repository, branch)
|
251
|
+
end
|
252
|
+
|
253
|
+
# Get the list of branch protection settings for a given branch of a repository
|
249
254
|
#
|
250
|
-
|
251
|
-
|
255
|
+
# @param [String] repository The repository name (including the organization)
|
256
|
+
# @param [String] branch The branch name
|
257
|
+
# @see https://docs.github.com/en/rest/branches/branch-protection#get-branch-protection
|
258
|
+
#
|
259
|
+
def get_branch_protection(repository:, branch:, **options)
|
260
|
+
client.branch_protection(repository, branch)
|
252
261
|
end
|
253
262
|
|
254
263
|
# Protects a single branch from a repository
|
@@ -262,6 +271,42 @@ module Fastlane
|
|
262
271
|
client.protect_branch(repository, branch, options)
|
263
272
|
end
|
264
273
|
|
274
|
+
# Convert a response from the `/branch-protection` API endpoint into a Hash
|
275
|
+
# suitable to be returned and/or reused to pass to a subsequent `/branch-protection` API request
|
276
|
+
# @param [Sawyer::Resource] response The API response returned by `#get_branch_protection` or `#set_branch_protection`
|
277
|
+
# @return [Hash] A hash representation of the API response—or an empty Hash if `response` was `nil`—
|
278
|
+
# with Boolean values normalized to true/false, and any extra values that would be refused
|
279
|
+
# if used in a subsequent API request (like legacy vs new key) removed.
|
280
|
+
# @see https://docs.github.com/en/rest/branches/branch-protection
|
281
|
+
#
|
282
|
+
def self.branch_protection_api_response_to_normalized_hash(response)
|
283
|
+
return {} if response.nil?
|
284
|
+
|
285
|
+
normalize_values = lambda do |hash|
|
286
|
+
hash.each do |k, v|
|
287
|
+
# Boolean values appear as { "enabled" => true/false } in the Response, while they must appear as true/false in Request
|
288
|
+
hash[k] = v[:enabled] if v.is_a?(Hash) && v.key?(:enabled)
|
289
|
+
# References to :users, :teams and :apps are expanded as Objects in the Response, while they must just be the login or slug in Request
|
290
|
+
hash[k] = v.map { |item| item[:login] } if k == :users && v.is_a?(Array)
|
291
|
+
hash[k] = v.map { |item| item[:slug] } if %i[teams apps].include?(k) && v.is_a?(Array)
|
292
|
+
# Response contains lots of `*url` keys that are useless in practice and makes the returned hash harder to parse visually
|
293
|
+
hash.delete(k) if k.to_s == 'url' || k.to_s.end_with?('_url')
|
294
|
+
|
295
|
+
# Recurse into Hashes and Array of Hashes
|
296
|
+
normalize_values.call(v) if v.is_a?(Hash)
|
297
|
+
v.each { |item| normalize_values.call(item) if item.is_a?(Hash) } if v.is_a?(Array)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
hash = response.to_hash
|
302
|
+
normalize_values.call(hash)
|
303
|
+
|
304
|
+
# Response contains both (legacy) `:contexts` key and new `:checks` key, but only one of the two should be passed in Request
|
305
|
+
hash[:required_status_checks].delete(:contexts) unless hash.dig(:required_status_checks, :checks).nil?
|
306
|
+
|
307
|
+
hash
|
308
|
+
end
|
309
|
+
|
265
310
|
# Creates a GithubToken Fastlane ConfigItem
|
266
311
|
#
|
267
312
|
# @return [FastlaneCore::ConfigItem] The Fastlane ConfigItem for GitHub OAuth access token
|
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/abstract_version_calculator.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/date_build_code_calculator.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/marketing_version_calculator.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/semantic_version_calculator.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/simple_build_code_calculator.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/abstract_version_formatter.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/derived_build_code_formatter.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/four_part_build_code_formatter.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/four_part_version_formatter.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/rc_notation_version_formatter.rb
ADDED
@@ -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
|
data/lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/simple_build_code_formatter.rb
ADDED
@@ -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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastlane-plugin-wpmreleasetoolkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0
|
4
|
+
version: 9.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Automattic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: java-properties
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.3.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.3.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: nokogiri
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -426,6 +440,7 @@ files:
|
|
426
440
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/circleci_trigger_job_action.rb
|
427
441
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/close_milestone_action.rb
|
428
442
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/comment_on_pr.rb
|
443
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/copy_branch_protection_action.rb
|
429
444
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_new_milestone_action.rb
|
430
445
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_release_action.rb
|
431
446
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/extract_release_notes_for_version_action.rb
|
@@ -436,8 +451,8 @@ files:
|
|
436
451
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb
|
437
452
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/promo_screenshots_action.rb
|
438
453
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb
|
439
|
-
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/
|
440
|
-
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/
|
454
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/remove_branch_protection_action.rb
|
455
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_branch_protection_action.rb
|
441
456
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setfrozentag_action.rb
|
442
457
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/common/upload_to_s3.rb
|
443
458
|
- lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_add_files_to_copy_action.rb
|
@@ -506,6 +521,8 @@ files:
|
|
506
521
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/promo_screenshots_helper.rb
|
507
522
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/release_notes_helper.rb
|
508
523
|
- lib/fastlane/plugin/wpmreleasetoolkit/helper/user_agent.rb
|
524
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/models/app_version.rb
|
525
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/models/build_code.rb
|
509
526
|
- lib/fastlane/plugin/wpmreleasetoolkit/models/configuration.rb
|
510
527
|
- lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb
|
511
528
|
- lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_account.rb
|
@@ -513,6 +530,20 @@ files:
|
|
513
530
|
- lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_lab_result.rb
|
514
531
|
- lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb
|
515
532
|
- lib/fastlane/plugin/wpmreleasetoolkit/version.rb
|
533
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/abstract_version_calculator.rb
|
534
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/date_build_code_calculator.rb
|
535
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/date_version_calculator.rb
|
536
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/marketing_version_calculator.rb
|
537
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/semantic_version_calculator.rb
|
538
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/calculators/simple_build_code_calculator.rb
|
539
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/android_version_file.rb
|
540
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/files/ios_version_file.rb
|
541
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/abstract_version_formatter.rb
|
542
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/derived_build_code_formatter.rb
|
543
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/four_part_build_code_formatter.rb
|
544
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/four_part_version_formatter.rb
|
545
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/rc_notation_version_formatter.rb
|
546
|
+
- lib/fastlane/plugin/wpmreleasetoolkit/versioning/formatters/simple_build_code_formatter.rb
|
516
547
|
homepage: https://github.com/wordpress-mobile/release-toolkit
|
517
548
|
licenses:
|
518
549
|
- MIT
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'fastlane/action'
|
2
|
-
require_relative '../../helper/github_helper'
|
3
|
-
|
4
|
-
module Fastlane
|
5
|
-
module Actions
|
6
|
-
class SetbranchprotectionAction < Action
|
7
|
-
def self.run(params)
|
8
|
-
repository = params[:repository]
|
9
|
-
branch_name = params[:branch]
|
10
|
-
|
11
|
-
branch_url = "https://api.github.com/repos/#{repository}/branches/#{branch_name}"
|
12
|
-
restrictions = { url: "#{branch_url}/protection/restrictions", users_url: "#{branch_url}/protection/restrictions/users", teams_url: "#{branch_url}/protection/restrictions/teams", users: [], teams: [] }
|
13
|
-
required_pull_request_reviews = { url: "#{branch_url}/protection/required_pull_request_reviews", dismiss_stale_reviews: false, require_code_owner_reviews: false }
|
14
|
-
|
15
|
-
github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
|
16
|
-
github_helper.set_branch_protection(
|
17
|
-
repository: repository,
|
18
|
-
branch: branch_name,
|
19
|
-
restrictions: restrictions,
|
20
|
-
enforce_admins: nil,
|
21
|
-
required_pull_request_reviews: required_pull_request_reviews
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.description
|
26
|
-
"Sets the 'release branch' protection state for the specified branch"
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.authors
|
30
|
-
['Automattic']
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.return_value
|
34
|
-
# If your method provides a return value, you can describe here what it does
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.details
|
38
|
-
# Optional:
|
39
|
-
"Sets the 'release branch' protection state for the specified branch"
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.available_options
|
43
|
-
[
|
44
|
-
FastlaneCore::ConfigItem.new(key: :repository,
|
45
|
-
env_name: 'GHHELPER_REPOSITORY',
|
46
|
-
description: 'The remote path of the GH repository on which we work',
|
47
|
-
optional: false,
|
48
|
-
type: String),
|
49
|
-
FastlaneCore::ConfigItem.new(key: :branch,
|
50
|
-
env_name: 'GHHELPER_BRANCH',
|
51
|
-
description: 'The branch to protect',
|
52
|
-
optional: false,
|
53
|
-
type: String),
|
54
|
-
Fastlane::Helper::GithubHelper.github_token_config_item,
|
55
|
-
]
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.is_supported?(platform)
|
59
|
-
true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|