Class: Fastlane::EnvironmentPrinter

Inherits:
Object
  • Object
show all
Defined in:
fastlane/lib/fastlane/environment_printer.rb

Class Method Summary collapse

Class Method Details

.anonymized_path(path, home = ) ⇒ Object



285
286
287
# File 'fastlane/lib/fastlane/environment_printer.rb', line 285

def self.anonymized_path(path, home = ENV['HOME'])
  return home ? path.gsub(%r{^#{home}(?=/(.*)|$)}, '~\2') : path
end

.copy_to_clipboard(string) ⇒ Object

Copy a given string into the clipboard Make sure to ask the user first, as some people don’t use a clipboard manager, so they might lose something important



292
293
294
295
# File 'fastlane/lib/fastlane/environment_printer.rb', line 292

def self.copy_to_clipboard(string)
  require 'open3'
  Open3.popen3('pbcopy') { |input, _, _| input << string }
end

.gems_to_checkObject

We have this as a separate method, as this has to be handled slightly differently, depending on how fastlane is being called



89
90
91
92
93
94
95
# File 'fastlane/lib/fastlane/environment_printer.rb', line 89

def self.gems_to_check
  if Helper.contained_fastlane?
    Gem::Specification
  else
    Gem.loaded_specs.values
  end
end

.getObject



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 'fastlane/lib/fastlane/environment_printer.rb', line 20

def self.get
  UI.important("Generating fastlane environment output, this might take a few seconds...")
  require "fastlane/markdown_table_formatter"
  env_output = ""
  env_output << print_system_environment
  env_output << print_system_locale
  env_output << print_fastlane_files
  env_output << print_loaded_fastlane_gems
  env_output << print_loaded_plugins
  env_output << print_loaded_gems
  env_output << print_date

  # Adding title
  status = (env_output.include?("🚫") ? "🚫" : "βœ…")
  env_header = "<details><summary>#{status} fastlane environment #{status}</summary>\n\n"
  env_tail = "</details>"
  final_output = ""

  if FastlaneCore::Globals.captured_output?
    final_output << "### Captured Output\n\n"
    final_output << "Command Used: `#{ARGV.join(' ')}`\n"
    final_output << "<details><summary>Output/Log</summary>\n\n```\n\n#{FastlaneCore::Globals.captured_output}\n\n```\n\n</details>\n\n"
  end

  final_output << env_header + env_output + env_tail
end

.outputObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'fastlane/lib/fastlane/environment_printer.rb', line 3

def self.output
  env_info = get

  # Remove sensitive option values
  FastlaneCore::Configuration.sensitive_strings.compact.each do |sensitive_element|
    env_info.gsub!(sensitive_element, "#########")
  end

  puts(env_info)
  UI.important("Take notice that this output may contain sensitive information, or simply information that you don't want to make public.")
  if FastlaneCore::Helper.mac? && UI.interactive? && UI.confirm("πŸ™„  Wow, that's a lot of markdown text... should fastlane put it into your clipboard, so you can easily paste it on GitHub?")
    copy_to_clipboard(env_info)
    UI.success("Successfully copied markdown into your clipboard 🎨")
  end
  UI.success("Open https://github.com/fastlane/fastlane/issues/new to submit a new issue βœ…")
end


47
48
49
50
# File 'fastlane/lib/fastlane/environment_printer.rb', line 47

def self.print_date
  date = Time.now.strftime("%Y-%m-%d")
  "\n*generated on:* **#{date}**\n"
end


251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'fastlane/lib/fastlane/environment_printer.rb', line 251

def self.print_fastlane_files
  env_output = "### fastlane files:\n\n"

  fastlane_path = FastlaneCore::FastlaneFolder.fastfile_path

  if fastlane_path && File.exist?(fastlane_path)
    env_output << "<details>"
    env_output << "<summary>`#{fastlane_path}`</summary>\n"
    env_output << "\n"
    env_output << "```ruby\n"
    env_output <<  File.read(fastlane_path, encoding: "utf-8")
    env_output <<  "\n```\n"
    env_output << "</details>"
  else
    env_output << "**No Fastfile found**\n"
  end
  env_output << "\n\n"

  appfile_path = CredentialsManager::AppfileConfig.default_path
  if appfile_path && File.exist?(appfile_path)
    env_output << "<details>"
    env_output << "<summary>`#{appfile_path}`</summary>\n"
    env_output << "\n"
    env_output << "```ruby\n"
    env_output <<  File.read(appfile_path, encoding: "utf-8")
    env_output <<  "\n```\n"
    env_output << "</details>"
  else
    env_output << "**No Appfile found**\n"
  end
  env_output << "\n\n"
  env_output
end


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
# File 'fastlane/lib/fastlane/environment_printer.rb', line 97

def self.print_loaded_fastlane_gems
  # fastlanes internal gems
  env_output = "### fastlane gems\n\n"
  table = ""
  table << "| Gem | Version | Update-Status |\n"
  table << "|-----|---------|------------|\n"
  fastlane_tools = Fastlane::TOOLS + [:fastlane_core, :credentials_manager]

  gems_to_check.each do |current_gem|
    update_status = "N/A"

    next unless fastlane_tools.include?(current_gem.name.to_sym)
    begin
      latest_version = FastlaneCore::UpdateChecker.fetch_latest(current_gem.name)
      if Gem::Version.new(current_gem.version) >= Gem::Version.new(latest_version)
        update_status = "βœ… Up-To-Date"
      else
        update_status = "🚫 Update available"
      end
    rescue
      update_status = "πŸ’₯ Check failed"
    end
    table << "| #{current_gem.name} | #{current_gem.version} | #{update_status} |\n"
  end

  rendered_table = MarkdownTableFormatter.new(table)
  env_output << rendered_table.to_md

  env_output << "\n\n"

  return env_output
end


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'fastlane/lib/fastlane/environment_printer.rb', line 130

def self.print_loaded_gems
  env_output = "<details>"
  env_output << "<summary><b>Loaded gems</b></summary>\n\n"

  table = "| Gem | Version |\n"
  table << "|-----|---------|\n"
  gems_to_check.each do |current_gem|
    unless Fastlane::TOOLS.include?(current_gem.name.to_sym)
      table << "| #{current_gem.name} | #{current_gem.version} |\n"
    end
  end
  rendered_table = MarkdownTableFormatter.new(table)

  env_output << rendered_table.to_md
  env_output << "</details>\n\n"
  return env_output
end


52
53
54
55
56
57
58
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
# File 'fastlane/lib/fastlane/environment_printer.rb', line 52

def self.print_loaded_plugins
  ENV["FASTLANE_ENV_PRINTER"] = "enabled"
  env_output =  "### Loaded fastlane plugins:\n"
  env_output << "\n"
  plugin_manager = Fastlane::PluginManager.new
  plugin_manager.load_plugins
  if plugin_manager.available_plugins.length <= 0
    env_output << "**No plugins Loaded**\n"
  else
    table = ""
    table << "| Plugin | Version | Update-Status |\n"
    table << "|--------|---------|\n"
    plugin_manager.available_plugins.each do |plugin|
      begin
        installed_version = Fastlane::ActionCollector.determine_version(plugin)
        latest_version = FastlaneCore::UpdateChecker.fetch_latest(plugin)
        if Gem::Version.new(installed_version) == Gem::Version.new(latest_version)
          update_status = "βœ… Up-To-Date"
        else
          update_status = "🚫 Update available"
        end
      rescue
        update_status = "πŸ’₯ Check failed"
      end
      table << "| #{plugin} | #{installed_version} | #{update_status} |\n"
    end

    rendered_table = MarkdownTableFormatter.new(table)
    env_output << rendered_table.to_md
  end

  env_output << "\n\n"
  env_output
end


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'fastlane/lib/fastlane/environment_printer.rb', line 177

def self.print_system_environment
  require "openssl"

  env_output = "### Stack\n\n"
  product, version, build = "Unknown"
  os_version = "UNKNOWN"

  if Helper.mac?
    product, version, build = `sw_vers`.strip.split("\n").map { |line| line.split(':').last.strip }
    os_version = version
  end

  if Helper.linux?
    # this should work on pretty much all linux distros
    os_version = `uname -a`.strip
    version = ""
    build = `uname -r`.strip
    product = `cat /etc/issue.net`.strip

    distro_guesser = {
      fedora: "/etc/fedora-release",
      debian_based: "/etc/debian_version",
      suse: "/etc/SUSE-release",
      mandrake: "/etc/mandrake-release"
    }

    distro_guesser.each do |dist, vers|
      os_version = "#{dist} " + File.read(vers).strip if File.exist?(vers)
      version = os_version
    end
  end

  table_content = {
    "fastlane" => Fastlane::VERSION,
    "OS" => os_version,
    "Ruby" => RUBY_VERSION,
    "Bundler?" => Helper.bundler?,
    "Git" => `git --version`.strip.split("\n").first,
    "Installation Source" => anonymized_path($PROGRAM_NAME),
    "Host" => "#{product} #{version} (#{build})",
    "Ruby Lib Dir" => anonymized_path(RbConfig::CONFIG['libdir']),
    "OpenSSL Version" => OpenSSL::OPENSSL_VERSION,
    "Is contained" => Helper.contained_fastlane?.to_s,
    "Is homebrew" => Helper.homebrew?.to_s,
    "Is installed via Fabric.app" => Helper.mac_app?.to_s
  }

  if Helper.mac?
    table_content["Xcode Path"] = anonymized_path(Helper.xcode_path)
    begin
      table_content["Xcode Version"] = Helper.xcode_version
    rescue => ex
      UI.error(ex)
      UI.error("Could not get Xcode Version")
    end
  end

  table = ["| Key | Value |"]
  table += table_content.collect { |k, v| "| #{k} | #{v} |" }

  begin
    rendered_table = MarkdownTableFormatter.new(table.join("\n"))
    env_output << rendered_table.to_md
  rescue => ex
    UI.error(ex)
    UI.error("Error rendering markdown table using the following text:")
    UI.message(table.join("\n"))
    env_output << table.join("\n")
  end

  env_output << "\n\n"
  env_output
end


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'fastlane/lib/fastlane/environment_printer.rb', line 148

def self.print_system_locale
  env_output = "### System Locale\n\n"
  found_one = false
  env_table = ""
  ["LANG", "LC_ALL", "LANGUAGE"].each do |e|
    env_icon = "🚫"
    if ENV[e] && ENV[e].end_with?("UTF-8")
      env_icon = "βœ…"
      found_one = true
    end
    if ENV[e].nil?
      env_icon = ""
    end
    env_table << "| #{e} | #{ENV[e]} | #{env_icon} |\n"
  end
  if !found_one
    table = "| Error |\n"
    table << "|-----|\n"
    table << "| No Locale with UTF8 found 🚫|\n"
  else
    table = "| Variable | Value |  |\n"
    table << "|-----|---------|----|\n"
    table << env_table
  end
  rendered_table = MarkdownTableFormatter.new(table)
  env_output << rendered_table.to_md
  env_output << "\n\n"
end