Class: Fastlane::Actions::SetXcconfigValueAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/xcconfig/actions/set_xcconfig_value_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



53
54
55
# File 'lib/fastlane/plugin/xcconfig/actions/set_xcconfig_value_action.rb', line 53

def self.authors
  ["Sergii Ovcharenko", "steprescott"]
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/xcconfig/actions/set_xcconfig_value_action.rb', line 65

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :name,
                                 env_name: "XCCP_SET_VALUE_PARAM_NAME",
                                 description: "Name of key in xcconfig file",
                                 type: String,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :value,
                                 env_name: "XCCP_SET_VALUE_PARAM_VALUE",
                                 description: "Value to set",
                                 skip_type_validation: true, # skipping type validation as fastlane converts YES/NO/true/false strings into booleans
                                 type: String,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :path,
                                 env_name: "XCCP_SET_VALUE_PARAM_PATH",
                                 description: "Path to xcconfig file you want to update",
                                 type: String,
                                 optional: false,
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find xcconfig file at path '#{value}'") unless File.exist?(File.expand_path(value))
                                 end),
    FastlaneCore::ConfigItem.new(key: :mask_value,
                                  env_name: "XCCP_SET_VALUE_PARAM_MASK_VALUE",
                                  description: "Masks the value from being printed to the console",
                                  optional: true,
                                  is_string: false,
                                  default_value: false)
  ]
end

.descriptionObject



49
50
51
# File 'lib/fastlane/plugin/xcconfig/actions/set_xcconfig_value_action.rb', line 49

def self.description
  'Sets the value of a setting in xcconfig file.'
end

.detailsObject



61
62
63
# File 'lib/fastlane/plugin/xcconfig/actions/set_xcconfig_value_action.rb', line 61

def self.details
  'This action sets the value of a given setting in a given xcconfig file.'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/fastlane/plugin/xcconfig/actions/set_xcconfig_value_action.rb', line 95

def self.is_supported?(platform)
  true
end

.return_valueObject



57
58
59
# File 'lib/fastlane/plugin/xcconfig/actions/set_xcconfig_value_action.rb', line 57

def self.return_value
  nil
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/xcconfig/actions/set_xcconfig_value_action.rb', line 7

def self.run(params)
  path = File.expand_path(params[:path])

  tmp_file = path + '.set'

  name = params[:name]

  # Revert fastlane's auto conversion of strings into booleans
  # https://github.com/fastlane/fastlane/pull/11923
  value = if [true, false].include?(params[:value])
            params[:value] ? 'YES' : 'NO'
          else
            params[:value].strip
          end
  begin
    updated = false

    File.open(tmp_file, 'w') do |file|
      File.open(path).each do |line|
        xcname, = Helper::XcconfigHelper.parse_xcconfig_name_value_line(line)
        if xcname == name
          file.write(name + ' = ' + value + "\n")
          updated = true
        else
          file.write(line.strip + "\n")
        end
      end
      file.write(name + ' = ' + value) unless updated
    end

    if params[:mask_value]
      Fastlane::UI.message("Set `#{name}` to `****`")
    else
      Fastlane::UI.message("Set `#{name}` to `#{value}`")
    end

    FileUtils.cp(tmp_file, path)
  ensure
    File.delete(tmp_file)
  end
end