Class: Fastlane::Saucectl::ConfigGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/saucectl/helper/config.rb

Overview

This class creates saucectl config.yml file based on given specifications

Constant Summary collapse

UI =
FastlaneCore::UI

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ConfigGenerator

Returns a new instance of ConfigGenerator.



19
20
21
# File 'lib/fastlane/plugin/saucectl/helper/config.rb', line 19

def initialize(config)
  @config = config
end

Instance Method Details

#base_configObject



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
# File 'lib/fastlane/plugin/saucectl/helper/config.rb', line 23

def base_config
  {
    'apiVersion' => 'v1alpha',
    'kind' => @config[:kind],
    'defaults' => {
      'timeout' => @config[:timeout],
    },
    'sauce' => {
      'region' => set_region.to_s,
      'concurrency' => @config[:max_concurrency_size],
      'retries' => @config[:retries]
    },
    (@config[:kind]).to_s => set_apps,
    'artifacts' => {
      'download' => {
        'when' => 'always',
        'match' => ['junit.xml'],
        'directory' => './artifacts/'
      }
    },
    'reporters' => {
      'junit' => {
        'enabled' => true
      }
    }
  }
end

#creat_sauce_dirObject



81
82
83
84
# File 'lib/fastlane/plugin/saucectl/helper/config.rb', line 81

def creat_sauce_dir
  dirname = '.sauce'
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
end

#createObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fastlane/plugin/saucectl/helper/config.rb', line 66

def create
  UI.message("Creating saucectl config .....🚕💨")
  file_name = 'config.yml'
  UI.user_error!("❌ Sauce Labs platform does not support virtual device execution for ios apps") if @config[:platform].eql?('ios') && @config[:emulators]

  config = base_config.merge({ 'suites' => suite.generate })
  out_file = File.new(file_name, 'w')
  out_file.puts(config.to_yaml)
  out_file.close
  creat_sauce_dir
  FileUtils.move(file_name, './.sauce')
  UI.message("Successfully created saucectl config ✅") if Dir.exist?('.sauce')
  UI.user_error!("Failed to create saucectl config ❌") unless Dir.exist?('.sauce')
end

#set_appsObject



55
56
57
58
59
60
# File 'lib/fastlane/plugin/saucectl/helper/config.rb', line 55

def set_apps
  {
    'app' => @config[:app],
    'testApp' => @config[:test_app]
  }
end

#set_regionObject



51
52
53
# File 'lib/fastlane/plugin/saucectl/helper/config.rb', line 51

def set_region
  @config[:region] == 'eu' ? 'eu-central-1' : 'us-west-1'
end

#suiteObject



62
63
64
# File 'lib/fastlane/plugin/saucectl/helper/config.rb', line 62

def suite
  @config[:platform].eql?('ios') ? Fastlane::Saucectl::IosSuites.new(@config) : Fastlane::Saucectl::AndroidSuites.new(@config)
end