Class: Fastlane::Actions::GetVersioningInfoAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb

Overview

Action to retrieve semantic versioning information from commit history.

Class Method Summary collapse

Class Method Details

.authorsObject



69
70
71
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 69

def self.authors
  ["kassi"]
end

.available_optionsObject

:nocov:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 97

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :allowed_types,
                                 env_name: "SEMANTIC_VERSIONING_ALLOWED_TYPES",
                                 description: "List of allowed commit types",
                                 optional: true,
                                 default_value: %w[build ci docs feat fix perf refactor style test chore revert
                                                   bump init],
                                 type: Array),
    FastlaneCore::ConfigItem.new(key: :bump_map,
                                 description: "Map of commit types to their bump level (major, minor, patch)",
                                 optional: true,
                                 default_value: { breaking: :major, feat: :minor, fix: :patch },
                                 is_string: false,
                                 verify_block: ->(value) { verify_bump_map(value) }),
    FastlaneCore::ConfigItem.new(key: :force_type,
                                 env_name: "SEMANTIC_VERSIONING_FORCE_TYPE",
                                 description: "Force a minimum bump type",
                                 optional: true,
                                 default_value: nil,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :tag_format,
                                 env_name: "SEMANTIC_VERSIONING_TAG_FORMAT",
                                 description: "The format for the git tag",
                                 optional: true,
                                 default_value: "$version",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :target,
                                 env_name: "SEMANTIC_VERSIONING_TARGET",
                                 description: "Name of the target to use for manual versioning system",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :type_map,
                                 env_name: "SEMANTIC_VERSIONING_TYPE_MAP",
                                 description: "Map of types to section titles for the changelog." \
                                              "Only the specified types will be used for the changelog",
                                 optional: true,
                                 default_value: { breaking: "BREAKING CHANGES", feat: "Features",
                                                  fix: "Bug Fixes" },
                                 is_string: false,
                                 verify_block: ->(value) { verify_type_map(value) }),
    FastlaneCore::ConfigItem.new(key: :update,
                                 env_name: "SEMANTIC_VERSIONING_UPDATE",
                                 description: "When set, the changelog is determined from the previous rather than current version." \
                                              "This is useful when being on a release branch where new commits are added to the " \
                                              "current release",
                                 optional: true,
                                 default_value: false,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :versioning_system,
                                 env_name: "SEMANTIC_VERSIONING_VERSIONING_SYSTEM",
                                 description: "Type of versioning to use. Can be 'manual' or 'apple-generic'." \
                                              "For 'apple-generic', the project has to be prepared with prepare_versioning." \
                                              "Defaults to 'manual'",
                                 optional: true,
                                 default_value: "manual",
                                 is_string: true,
                                 verify_block: ->(value) { Helper::SemanticVersioningHelper.verify_versioning_system(value) })
  ]
end

.descriptionObject

:nocov:



65
66
67
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 65

def self.description
  "Retrieve semantic versioning information from commit history."
end

.detailsObject



91
92
93
94
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 91

def self.details
  # Optional:
  "Reads commits from last version and determines next version and changelog."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


166
167
168
169
170
171
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 166

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  %i[ios mac].include?(platform)
end

.outputObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 73

def self.output
  # Define the shared values you are going to provide
  [
    ["SEMVER_CURRENT_VERSION", "Current version of the project as provided"],
    ["SEMVER_CURRENT_TAG", "Current tag for the current version number"],
    ["SEMVER_BUMP_TYPE", "Type of version bump. One of major, minor, or patch"],
    ["SEMVER_NEW_VERSION", "New version that would have to be set from current version and commits"],
    ["SEMVER_NEW_CHANGELOG", "New changelog section for the new bump"],
    ["SEMVER_BUMPABLE", "True if a version bump is possible"],
    ["SEMVER_VERSIONING_SYSTEM", "The versioning system used"]
  ]
end

.return_valueObject



86
87
88
89
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 86

def self.return_value
  # If your method provides a return value, you can describe here what it does
  "Returns true, if the determined next version is higher than the current one."
end

.run(params) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 21

def self.run(params)
  params[:allowed_types].map!(&:to_sym)
  params[:bump_map].transform_keys!(&:to_sym)
  params[:bump_map].transform_values!(&:to_sym)
  params[:force_type] = params[:force_type]&.to_sym

  verify_type_map(params[:type_map])
  verify_bump_map(params[:bump_map])
  Helper::SemanticVersioningHelper.verify_versioning_system(params[:versioning_system])

  system = lane_context[SharedValues::SEMVER_VERSIONING_SYSTEM] = params[:versioning_system]
  target = params[:target]

  current_version = if params[:update]
                      Helper::SemanticVersioningHelper.previous_version(tag_format: params[:tag_format])
                    else
                      Helper::SemanticVersioningHelper.version_number(system: system, target: target)
                    end
  formatted_tag = Helper::SemanticVersioningHelper.formatted_tag(current_version, params[:tag_format])

  commits = Helper::SemanticVersioningHelper.git_commits(
    from: Helper::SemanticVersioningHelper.git_tag_exists?(formatted_tag) ? formatted_tag : nil,
    allowed_types: params[:allowed_types],
    bump_map: params[:bump_map]
  )

  bump_type = Helper::SemanticVersioningHelper.bump_type(commits: commits, force_type: params[:force_type])
  new_version = Helper::SemanticVersioningHelper.increase_version(current_version: current_version,
                                                                  bump_type: bump_type)
  new_changelog = Helper::SemanticVersioningHelper.build_changelog(version: new_version, commits: commits,
                                                                   type_map: params[:type_map])
  bumpable = current_version != new_version

  Actions.lane_context[SharedValues::SEMVER_CURRENT_VERSION] = current_version
  Actions.lane_context[SharedValues::SEMVER_CURRENT_TAG] = formatted_tag
  Actions.lane_context[SharedValues::SEMVER_BUMP_TYPE] = bump_type
  Actions.lane_context[SharedValues::SEMVER_NEW_VERSION] = new_version
  Actions.lane_context[SharedValues::SEMVER_NEW_CHANGELOG] = new_changelog
  Actions.lane_context[SharedValues::SEMVER_BUMPABLE] = bumpable

  bumpable
end

.verify_bump_map(value) ⇒ Object



162
163
164
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 162

def self.verify_bump_map(value)
  UI.user_error!("Parameter 'bump_map' must be a Hash.") unless value.is_a?(Hash)
end

.verify_type_map(value) ⇒ Object



158
159
160
# File 'lib/fastlane/plugin/semantic_versioning/actions/get_versioning_info_action.rb', line 158

def self.verify_type_map(value)
  UI.user_error!("Parameter 'type_map' must be a Hash.") unless value.is_a?(Hash)
end