Class: Fastlane::Actions::EmergeSnapshotAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



85
86
87
# File 'lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb', line 85

def self.authors
  ["Emerge Tools"]
end

.available_optionsObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb', line 97

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: :scheme,
                                 description: "The scheme of your app to build",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :configuration,
                                 description: "The configuration of your app to use",
                                 optional: false,
                                 default_value: "Debug",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :team_id,
                                 env_name: "EXPORT_TEAM_ID",
                                 description: "The Apple Team ID to use for exporting the archive. If not provided, we will try to use the team_id from the Appfile",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :config_path,
                                 description: "Path to Emerge YAML config path",
                                 optional: true,
                                 type: String),
    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: :previous_sha,
                                 description: "The git SHA of the commit right before this build's commit",
                                 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)
  ]
end

.descriptionObject



81
82
83
# File 'lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb', line 81

def self.description
  "Fastlane plugin for Emerge to generate iOS snapshots"
end

.detailsObject



93
94
95
# File 'lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb', line 93

def self.details
  ""
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb', line 157

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

.make_debug_build(scheme:, configuration:, team_id:, archive_path:) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb', line 68

def self.make_debug_build(scheme:, configuration:, team_id:, archive_path:)
  other_action.gym(
    scheme: scheme,
    configuration: configuration,
    skip_codesigning: true,
    clean: true,
    export_method: "development",
    export_team_id: team_id,
    skip_package_ipa: true,
    archive_path: archive_path
  )
end

.return_valueObject



89
90
91
# File 'lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb', line 89

def self.return_value
  "If successful, returns the upload id of the generated snapshot 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
# File 'lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb', line 14

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

  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] || git_params.sha
  base_sha = params[:base_sha] || git_params.base_sha
  previous_sha = params[:previous_sha] || git_params.previous_sha
  repo_name = params[:repo_name] || git_params.repo_name
  gitlab_project_id = params[:gitlab_project_id]
  tag = params[:tag]
  config_path = params[:config_path]
  scheme = params[:scheme]
  configuration = params[:configuration]
  team_id = params[:team_id] || CredentialsManager::AppfileConfig.try_fetch_value(:team_id)

  Dir.mktmpdir do |temp_dir|
    archive_name = "#{scheme}-Emerge-Snapshots"
    archive_path = "#{temp_dir}/build/#{archive_name}.xcarchive"
    make_debug_build(
      scheme: scheme,
      configuration: configuration,
      team_id: team_id,
      archive_path: archive_path
    )
    Helper::EmergeHelper.copy_config(config_path, archive_path)
    Xcodeproj::Plist.write_to_path({ "NAME" => "Emerge Upload" }, "#{archive_path}/Info.plist")

    zip_file_path = "#{temp_dir}/build/#{archive_name}.xcarchive.zip"
    ZipAction.run(
      path: archive_path,
      symlinks: true,
      output_path: zip_file_path,
      exclude: [],
      include: []
    )

    params = {
      appIdSuffix: 'snapshots',
      prNumber: pr_number,
      branch: branch,
      sha: sha,
      baseSha: base_sha,
      previousSha: previous_sha,
      repoName: repo_name,
      gitlabProjectId: gitlab_project_id,
      tag: tag || "default"
    }
    upload_id = Helper::EmergeHelper.perform_upload(api_token, params, zip_file_path)
    UI.success("🎉 Your app is processing, you can find the results at https://emergetools.com/snapshot/#{upload_id}")
  end
end