fastlane-plugin-emerge 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e170856bceb03b9747e72d074ce9a96d124dfe6519e5bc9f47becffb39b1acea
4
- data.tar.gz: 71d34166a5fa640ac3af5ec2763a8b373052e3da358c0dc68dce5ed4bb46bd32
3
+ metadata.gz: 0d2c3b1e6fa8f6246418040883cdbdf868dd54058e363f1c6de46a4f63646543
4
+ data.tar.gz: 0f601eeb52b1041210eb5620ab44bf18c233be7d3b873c320cf2aae0d4f4fc78
5
5
  SHA512:
6
- metadata.gz: '07929884d01b7ce42b2863dc9973768b2bb033da495e6d63c6dd09a66e63d6613e55c41a0845eff819afcd8689897d5c32c6099028e0059e2f12df9aed1470af'
7
- data.tar.gz: a971a076cb1724adec271841883b49a0ecfac4fe245884076b64cc655f1fabf930af60830f76cf7dbd46005d6e28c5a16d01d716a6ae63133df8a7cf6a013f56
6
+ metadata.gz: ea622f13cae0b3f362687e1cadb631ca17f35c5330f23d1475c9185c4b8a166a6fbc992d5e19dd79846f7fe0a6823ea9b8aed00dbcf60a1ff7070236eea18ba5
7
+ data.tar.gz: 0c448cfd0fda4d20031e25101f41c7835c22a507c26e39337a83ad7868259d6c348b7a3e1bfacf0212ec6d60ebc323c13bbdfe9e5b4f9feebb9f10428b2760db
data/README.md CHANGED
@@ -12,24 +12,60 @@ fastlane add_plugin emerge
12
12
 
13
13
  ## About Emerge
14
14
 
15
- Fastlane plugin for Emerge
15
+ [Emerge](https://emergetools.com) offers a suite of products to help optimize app size, performance and quality. This plugin provides a set of actions to interact with the Emerge API.
16
16
 
17
- ## Run tests for this plugin
17
+ ## Usage
18
18
 
19
- To run both the tests, and code style validation, run
19
+ To get started, first obtain an [API token](https://docs.emergetools.com/docs/uploading-basics#obtain-an-api-key) for your organization. The API Token is used to authenticate with the Emerge API in each call.
20
20
 
21
- ```
22
- rake
23
- ```
21
+ ```ruby
22
+ # Your EMERGE_API_TOKEN is available on your Emerge profile page: https://www.emergetools.com/profile
23
+ ENV['EMERGE_API_TOKEN'] = 'COPIED_FROM_EMERGETOOLS_PROFILE'
24
24
 
25
- To automatically fix many of the styling issues, use
25
+ platform {:ios} do
26
+ lane :app_size do
27
+ emerge()
28
+ end
29
+ end
26
30
  ```
27
- rubocop -a
31
+
32
+ For a full list of available parameters run `fastlane action emerge`.
33
+
34
+ ## Git Configuration
35
+
36
+ For build comparisons to work, Emerge needs the appropriate Git `sha` and `base_sha` values set on each build. Emerge will automatically compare a build at `sha` against the build we find matching the `base_sha` for a given application id. We also recommend setting `pr_number`, `branch`, and `repo_name` for the best experience.
37
+
38
+ For example:
39
+
40
+ - `sha`: `pr-branch-commit-1`
41
+ - `base_sha`: `main-branch-commit-1`
42
+ - `pr_number`: `42`
43
+ - `branch`: `my-awesome-feature`
44
+ - `repo_name`: `EmergeTools/hackernews`
45
+
46
+ Will compare the size difference of your pull request changes.
47
+
48
+ This plugin will automatically configure Git values for you assuming certain Github workflow triggers:
49
+
50
+ ```yaml
51
+ on:
52
+ # Produce base builds with a 'sha' when commits are pushed to the main branch
53
+ push:
54
+ branches: [main]
55
+
56
+ # Produce branch comparison builds with `sha` and `base_sha` when commits are pushed
57
+ # to open pull requests
58
+ pull_request:
59
+ branches: [main]
60
+
61
+ ...
28
62
  ```
29
63
 
64
+ If this doesn't cover your use-case, manually set the `sha` and `base_sha` values when calling the Emerge plugin.
65
+
30
66
  ## Issues and Feedback
31
67
 
32
- For any other issues and feedback about this plugin, please submit it to this repository.
68
+ For any other issues and feedback about this plugin, please open a [GitHub issue](https://github.com/EmergeTools/fastlane-plugin-emerge/issues).
33
69
 
34
70
  ## Troubleshooting
35
71
 
@@ -50,7 +50,7 @@ module Fastlane
50
50
  FileUtils.cp(l, linkmap_folder)
51
51
  end
52
52
  end
53
- copy_config(config_path, "#{d}/archive.xcarchive")
53
+ Helper::EmergeHelper.copy_config(config_path, "#{d}/archive.xcarchive")
54
54
  FileUtils.cp_r(file_path, application_folder)
55
55
  copy_dsyms("#{absolute_path.dirname}/*.dsym", dsym_folder)
56
56
  copy_dsyms("#{absolute_path.dirname}/*/*.dsym", dsym_folder)
@@ -73,7 +73,7 @@ module Fastlane
73
73
  FileUtils.cp(l, linkmap_folder)
74
74
  end
75
75
  end
76
- copy_config(config_path, file_path)
76
+ Helper::EmergeHelper.copy_config(config_path, file_path)
77
77
  Actions::ZipAction.run(
78
78
  path: file_path,
79
79
  output_path: zip_path,
@@ -88,62 +88,18 @@ module Fastlane
88
88
  return
89
89
  end
90
90
 
91
- filename = File.basename(file_path)
92
- url = 'https://api.emergetools.com/upload'
93
91
  params = {
94
- filename: filename
92
+ prNumber: pr_number,
93
+ branch: branch,
94
+ sha: sha,
95
+ baseSha: base_sha,
96
+ repoName: repo_name,
97
+ gitlabProjectId: gitlab_project_id,
98
+ orderFileVersion: order_file_version,
99
+ tag: tag || "default"
95
100
  }
96
- if pr_number
97
- params[:prNumber] = pr_number
98
- end
99
- if branch
100
- params[:branch] = branch
101
- end
102
- if sha
103
- params[:sha] = sha
104
- end
105
- if base_sha
106
- params[:baseSha] = base_sha
107
- end
108
- if repo_name
109
- params[:repoName] = repo_name
110
- end
111
- if gitlab_project_id
112
- params[:gitlabProjectId] = gitlab_project_id
113
- end
114
- if order_file_version
115
- params[:orderFileVersion] = order_file_version
116
- end
117
- params[:tag] = tag || "default"
118
- FastlaneCore::PrintTable.print_values(
119
- config: params,
120
- hide_keys: [],
121
- title: "Summary for Emerge #{Fastlane::Emerge::VERSION}"
122
- )
123
- resp = Faraday.post(
124
- url,
125
- params.to_json,
126
- 'Content-Type' => 'application/json', 'X-API-Token' => api_token, 'User-Agent' => "fastlane-plugin-emerge/#{Fastlane::Emerge::VERSION}"
127
- )
128
- case resp.status
129
- when 200
130
- json = JSON.parse(resp.body)
131
- upload_id = json["upload_id"]
132
- upload_url = json["uploadURL"]
133
- warning = json["warning"]
134
- if warning
135
- UI.important(warning)
136
- end
137
- return Helper::EmergeHelper.perform_upload(upload_url, upload_id, file_path)
138
- when 403
139
- UI.error("Invalid API token")
140
- when 400
141
- UI.error("Invalid parameters")
142
- json = JSON.parse(resp.body)
143
- UI.error("Error: #{json['errorMessage']}")
144
- else
145
- UI.error("Upload failed")
146
- end
101
+ upload_id = Helper::EmergeHelper.perform_upload(api_token, params, file_path)
102
+ UI.success("🎉 Your app is processing, you can find the results at https://emergetools.com/build/#{upload_id}")
147
103
  end
148
104
 
149
105
  def self.copy_dsyms(from, to)
@@ -153,19 +109,6 @@ module Fastlane
153
109
  end
154
110
  end
155
111
 
156
- def self.copy_config(config_path, tmp_dir)
157
- return if config_path.nil?
158
-
159
- expanded_path = File.expand_path(config_path)
160
- unless File.exist?(expanded_path)
161
- UI.error("No config file found at path '#{expanded_path}'.\nUploading without config file")
162
- return
163
- end
164
-
165
- emerge_config_path = "#{tmp_dir}/emerge_config.yaml"
166
- FileUtils.cp(expanded_path, emerge_config_path)
167
- end
168
-
169
112
  def self.description
170
113
  "Fastlane plugin for Emerge"
171
114
  end
@@ -0,0 +1,155 @@
1
+ require 'fastlane/action'
2
+ require 'fastlane_core/print_table'
3
+ require_relative '../helper/emerge_helper'
4
+ require_relative '../helper/git'
5
+ require_relative '../helper/github'
6
+ require 'pathname'
7
+ require 'tmpdir'
8
+ require 'json'
9
+ require 'fileutils'
10
+
11
+ module Fastlane
12
+ module Actions
13
+ class EmergeSnapshotAction < Action
14
+ def self.run(params)
15
+ api_token = params[:api_token]
16
+
17
+ git_params = Helper::EmergeHelper.make_git_params
18
+ pr_number = params[:pr_number] || git_params.pr_number
19
+ branch = params[:branch] || git_params.branch
20
+ sha = params[:sha] || git_params.sha
21
+ base_sha = params[:base_sha] || git_params.base_sha
22
+ repo_name = params[:repo_name] || git_params.repo_name
23
+ gitlab_project_id = params[:gitlab_project_id]
24
+ tag = params[:tag]
25
+ config_path = params[:config_path]
26
+ scheme = params[:scheme]
27
+ configuration = params[:configuration]
28
+ team_id = params[:team_id] || CredentialsManager::AppfileConfig.try_fetch_value(:team_id)
29
+
30
+ Dir.mktmpdir do |temp_dir|
31
+ archive_name = "#{scheme}-Emerge-Snapshots"
32
+ archive_path = "#{temp_dir}/build/#{archive_name}.xcarchive"
33
+ make_debug_build(
34
+ scheme: scheme,
35
+ configuration: configuration,
36
+ team_id: team_id,
37
+ archive_path: archive_path
38
+ )
39
+ Helper::EmergeHelper.copy_config(config_path, archive_path)
40
+ Xcodeproj::Plist.write_to_path({ "NAME" => "Emerge Upload" }, "#{archive_path}/Info.plist")
41
+
42
+ zip_file_path = "#{temp_dir}/build/#{archive_name}.xcarchive.zip"
43
+ ZipAction.run(
44
+ path: archive_path,
45
+ output_path: zip_file_path,
46
+ exclude: [],
47
+ include: []
48
+ )
49
+
50
+ params = {
51
+ appIdSuffix: 'snapshots',
52
+ prNumber: pr_number,
53
+ branch: branch,
54
+ sha: sha,
55
+ baseSha: base_sha,
56
+ repoName: repo_name,
57
+ gitlabProjectId: gitlab_project_id,
58
+ tag: tag || "default"
59
+ }
60
+ upload_id = Helper::EmergeHelper.perform_upload(api_token, params, zip_file_path)
61
+ UI.success("🎉 Your app is processing, you can find the results at https://emergetools.com/snapshot/#{upload_id}")
62
+ end
63
+ end
64
+
65
+ def self.make_debug_build(scheme:, configuration:, team_id:, archive_path:)
66
+ other_action.gym(
67
+ scheme: scheme,
68
+ configuration: configuration,
69
+ skip_codesigning: true,
70
+ clean: true,
71
+ export_method: "development",
72
+ export_team_id: team_id,
73
+ skip_package_ipa: true,
74
+ archive_path: archive_path
75
+ )
76
+ end
77
+
78
+ def self.description
79
+ "Fastlane plugin for Emerge to generate iOS snapshots"
80
+ end
81
+
82
+ def self.authors
83
+ ["Emerge Tools"]
84
+ end
85
+
86
+ def self.return_value
87
+ "If successful, returns the upload id of the generated snapshot build"
88
+ end
89
+
90
+ def self.details
91
+ ""
92
+ end
93
+
94
+ def self.available_options
95
+ [
96
+ FastlaneCore::ConfigItem.new(key: :api_token,
97
+ env_name: "EMERGE_API_TOKEN",
98
+ description: "An API token for Emerge",
99
+ optional: false,
100
+ type: String),
101
+ FastlaneCore::ConfigItem.new(key: :scheme,
102
+ description: "The scheme of your app to build",
103
+ optional: false,
104
+ type: String),
105
+ FastlaneCore::ConfigItem.new(key: :configuration,
106
+ description: "The configuration of your app to use",
107
+ optional: false,
108
+ default_value: "Debug",
109
+ type: String),
110
+ FastlaneCore::ConfigItem.new(key: :team_id,
111
+ env_name: "EXPORT_TEAM_ID",
112
+ 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",
113
+ optional: true,
114
+ type: String),
115
+ FastlaneCore::ConfigItem.new(key: :config_path,
116
+ description: "Path to Emerge YAML config path",
117
+ optional: true,
118
+ type: String),
119
+ FastlaneCore::ConfigItem.new(key: :pr_number,
120
+ description: "The PR number that triggered this upload",
121
+ optional: true,
122
+ type: String),
123
+ FastlaneCore::ConfigItem.new(key: :branch,
124
+ description: "The current git branch",
125
+ optional: true,
126
+ type: String),
127
+ FastlaneCore::ConfigItem.new(key: :sha,
128
+ description: "The git SHA that triggered this build",
129
+ optional: true,
130
+ type: String),
131
+ FastlaneCore::ConfigItem.new(key: :base_sha,
132
+ description: "The git SHA of the base build",
133
+ optional: true,
134
+ type: String),
135
+ FastlaneCore::ConfigItem.new(key: :repo_name,
136
+ description: "Full name of the respository this upload was triggered from. For example: EmergeTools/Emerge",
137
+ optional: true,
138
+ type: String),
139
+ FastlaneCore::ConfigItem.new(key: :gitlab_project_id,
140
+ description: "Id of the gitlab project this upload was triggered from",
141
+ optional: true,
142
+ type: Integer),
143
+ FastlaneCore::ConfigItem.new(key: :tag,
144
+ description: "String to label the build. Useful for grouping builds together in our dashboard, like development, default, or pull-request",
145
+ optional: true,
146
+ type: String)
147
+ ]
148
+ end
149
+
150
+ def self.is_supported?(platform)
151
+ platform == :ios
152
+ end
153
+ end
154
+ end
155
+ end
@@ -18,21 +18,16 @@ module Fastlane
18
18
 
19
19
  module Helper
20
20
  class EmergeHelper
21
- def self.perform_upload(upload_url, upload_id, file_path)
22
- UI.message("Starting upload")
23
- response = Faraday.put(upload_url) do |req|
24
- req.headers['Content-Type'] = 'application/zip'
25
- req.headers['Content-Length'] = File.size(file_path).to_s
26
- req.body = Faraday::UploadIO.new(file_path, 'application/zip')
27
- end
28
- case response.status
29
- when 200
30
- UI.success("🎉 Your app is processing, you can find the results at https://emergetools.com/build/#{upload_id}")
31
- return upload_id
32
- else
33
- UI.error("Upload failed")
34
- end
35
- return nil
21
+ API_URL = 'https://api.emergetools.com/upload'.freeze
22
+
23
+ def self.perform_upload(api_token, params, file_path)
24
+ cleaned_params = clean_params(params)
25
+ print_summary(cleaned_params)
26
+
27
+ upload_response = create_upload(api_token, cleaned_params)
28
+ handle_upload_response(api_token, upload_response, file_path)
29
+ rescue StandardError => e
30
+ UI.user_error!(e.message)
36
31
  end
37
32
 
38
33
  def self.make_git_params
@@ -56,6 +51,84 @@ module Fastlane
56
51
  UI.message("Got git result #{git_result.inspect}")
57
52
  git_result
58
53
  end
54
+
55
+ def self.copy_config(config_path, tmp_dir)
56
+ return if config_path.nil?
57
+
58
+ expanded_path = File.expand_path(config_path)
59
+ unless File.exist?(expanded_path)
60
+ UI.error("No config file found at path '#{expanded_path}'.\nUploading without config file")
61
+ return
62
+ end
63
+
64
+ emerge_config_path = "#{tmp_dir}/emerge_config.yaml"
65
+ FileUtils.cp(expanded_path, emerge_config_path)
66
+ end
67
+
68
+ private_class_method
69
+
70
+ def self.clean_params(params)
71
+ params.reject { |_, v| v.nil? }
72
+ end
73
+
74
+ def self.print_summary(params)
75
+ FastlaneCore::PrintTable.print_values(
76
+ config: params,
77
+ hide_keys: [],
78
+ title: "Summary for Emerge Upload #{Fastlane::Emerge::VERSION}"
79
+ )
80
+ end
81
+
82
+ def self.create_upload(api_token, params)
83
+ response = Faraday.post(API_URL, params.to_json, headers(api_token, params, 'application/json'))
84
+ parse_response(response)
85
+ end
86
+
87
+ def self.headers(api_token, params, content_type)
88
+ {
89
+ 'Content-Type' => content_type,
90
+ 'X-API-Token' => api_token,
91
+ 'User-Agent' => "fastlane-plugin-emerge/#{Fastlane::Emerge::VERSION}"
92
+ }
93
+ end
94
+
95
+ def self.parse_response(response)
96
+ case response.status
97
+ when 200
98
+ JSON.parse(response.body)
99
+ when 400
100
+ error_message = JSON.parse(response.body)['errorMessage']
101
+ raise "Invalid parameters: #{error_message}"
102
+ when 401, 403
103
+ raise 'Invalid API token'
104
+ else
105
+ raise "Creating upload failed with status #{response.status}"
106
+ end
107
+ end
108
+
109
+ def self.handle_upload_response(api_token, response, file_path)
110
+ upload_url = response.fetch('uploadURL')
111
+ upload_id = response.fetch('upload_id')
112
+
113
+ warning = response.dig('warning')
114
+ if warning
115
+ UI.important(warning)
116
+ end
117
+
118
+ UI.message('Starting zip file upload')
119
+ upload_file(api_token, upload_url, file_path)
120
+ upload_id
121
+ end
122
+
123
+ def self.upload_file(api_token, upload_url, file_path)
124
+ response = Faraday.put(upload_url) do |req|
125
+ req.headers = headers(api_token, nil, 'application/zip')
126
+ req.headers['Content-Length'] = File.size(file_path).to_s
127
+ req.body = Faraday::UploadIO.new(file_path, 'application/zip')
128
+ end
129
+
130
+ raise "Uploading zip file failed #{response.status}" unless response.status == 200
131
+ end
59
132
  end
60
133
  end
61
134
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Emerge
3
- VERSION = "0.8.0"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-emerge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emerge Tools, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-08 00:00:00.000000000 Z
11
+ date: 2024-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -162,6 +162,7 @@ files:
162
162
  - lib/fastlane/plugin/emerge/actions/emerge_action.rb
163
163
  - lib/fastlane/plugin/emerge/actions/emerge_comment_action.rb
164
164
  - lib/fastlane/plugin/emerge/actions/emerge_order_file_action.rb
165
+ - lib/fastlane/plugin/emerge/actions/emerge_snapshot_action.rb
165
166
  - lib/fastlane/plugin/emerge/helper/emerge_helper.rb
166
167
  - lib/fastlane/plugin/emerge/helper/git.rb
167
168
  - lib/fastlane/plugin/emerge/helper/github.rb
@@ -185,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
186
  - !ruby/object:Gem::Version
186
187
  version: '0'
187
188
  requirements: []
188
- rubygems_version: 3.2.3
189
+ rubygems_version: 3.3.25
189
190
  signing_key:
190
191
  specification_version: 4
191
192
  summary: Fastlane plugin for Emerge