Class: Fastlane::Actions::SpaceshipLogsAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/spaceship_logs.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, details, lane_context, method_missing, other_action, output, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



130
131
132
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 130

def self.author
  "joshdholtz"
end

.available_optionsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 69

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :latest,
                                 description: "Finds only the latest Spaceshop log file if set to true, otherwise returns all",
                                 default_value: true,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :print_contents,
                                 description: "Prints the contents of the found Spaceship log file(s)",
                                 default_value: false,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :print_paths,
                                 description: "Prints the paths of the found Spaceship log file(s)",
                                 default_value: false,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :copy_to_path,
                                 description: "Copies the found Spaceship log file(s) to a directory",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :copy_to_clipboard,
                                 description: "Copies the contents of the found Spaceship log file(s) to the clipboard",
                                 default_value: false,
                                 type: Boolean)
  ]
end

.categoryObject



118
119
120
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 118

def self.category
  :misc
end

.descriptionObject



65
66
67
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 65

def self.description
  "Find, print, and copy Spaceship logs"
end

.example_codeObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 97

def self.example_code
  [
    'spaceship_logs',
    'spaceship_logs(
      copy_to_path: "/tmp/artifacts"
    )',
    'spaceship_logs(
      copy_to_clipboard: true
    )',
    'spaceship_logs(
      print_contents: true,
      print_paths: true
    )',
    'spaceship_logs(
      latest: false,
      print_contents: true,
      print_paths: true
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



93
94
95
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 93

def self.is_supported?(platform)
  true
end

.return_typeObject



126
127
128
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 126

def self.return_type
  :array_of_strings
end

.return_valueObject



122
123
124
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 122

def self.return_value
  "The array of Spaceship logs"
end

.run(params) ⇒ Object



4
5
6
7
8
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'fastlane/lib/fastlane/actions/spaceship_logs.rb', line 4

def self.run(params)
  latest = params[:latest]
  print_contents = params[:print_contents]
  print_paths = params[:print_paths]
  copy_to_path = params[:copy_to_path]
  copy_to_clipboard = params[:copy_to_clipboard]

  # Get log files
  files = Dir.glob("/tmp/spaceship*.log").sort_by { |f| File.mtime(f) }.reverse

  if files.size == 0
    UI.message("No Spaceship log files found")
    return []
  end

  # Filter to latest
  if latest
    files = [files.first]
  end

  # Print contents
  if print_contents
    files.each do |file|
      data = File.read(file)
      puts("-----------------------------------------------------------------------------------")
      puts(" Spaceship Log Content - #{file}")
      puts("-----------------------------------------------------------------------------------")
      puts(data)
      puts("\n")
    end
  end

  # Print paths
  if print_paths
    puts("-----------------------------------------------------------------------------------")
    puts(" Spaceship Log Paths")
    puts("-----------------------------------------------------------------------------------")
    files.each do |file|
      puts(file)
    end
    puts("\n")
  end

  # Copy to a directory
  if copy_to_path
    require 'fileutils'
    FileUtils.mkdir_p(copy_to_path)
    files.each do |file|
      FileUtils.cp(file, copy_to_path)
    end
  end

  # Copy contents to clipboard
  if copy_to_clipboard
    string = files.map { |file| File.read(file) }.join("\n")
    ClipboardAction.run(value: string)
  end

  return files
end