Class: Fastlane::EnvironmentPrinter

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

Class Method Summary collapse

Class Method Details

.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



186
187
188
189
190
191
192
# File 'lib/fastlane/environment_printer.rb', line 186

def self.copy_to_clipboard(string)
  require 'tempfile'
  Tempfile.create('environment_printer') do |tmp_file|
    File.write(tmp_file, string)
    `cat '#{tmp_file.path}' | pbcopy`
  end
end

.getObject



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

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_fastlane_files
  env_output << print_loaded_fastlane_gems
  env_output << print_loaded_plugins
  env_output << print_loaded_gems
  env_output << print_date
  env_output << "</details>"

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

  return env_header + env_output
end


22
23
24
25
# File 'lib/fastlane/environment_printer.rb', line 22

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


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
176
177
178
179
180
181
# File 'lib/fastlane/environment_printer.rb', line 149

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

  fastlane_path = 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)
    env_output <<  "```\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)
    env_output <<  "```\n"
    env_output << "</details>"
  else
    env_output << "**No Appfile found**\n"
  end
  env_output << "\n\n"
  env_output
end


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
90
91
92
93
94
# File 'lib/fastlane/environment_printer.rb', line 63

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]
  Gem.loaded_specs.values.each do |x|
    update_status = "N/A"

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

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

  env_output << "\n\n"

  return env_output
end


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fastlane/environment_printer.rb', line 96

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

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

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


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

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)
      update_url = FastlaneCore::UpdateChecker.generate_fetch_url(plugin)
      latest_version = FastlaneCore::UpdateChecker.fetch_latest(update_url)
      if Gem::Version.new(installed_version) == Gem::Version.new(latest_version)
        update_status = "βœ… Up-To-Date"
      else
        update_status = "🚫 Update availaible"
      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


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

def self.print_system_environment
  require "openssl"

  env_output = "### Stack\n\n"
  product, version, build = `sw_vers`.strip.split("\n").map { |line| line.split(':').last.strip }
  table_content = {
    "fastlane" => Fastlane::VERSION,
    "OS" => `sw_vers -productVersion`.strip,
    "Ruby" => RUBY_VERSION,
    "Bundler?" => Helper.bundler?,
    "Xcode Path" => Helper.xcode_path,
    "Xcode Version" => Helper.xcode_version,
    "Git" => `git --version`.strip.split("\n").first,
    "Installation Source" => $PROGRAM_NAME,
    "Host" => "#{product} #{version} (#{build})",
    "Ruby Lib Dir" => RbConfig::CONFIG['libdir'],
    "OpenSSL Version" => OpenSSL::OPENSSL_VERSION
  }
  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