fastlane-plugin-emerge 0.7.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: d4d089c7870b5c71f07b01d99df92996471d9050ab6fd4b0f6c3290648dcd404
4
- data.tar.gz: a98f1c7796d0e21d0a2d7dcbadc20e11d3e2de626e1441da4947610e8433d468
3
+ metadata.gz: 0d2c3b1e6fa8f6246418040883cdbdf868dd54058e363f1c6de46a4f63646543
4
+ data.tar.gz: 0f601eeb52b1041210eb5620ab44bf18c233be7d3b873c320cf2aae0d4f4fc78
5
5
  SHA512:
6
- metadata.gz: 7afe4c7adc02c46fa4193dbed344afc716877d26ca00849f6dce44bdd73e7da8458221aa875e9b9290aeec36c2e08fa2036e71d08581af4de74cb848779fdffe
7
- data.tar.gz: 3fb17574090d31c7088b5afb3e0f9161e627ba777de779887b7d34ee45ea6094d3439bde09851087035d3c2face7be1caf173fb5228e5b81496f412b80d27aa0
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
 
@@ -1,6 +1,8 @@
1
1
  require 'fastlane/action'
2
2
  require 'fastlane_core/print_table'
3
3
  require_relative '../helper/emerge_helper'
4
+ require_relative '../helper/git'
5
+ require_relative '../helper/github'
4
6
  require 'pathname'
5
7
  require 'tmpdir'
6
8
  require 'json'
@@ -16,11 +18,12 @@ module Fastlane
16
18
  if file_path.nil?
17
19
  file_path = Dir.glob("#{lane_context[SharedValues::SCAN_DERIVED_DATA_PATH]}/Build/Products/Debug-iphonesimulator/*.app").first
18
20
  end
19
- pr_number = params[:pr_number]
20
- branch = params[:branch]
21
- sha = params[:sha] || params[:build_id]
22
- base_sha = params[:base_sha] || params[:base_build_id]
23
- repo_name = params[:repo_name]
21
+ git_params = Helper::EmergeHelper.make_git_params
22
+ pr_number = params[:pr_number] || git_params.pr_number
23
+ branch = params[:branch] || git_params.branch
24
+ sha = params[:sha] || params[:build_id] || git_params.sha
25
+ base_sha = params[:base_sha] || params[:base_build_id] || git_params.base_sha
26
+ repo_name = params[:repo_name] || git_params.repo_name
24
27
  gitlab_project_id = params[:gitlab_project_id]
25
28
  tag = params[:tag]
26
29
  order_file_version = params[:order_file_version]
@@ -47,7 +50,7 @@ module Fastlane
47
50
  FileUtils.cp(l, linkmap_folder)
48
51
  end
49
52
  end
50
- copy_config(config_path, "#{d}/archive.xcarchive")
53
+ Helper::EmergeHelper.copy_config(config_path, "#{d}/archive.xcarchive")
51
54
  FileUtils.cp_r(file_path, application_folder)
52
55
  copy_dsyms("#{absolute_path.dirname}/*.dsym", dsym_folder)
53
56
  copy_dsyms("#{absolute_path.dirname}/*/*.dsym", dsym_folder)
@@ -70,7 +73,7 @@ module Fastlane
70
73
  FileUtils.cp(l, linkmap_folder)
71
74
  end
72
75
  end
73
- copy_config(config_path, file_path)
76
+ Helper::EmergeHelper.copy_config(config_path, file_path)
74
77
  Actions::ZipAction.run(
75
78
  path: file_path,
76
79
  output_path: zip_path,
@@ -85,62 +88,18 @@ module Fastlane
85
88
  return
86
89
  end
87
90
 
88
- filename = File.basename(file_path)
89
- url = 'https://api.emergetools.com/upload'
90
91
  params = {
91
- 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"
92
100
  }
93
- if pr_number
94
- params[:prNumber] = pr_number
95
- end
96
- if branch
97
- params[:branch] = branch
98
- end
99
- if sha
100
- params[:sha] = sha
101
- end
102
- if base_sha
103
- params[:baseSha] = base_sha
104
- end
105
- if repo_name
106
- params[:repoName] = repo_name
107
- end
108
- if gitlab_project_id
109
- params[:gitlabProjectId] = gitlab_project_id
110
- end
111
- if order_file_version
112
- params[:orderFileVersion] = order_file_version
113
- end
114
- params[:tag] = tag || "default"
115
- FastlaneCore::PrintTable.print_values(
116
- config: params,
117
- hide_keys: [],
118
- title: "Summary for Emerge #{Fastlane::Emerge::VERSION}"
119
- )
120
- resp = Faraday.post(
121
- url,
122
- params.to_json,
123
- 'Content-Type' => 'application/json', 'X-API-Token' => api_token, 'User-Agent' => "fastlane-plugin-emerge/#{Fastlane::Emerge::VERSION}"
124
- )
125
- case resp.status
126
- when 200
127
- json = JSON.parse(resp.body)
128
- upload_id = json["upload_id"]
129
- upload_url = json["uploadURL"]
130
- warning = json["warning"]
131
- if warning
132
- UI.important(warning)
133
- end
134
- return Helper::EmergeHelper.perform_upload(upload_url, upload_id, file_path)
135
- when 403
136
- UI.error("Invalid API token")
137
- when 400
138
- UI.error("Invalid parameters")
139
- json = JSON.parse(resp.body)
140
- UI.error("Error: #{json['errorMessage']}")
141
- else
142
- UI.error("Upload failed")
143
- 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}")
144
103
  end
145
104
 
146
105
  def self.copy_dsyms(from, to)
@@ -150,19 +109,6 @@ module Fastlane
150
109
  end
151
110
  end
152
111
 
153
- def self.copy_config(config_path, tmp_dir)
154
- return if config_path.nil?
155
-
156
- expanded_path = File.expand_path(config_path)
157
- unless File.exist?(expanded_path)
158
- UI.error("No config file found at path '#{expanded_path}'.\nUploading without config file")
159
- return
160
- end
161
-
162
- emerge_config_path = "#{tmp_dir}/emerge_config.yaml"
163
- FileUtils.cp(expanded_path, emerge_config_path)
164
- end
165
-
166
112
  def self.description
167
113
  "Fastlane plugin for Emerge"
168
114
  end
@@ -172,11 +118,10 @@ module Fastlane
172
118
  end
173
119
 
174
120
  def self.return_value
175
- # If your method provides a return value, you can describe here what it does
121
+ "If successful, returns the upload id of the generated build"
176
122
  end
177
123
 
178
124
  def self.details
179
- # Optional:
180
125
  ""
181
126
  end
182
127
 
@@ -246,10 +191,6 @@ module Fastlane
246
191
  end
247
192
 
248
193
  def self.is_supported?(platform)
249
- # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
250
- # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
251
- #
252
- # [:ios, :mac, :android].include?(platform)
253
194
  platform == :ios
254
195
  end
255
196
  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
@@ -4,23 +4,130 @@ require 'faraday'
4
4
  module Fastlane
5
5
  UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
6
6
 
7
+ class GitResult
8
+ attr_accessor :sha, :base_sha, :branch, :pr_number, :repo_name
9
+
10
+ def initialize(sha:, base_sha:, branch:, pr_number: nil, repo_name: nil)
11
+ @pr_number = pr_number
12
+ @sha = sha
13
+ @base_sha = base_sha
14
+ @branch = branch
15
+ @repo_name = repo_name
16
+ end
17
+ end
18
+
7
19
  module Helper
8
20
  class EmergeHelper
9
- def self.perform_upload(upload_url, upload_id, file_path)
10
- UI.message("Starting upload")
11
- response = Faraday.put(upload_url) do |req|
12
- req.headers['Content-Type'] = 'application/zip'
13
- req.headers['Content-Length'] = "#{File.size(file_path)}"
14
- req.body = Faraday::UploadIO.new(file_path, 'application/zip')
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)
31
+ end
32
+
33
+ def self.make_git_params
34
+ git_result = if Helper::Github.is_supported_github_event?
35
+ UI.message("Fetching Git info from Github event")
36
+ GitResult.new(
37
+ sha: Helper::Github.sha,
38
+ base_sha: Helper::Github.base_sha,
39
+ branch: Helper::Github.branch,
40
+ pr_number: Helper::Github.pr_number,
41
+ repo_name: Helper::Github.repo_name
42
+ )
43
+ else
44
+ UI.message("Fetching Git info from system Git")
45
+ GitResult.new(
46
+ sha: Helper::Git.sha,
47
+ base_sha: Helper::Git.base_sha,
48
+ branch: Helper::Git.branch
49
+ )
50
+ end
51
+ UI.message("Got git result #{git_result.inspect}")
52
+ git_result
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
15
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)
16
96
  case response.status
17
97
  when 200
18
- UI.success("Your app is processing, you can find the results at https://emergetools.com/build/#{upload_id}")
19
- return upload_id
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'
20
104
  else
21
- UI.error("Upload failed")
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)
22
116
  end
23
- return nil
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
24
131
  end
25
132
  end
26
133
  end
@@ -0,0 +1,66 @@
1
+ require 'fastlane_core/print_table'
2
+ require 'open3'
3
+
4
+ module Fastlane
5
+ module Helper
6
+ module Git
7
+ def self.branch
8
+ shell_command = "git rev-parse --abbrev-ref HEAD"
9
+ UI.command(shell_command)
10
+ stdout, _, status = Open3.capture3(shell_command)
11
+ stdout.strip if status.success?
12
+ end
13
+
14
+ def self.sha
15
+ shell_command = "git rev-parse HEAD"
16
+ UI.command(shell_command)
17
+ stdout, _, status = Open3.capture3(shell_command)
18
+ stdout.strip if status.success?
19
+ end
20
+
21
+ def self.base_sha
22
+ shell_command = "git merge-base #{remote_head_branch} #{branch}"
23
+ UI.command(shell_command)
24
+ stdout, _, status = Open3.capture3(shell_command)
25
+ return nil if stdout.strip.empty? || !status.success?
26
+ current_sha = sha
27
+ stdout.strip == current_sha ? nil : stdout.strip
28
+ end
29
+
30
+ def self.primary_remote
31
+ remote = remote()
32
+ return nil if remote.nil?
33
+ remote.include?("origin") ? "origin" : remote.first
34
+ end
35
+
36
+ def self.remote_head_branch(remote = primary_remote)
37
+ return nil if remote.nil?
38
+ shell_command = "git remote show #{remote}"
39
+ UI.command(shell_command)
40
+ stdout, _, status = Open3.capture3(shell_command)
41
+ return nil if stdout.nil? || !status.success?
42
+ stdout
43
+ .split("\n")
44
+ .map(&:strip)
45
+ .find { |line| line.start_with?("HEAD branch: ") }
46
+ &.split(' ')
47
+ &.last
48
+ end
49
+
50
+ def self.remote_url(remote = primary_remote)
51
+ return nil if remote.nil?
52
+ shell_command = "git config --get remote.#{remote}.url"
53
+ UI.command(shell_command)
54
+ stdout, _, status = Open3.capture3(shell_command)
55
+ stdout if status.success?
56
+ end
57
+
58
+ def self.remote
59
+ shell_command = "git remote"
60
+ UI.command(shell_command)
61
+ stdout, _, status = Open3.capture3(shell_command)
62
+ stdout.split("\n") if status.success?
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,77 @@
1
+ require 'json'
2
+ require 'fastlane_core/print_table'
3
+ require_relative 'git'
4
+
5
+ module Fastlane
6
+ module Helper
7
+ module Github
8
+ GITHUB_EVENT_PR = "pull_request".freeze
9
+ GITHUB_EVENT_PUSH = "push".freeze
10
+
11
+ def self.event_name
12
+ ENV['GITHUB_EVENT_NAME']
13
+ end
14
+
15
+ def self.is_supported_github_event?
16
+ UI.message("GitHub event name: #{event_name}")
17
+ is_pull_request? || is_push?
18
+ end
19
+
20
+ def self.is_pull_request?
21
+ event_name == GITHUB_EVENT_PR
22
+ end
23
+
24
+ def self.is_push?
25
+ event_name == GITHUB_EVENT_PUSH
26
+ end
27
+
28
+ def self.sha
29
+ if is_push?
30
+ ENV['GITHUB_SHA']
31
+ elsif is_pull_request?
32
+ github_event_data.dig(:pull_request, :head, :sha)
33
+ end
34
+ end
35
+
36
+ def self.base_sha
37
+ if is_pull_request?
38
+ github_event_data.dig(:pull_request, :base, :sha)
39
+ end
40
+ end
41
+
42
+ def self.pr_number
43
+ is_pull_request? ? github_event_data.dig(:number) : nil
44
+ end
45
+
46
+ def self.branch
47
+ is_pull_request? ? github_event_data.dig(:pull_request, :head, :ref) : Git.branch
48
+ end
49
+
50
+ def self.repo_owner
51
+ github_event_data.dig(:repository, :owner, :login)
52
+ end
53
+
54
+ def self.repo_name
55
+ github_event_data.dig(:repository, :full_name)
56
+ end
57
+
58
+ private_class_method
59
+
60
+ def self.github_event_data
61
+ github_event_path = ENV['GITHUB_EVENT_PATH']
62
+ UI.error!("GITHUB_EVENT_PATH is not set") if github_event_path.nil?
63
+
64
+ unless File.exist?(github_event_path)
65
+ UI.error!("File #{github_event_path} doesn't exist")
66
+ end
67
+
68
+ file_content = File.read(github_event_path)
69
+ file_json = JSON.parse(file_content, symbolize_names: true)
70
+ if ENV['DEBUG']
71
+ UI.message("Parsed GitHub event data: #{file_json.inspect}")
72
+ end
73
+ file_json
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Emerge
3
- VERSION = "0.7.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.7.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-06 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,7 +162,10 @@ 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
167
+ - lib/fastlane/plugin/emerge/helper/git.rb
168
+ - lib/fastlane/plugin/emerge/helper/github.rb
166
169
  - lib/fastlane/plugin/emerge/version.rb
167
170
  homepage: https://github.com/EmergeTools/fastlane-plugin-emerge
168
171
  licenses:
@@ -183,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
186
  - !ruby/object:Gem::Version
184
187
  version: '0'
185
188
  requirements: []
186
- rubygems_version: 3.2.3
189
+ rubygems_version: 3.3.25
187
190
  signing_key:
188
191
  specification_version: 4
189
192
  summary: Fastlane plugin for Emerge