class Fastlane::Actions::PrepareSnapfilesAction

To share this integration with the other fastlane users:

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/mobile_common/actions/prepare_snapfiles.rb, line 119
def self.authors
  # So no one will ever forget your contribution to fastlane :) You are awesome btw!
  ['SemenovAlexander']
end
available_options() click to toggle source
# File lib/fastlane/plugin/mobile_common/actions/prepare_snapfiles.rb, line 70
def self.available_options
  # Define all options your action supports.

  # Below a few examples
  [
    FastlaneCore::ConfigItem.new(key: :devices,
                                 env_name: 'FL_PREPARE_SNAPFILES_DEVICES', # The name of the environment variable
                                 description: 'Array with names of simulator devices to use', # a short description of this parameter
                                 is_string: false,
                                 verify_block: proc do |value|
                                   UI.user_error!("No Devices for PrepareSnapfilesAction given, pass using `devices: ['iPhone 4s', 'iPhone 6',...]`") unless value && !value.empty?
                                   # UI.user_error!("Invalid devices passed: #{value}. Please, pass array of devices!") unless value.kind_of?(Array)
                                 end),
    FastlaneCore::ConfigItem.new(key: :languages,
                                 env_name: 'FL_PREPARE_SNAPFILES_LANGUAGES', # The name of the environment variable
                                 description: 'Array with names of langugages to use', # a short description of this parameter
                                 is_string: false,
                                 verify_block: proc do |value|
                                   UI.user_error!("No languages for PrepareSnapfilesAction given, pass using `languages: ['en-US', 'ru-RU']`") unless value && !value.empty?
                                   # UI.user_error!("Invalid languages passed: #{value}. Please, pass array of languages!") unless value.kind_of?(Array)
                                 end),
    FastlaneCore::ConfigItem.new(key: :snapfile_template_path,
                                 env_name: 'FL_PREPARE_SNAPFILES_TEMPLATE_PATH', # The name of the environment variable
                                 description: 'path for template snapfile, to which info will be added', # a short description of this parameter
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :screenshots_path,
                                 env_name: 'FL_PREPARE_SNAPFILES_SCREENSHOTS_PATH', # The name of the environment variable
                                 description: 'Base directory for screenshots, from where action will separate snapfiles through language dirs', # a short description of this parameter
                                 default_value: 'screenshots-ui-test'),
    FastlaneCore::ConfigItem.new(key: :ios_version,
                                 env_name: 'FL_PREPARE_SNAPFILES_IOS_VERSION', # The name of the environment variable
                                 description: 'Optional ios version to be added in generated snapfile as param', # a short description of this parameter
                                 default_value: '')

  ]
end
description() click to toggle source

@!group Documentation

# File lib/fastlane/plugin/mobile_common/actions/prepare_snapfiles.rb, line 60
def self.description
  'Generates snapfile from template in each language/device folder combination'
end
details() click to toggle source
# File lib/fastlane/plugin/mobile_common/actions/prepare_snapfiles.rb, line 64
def self.details
  # Optional:
  # this is your change to provide a more detailed description of this action
  'You can use this action to generate individual snapshot report for each language/device combination. Just run snapshot for each path, returned in PREPARE_SNAPFILES_FILES_PATHS shared value'
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/mobile_common/actions/prepare_snapfiles.rb, line 124
def self.is_supported?(platform)
  [:ios, :mac].include? platform
end
output() click to toggle source
# File lib/fastlane/plugin/mobile_common/actions/prepare_snapfiles.rb, line 107
def self.output
  # Define the shared values you are going to provide
  # Example
  [
    ['PREPARE_SNAPFILES_FILES_PATHS', 'Array with paths to generated Snapfiles']
  ]
end
return_value() click to toggle source
# File lib/fastlane/plugin/mobile_common/actions/prepare_snapfiles.rb, line 115
def self.return_value
  'Returns array of paths to generated Snapfiles'
end
run(params) click to toggle source
# File lib/fastlane/plugin/mobile_common/actions/prepare_snapfiles.rb, line 14
def self.run(params)
  require 'fileutils'
  Dir.chdir(FastlaneCore::FastlaneFolder.path) do
    if params[:snapfile_template_path].to_s != ''
      snapfile_template_path = params[:snapfile_template_path]
    else
      lib_path = File.join(Helper.gem_path('fastlane-plugin-mobile_common'), "lib")
      snapfile_template_path = File.join(lib_path, "assets/Snapfile-template")
    end

    template = File.read(snapfile_template_path)

    devices = params[:devices]
    langs = params[:languages]
    base_path = params[:screenshots_path]
    result_paths = []
    ios_version = params[:ios_version]
    langs.each do |item|
      language = item
      devices.each do |device|
        path = base_path + '/' + language + '/' + device
        path += " (#{ios_version})" unless ios_version.empty?
        FileUtils.mkdir_p path
        File.open(path + '/Snapfile', 'w') do |fo|
          fo.puts template
          fo.puts "\n"
          fo.puts "output_directory \"fastlane/#{path}\""
          fo.puts "\n"
          fo.puts "devices([\"#{device}\"])"
          fo.puts "\n"
          fo.puts "languages([\"#{language}\"])"
          fo.puts "\n"
          fo.puts "ios_version '#{ios_version}'" unless ios_version.empty?
        end
        result_paths << path
      end
    end
    Actions.lane_context[SharedValues::PREPARE_SNAPFILES_FILES_PATHS] = result_paths
    return result_paths
  end
end