Class: Fastlane::Helper::TestappioHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/testappio/helper/testappio_helper.rb

Class Method Summary collapse

Class Method Details

.call_ta_cli(command) ⇒ Object

Run the given command



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/fastlane/plugin/testappio/helper/testappio_helper.rb', line 91

def self.call_ta_cli(command)
  UI.message("Starting ta-cli...")
  require 'open3'
  if FastlaneCore::Globals.verbose?
    UI.verbose("ta-cli command:\n\n")
    UI.command(command.to_s)
    UI.verbose("\n\n")
  end
  final_command = command.map { |arg| Shellwords.escape(arg) }.join(" ")
  out = []
  error = []
  Open3.popen3(final_command) do |stdin, stdout, stderr, wait_thr|
    while (line = stdout.gets)
      out << line
      line.strip!

      # Print output as it's generated
      UI.message(line) unless line.empty?

    end
    while (line = stderr.gets)
      error << line.strip!
    end
    exit_status = wait_thr.value
    handle_error(error) unless exit_status.success?
  end
  out.join
end

.check_ta_cliObject

Check if ‘ta_cli` exists, install it if not



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fastlane/plugin/testappio/helper/testappio_helper.rb', line 10

def self.check_ta_cli
  unless system('which ta-cli > /dev/null 2>&1')
    UI.error("ta-cli not found, installing")

    unless system('curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash')
      UI.error("Error installing ta-cli")
      return false
    end
  end

  return true
end

.check_update(self_update) ⇒ Object

Check if there is an update available for ‘ta_cli`, and install it if necessary



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
64
65
66
67
68
# File 'lib/fastlane/plugin/testappio/helper/testappio_helper.rb', line 24

def self.check_update(self_update)
  require 'open3'

  version_output = `ta-cli version`
  UI.verbose(version_output)

  if version_output.include?("breaking changes")
    if self_update
      UI.message("Updating ta-cli due to breaking changes...")
    else
      UI.user_error!("Update necessary due to breaking changes. Please update ta-cli manually or set self_update to true")
      return false
    end
  elsif version_output.include?("New version available")
    if self_update
      UI.message("Updating ta-cli...")
    else
      UI.error("New version available, but skipping update as self_update is set to false.")
      return true
    end
  else
    UI.success("ta-cli is already up-to-date")
    return true
  end

  update_command = "curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash"
  update_output, update_errors, update_status = Open3.capture3(update_command)
  UI.verbose(update_output)

  if update_output.include?("ta-cli successfully installed") || update_output.include?("ta-cli has been updated")
    version_output = `ta-cli version`
    UI.verbose(version_output)

    if version_output.include?("Update necessary due to breaking changes") || version_output.include?("New version available")
      UI.user_error!("Error updating ta-cli: the version is still outdated")
      return false
    else
      UI.success("ta-cli has been updated successfully")
      return true
    end
  else
    UI.user_error!("Error updating ta-cli: #{update_output}")
    return false
  end
end

.handle_error(errors) ⇒ Object

Handle errors from ‘ta_cli`, if contains ’Error’, the process stops, otherwise, just print to user console



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fastlane/plugin/testappio/helper/testappio_helper.rb', line 72

def self.handle_error(errors)
  errors.each do |error|
    if error
      if error =~ /Error/
        UI.error(error.to_s)
      else
        UI.verbose(error.to_s)
      end
    end
  end

  if errors.any? { |e| e =~ /Error/ }
    UI.user_error!('Error while calling ta-cli')
  elsif errors.any?
    UI.user_error!("Error while calling ta-cli: #{errors.join(', ')}")
  end
end