Class: Fastlane::Actions::EmergeAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



131
132
133
# File 'lib/fastlane/plugin/emerge/actions/emerge_action.rb', line 131

def self.authors
  ["Emerge Tools"]
end

.available_optionsObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/fastlane/plugin/emerge/actions/emerge_action.rb', line 143

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "EMERGE_API_TOKEN",
                                 description: "An API token for Emerge",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :file_path,
                                 env_name: "EMERGE_FILE_PATH",
                                 description: "Path to the zipped xcarchive or app to upload",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :linkmaps,
                                 description: "List of paths to linkmaps",
                                 optional: true,
                                 type: Array),
    FastlaneCore::ConfigItem.new(key: :pr_number,
                                 description: "The PR number that triggered this upload",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :branch,
                                 description: "The current git branch",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :sha,
                                 description: "The git SHA that triggered this build",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :base_sha,
                                 description: "The git SHA of the base build",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :build_id,
                                 description: "A string to identify this build",
                                 deprecated: "Replaced by `sha`",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :base_build_id,
                                 description: "Id of the build to compare with this upload",
                                 deprecated: "Replaced by `base_sha`",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :repo_name,
                                 description: "Full name of the respository this upload was triggered from. For example: EmergeTools/Emerge",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :gitlab_project_id,
                                 description: "Id of the gitlab project this upload was triggered from",
                                 optional: true,
                                 type: Integer),
    FastlaneCore::ConfigItem.new(key: :tag,
                                 description: "String to label the build. Useful for grouping builds together in our dashboard, like development, default, or pull-request",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :order_file_version,
                                 description: "Version of the order file to download",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :config_path,
                                 description: "Path to Emerge config path",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :app_id_suffix,
                                 description: "A suffix to append to the application ID to differentiate between different builds of the same app",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :release_notes,
                                 description: "A markdown string with release notes for the upload",
                                 optional: true,
                                 type: String)
  ]
end

.copy_dsyms(from, to) ⇒ Object



120
121
122
123
124
125
# File 'lib/fastlane/plugin/emerge/actions/emerge_action.rb', line 120

def self.copy_dsyms(from, to)
  Dir.glob(from) do |filename|
    UI.message("Found dSYM: #{Pathname.new(filename).basename}")
    FileUtils.cp_r(filename, to)
  end
end

.descriptionObject



127
128
129
# File 'lib/fastlane/plugin/emerge/actions/emerge_action.rb', line 127

def self.description
  "Fastlane plugin for Emerge"
end

.detailsObject



139
140
141
# File 'lib/fastlane/plugin/emerge/actions/emerge_action.rb', line 139

def self.details
  ""
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/fastlane/plugin/emerge/actions/emerge_action.rb', line 216

def self.is_supported?(platform)
  platform == :ios
end

.return_valueObject



135
136
137
# File 'lib/fastlane/plugin/emerge/actions/emerge_action.rb', line 135

def self.return_value
  "If successful, returns the upload id of the generated build"
end

.run(params) ⇒ Object



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
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/emerge/actions/emerge_action.rb', line 14

def self.run(params)
  api_token = params[:api_token]

  file_path = if params[:file_path]
                UI.message("Using input file_path: #{file_path}")
                params[:file_path]
              elsif lane_context[SharedValues::XCODEBUILD_ARCHIVE]
                UI.message("Using XCODEBUILD_ARCHIVE path")
                lane_context[SharedValues::XCODEBUILD_ARCHIVE]
              else
                UI.message("Falling back to searching SCAN_DERIVED_DATA_PATH")
                Dir.glob("#{lane_context[SharedValues::SCAN_DERIVED_DATA_PATH]}/Build/Products/Debug-iphonesimulator/*.app").first
              end

  git_params = Helper::EmergeHelper.make_git_params
  pr_number = params[:pr_number] || git_params.pr_number
  branch = params[:branch] || git_params.branch
  sha = params[:sha] || params[:build_id] || git_params.sha
  base_sha = params[:base_sha] || params[:base_build_id] || git_params.base_sha
  repo_name = params[:repo_name] || git_params.repo_name
  gitlab_project_id = params[:gitlab_project_id]
  tag = params[:tag]
  order_file_version = params[:order_file_version]
  config_path = params[:config_path]

  if file_path.nil? || !File.exist?(file_path)
    UI.error("Invalid input file")
    return false
  else
    UI.message("Using file_path: #{file_path}")
  end
  extension = File.extname(file_path)

  # If the user provided a .app we will look for dsyms and package it into a zipped xcarchive
  if extension == '.app'
    absolute_path = Pathname.new(File.expand_path(file_path))
    UI.message("A .app was provided, dSYMs will be looked for in #{absolute_path.dirname}")
    Dir.mktmpdir do |d|
      application_folder = "#{d}/archive.xcarchive/Products/Applications/"
      dsym_folder = "#{d}/archive.xcarchive/dSYMs/"
      FileUtils.mkdir_p(application_folder)
      FileUtils.mkdir_p(dsym_folder)
      if params[:linkmaps] && params[:linkmaps].length > 0
        linkmap_folder = "#{d}/archive.xcarchive/Linkmaps/"
        FileUtils.mkdir_p(linkmap_folder)
        params[:linkmaps].each do |l|
          FileUtils.cp(l, linkmap_folder)
        end
      end
      Helper::EmergeHelper.copy_config(config_path, "#{d}/archive.xcarchive")
      FileUtils.cp_r(file_path, application_folder)
      copy_dsyms("#{absolute_path.dirname}/*.dsym", dsym_folder)
      copy_dsyms("#{absolute_path.dirname}/*/*.dsym", dsym_folder)
      Xcodeproj::Plist.write_to_path({ "NAME" => "Emerge Upload" }, "#{d}/archive.xcarchive/Info.plist")
      file_path = "#{absolute_path.dirname}/archive.xcarchive.zip"
      ZipAction.run(
        path: "#{d}/archive.xcarchive",
        symlinks: true,
        output_path: file_path,
        exclude: [],
        include: []
      )
      UI.message("Archive generated at #{file_path}")
    end
  elsif extension == '.xcarchive'
    zip_path = file_path + ".zip"
    if params[:linkmaps] && params[:linkmaps].length > 0
      linkmap_folder = "#{file_path}/Linkmaps/"
      FileUtils.mkdir_p(linkmap_folder)
      params[:linkmaps].each do |l|
        FileUtils.cp(l, linkmap_folder)
      end
    end
    Helper::EmergeHelper.copy_config(config_path, file_path)
    Actions::ZipAction.run(
      path: file_path,
      symlinks: true,
      output_path: zip_path,
      exclude: [],
      include: []
    )
    file_path = zip_path
  elsif (extension == '.zip' || extension == '.ipa') && params[:linkmaps] && params[:linkmaps].length > 0
    UI.error("Provided #{extension == '.zip' ? 'zipped archive' : 'ipa'} and linkmaps, linkmaps will not be added to upload.")
  elsif extension != '.zip' && extension != '.ipa'
    UI.error("Invalid input file")
    return false
  end

  params = {
    prNumber: pr_number,
    branch: branch,
    sha: sha,
    baseSha: base_sha,
    repoName: repo_name,
    gitlabProjectId: gitlab_project_id,
    orderFileVersion: order_file_version,
    appIdSuffix: params[:app_id_suffix],
    releaseNotes: params[:release_notes],
    tag: tag || "default"
  }
  upload_id = Helper::EmergeHelper.perform_upload(api_token, params, file_path)
  UI.success("🎉 Your app is processing, you can find the results at https://emergetools.com/build/#{upload_id}")
  upload_id
end