Class: Fastlane::Actions::IosCheckBetaDepsAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb

Constant Summary collapse

ALL_PODS_STABLE_MESSAGE =
'All pods are pointing to a stable version. You can continue with the code freeze.'.freeze
NON_STABLE_PODS_MESSAGE =
"Please create a new stable version of those pods and update the Podfile to the newly released version before continuing with the code freeze:\n".freeze

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



102
103
104
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb', line 102

def self.authors
  ['Automattic']
end

.available_optionsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb', line 59

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :lockfile,
      description: 'Path to the Podfile.lock to analyse',
      default_value: 'Podfile.lock',
      type: String,
      verify_block: proc do |value|
        UI.user_error!("File `#{value}` does not exist") unless File.exist?(value)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :report_commits,
      description: 'Whether to report pods referenced by commit',
      default_value: true,
      type: Boolean
    ),
    FastlaneCore::ConfigItem.new(
      key: :report_branches,
      description: 'Whether to report pods referenced by branch',
      default_value: true,
      type: Boolean
    ),
    FastlaneCore::ConfigItem.new(
      key: :report_version_pattern,
      description: 'Report any pod whose resolved version matches this Regex pattern. Set to empty string to ignore',
      default_value: '-beta|-rc',
      type: String
    ),
  ]
end

.descriptionObject



51
52
53
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb', line 51

def self.description
  'Runs some prechecks before finalizing a release'
end

.detailsObject



55
56
57
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb', line 55

def self.details
  'Runs some prechecks before finalizing a release'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb', line 106

def self.is_supported?(platform)
  %i[ios mac].include?(platform)
end

.outputObject



91
92
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb', line 91

def self.output
end

.return_valueObject



94
95
96
97
98
99
100
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb', line 94

def self.return_value
  <<~RETURN_VALUE
    A Hash with keys `message` and `pods`.
    - The `message` can be used to e.g. post a Buildkite annotation.
    - The `pods` is itself a `Hash` whose keys are the pod names and values are the reason for the violation
  RETURN_VALUE
end

.run(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
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
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_check_beta_deps.rb', line 9

def self.run(params)
  yaml = YAML.load_file(params[:lockfile])
  non_stable_pods = {} # Key will be pod name, value will be reason for flagging

  # Find pods referenced by commit and branch to a repo. if any
  yaml['EXTERNAL SOURCES']&.each do |pod, options|
    non_stable_pods[pod] = 'commit' if params[:report_commits] && options.key?(:commit)
    non_stable_pods[pod] = 'branch' if params[:report_branches] && options.key?(:branch)
  end

  # Find pods whose resolved version matches the regex
  version_pattern = params[:report_version_pattern]
  unless version_pattern.nil? || version_pattern.empty?
    regex = begin
      Regexp.new(version_pattern)
    rescue RegexpError
      UI.user_error!("Invalid regex pattern: `#{version_pattern}`")
    end
    resolved_pods = yaml['PODS'].flat_map { |entry| entry.is_a?(Hash) ? entry.keys : entry }
    resolved_pods.each do |line|
      (pod, version) = /(.*) \((.*)\)/.match(line)&.captures
      non_stable_pods[pod] = regex.source if regex.match?(version)
    end
  end

  message = ''
  if non_stable_pods.empty?
    message << ALL_PODS_STABLE_MESSAGE
  else
    message << NON_STABLE_PODS_MESSAGE
    non_stable_pods.sort.each do |pod, reason|
      message << " - #{pod} (currently points to #{reason})\n"
    end
  end
  UI.important(message)
  { message: message, pods: non_stable_pods }
end