Class: Fastlane::Actions::EnSetupProjectAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



127
128
129
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 127

def self.authors
  ["Nicolae Ghimbovschi"]
end

.available_optionsObject



117
118
119
120
121
122
123
124
125
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 117

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :config,
                                 env_name: "EN_SETUP_PROJECT_CONFIG",
                                 description: "Config file path, default it tries to load config.yaml",
                                 is_string: true,
                                 default_value: "config.yaml")
  ]
end

.descriptionObject



83
84
85
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 83

def self.description
  "Updates Xcode project, plist and entitlements file if config file is provided"
end

.detailsObject



87
88
89
90
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
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 87

def self.details
  "Updates Xcode project, plist and entitlements file if config file is provided.

Example a project with two targets info.plist and entitlements.

TestMatch.xcodeproj:
  options:
    CODE_SIGN_IDENTITY: iOS Distribution
    DEVELOPMENT_TEAM: H86U5Z8HYB
    CODE_SIGN_STYLE: Manual
    BUNDLE_ID: com.ghimbovschi.FastlaneDemo
  targets:
    TestMatch:
PRODUCT_BUNDLE_IDENTIFIER: ${BUNDLE_ID}
PROVISIONING_PROFILE_SPECIFIER: match AppStore $(PRODUCT_BUNDLE_IDENTIFIER)

    keyboard:
PRODUCT_BUNDLE_IDENTIFIER: ${BUNDLE_ID}.keyboard
PROVISIONING_PROFILE_SPECIFIER: match AppStore $(PRODUCT_BUNDLE_IDENTIFIER)

TestMatch/Info.plist:
  CFBundleDisplayName: My App

TestMatch/TestMatch.entitlements:
  com.apple.security.application-groups: 


The config file path should be relative to fastlane folder or full path"
end

.file_type(file_path) ⇒ Object



73
74
75
76
77
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 73

def self.file_type(file_path)
    return ResourceType::XcodeProject if file_path.end_with? ".xcodeproj"
    return ResourceType::InfoPlist if file_path.end_with? ".plist"
    return ResourceType::InfoPlist if file_path.end_with? ".entitlements"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 131

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 14

def self.run(params)
  config_file = params[:config]

  unless File.exist?(config_file)
    UI.user_error!("Could not find #{config_file}! Aborting!")
    return
  end

  configurations = YAML.load_file(config_file)
  configurations.each do |file_path, settings|
      file_type = self.file_type(file_path)

      if file_type == ResourceType::XcodeProject
            self.updateXcodeProject(file_path, settings)
      elsif file_type == ResourceType::InfoPlist
            self.updatePlistFile(file_path, settings)
      end
  end
end

.updatePlistFile(file_path, settings) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 57

def self.updatePlistFile(file_path, settings)
    plist = {}
    plist = Plist.parse_xml(file_path) if File.exist?(file_path)
    plist.merge!(settings)

    settings.each do |key, value|
        plist.delete(key) if value == nil
    end

    File.open(file_path, 'w') do |file|
        file.write(plist.to_plist)
    end

    UI.message("#{file_path} has been updated")
end

.updateXcodeProject(project_path, settings) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fastlane/plugin/ciutils/actions/en_setup_project.rb', line 34

def self.updateXcodeProject(project_path, settings)
    project = Xcodeproj::Project.open(project_path)

    common_configurations = settings['common']

    project.targets.each do |target|
        target_configurations = settings['targets'][target.name]
        target_configurations = {} if target_configurations == nil
        target_configurations.merge!(common_configurations) unless common_configurations == nil

        target.build_configurations.each do |config|

            target_configurations.each do |key, value|
                value = "iPhone Distribution" if value == "iOS Distribution"
                config.build_settings[key] = value
            end
        end
    end
    project.save

    UI.message("#{project_path} has been updated")
end