fastlane-plugin-emerge 0.7.0 → 0.8.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: e170856bceb03b9747e72d074ce9a96d124dfe6519e5bc9f47becffb39b1acea
4
+ data.tar.gz: 71d34166a5fa640ac3af5ec2763a8b373052e3da358c0dc68dce5ed4bb46bd32
5
5
  SHA512:
6
- metadata.gz: 7afe4c7adc02c46fa4193dbed344afc716877d26ca00849f6dce44bdd73e7da8458221aa875e9b9290aeec36c2e08fa2036e71d08581af4de74cb848779fdffe
7
- data.tar.gz: 3fb17574090d31c7088b5afb3e0f9161e627ba777de779887b7d34ee45ea6094d3439bde09851087035d3c2face7be1caf173fb5228e5b81496f412b80d27aa0
6
+ metadata.gz: '07929884d01b7ce42b2863dc9973768b2bb033da495e6d63c6dd09a66e63d6613e55c41a0845eff819afcd8689897d5c32c6099028e0059e2f12df9aed1470af'
7
+ data.tar.gz: a971a076cb1724adec271841883b49a0ecfac4fe245884076b64cc655f1fabf930af60830f76cf7dbd46005d6e28c5a16d01d716a6ae63133df8a7cf6a013f56
@@ -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]
@@ -172,11 +175,10 @@ module Fastlane
172
175
  end
173
176
 
174
177
  def self.return_value
175
- # If your method provides a return value, you can describe here what it does
178
+ "If successful, returns the upload id of the generated build"
176
179
  end
177
180
 
178
181
  def self.details
179
- # Optional:
180
182
  ""
181
183
  end
182
184
 
@@ -246,10 +248,6 @@ module Fastlane
246
248
  end
247
249
 
248
250
  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
251
  platform == :ios
254
252
  end
255
253
  end
@@ -4,24 +4,58 @@ 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
21
  def self.perform_upload(upload_url, upload_id, file_path)
10
22
  UI.message("Starting upload")
11
23
  response = Faraday.put(upload_url) do |req|
12
24
  req.headers['Content-Type'] = 'application/zip'
13
- req.headers['Content-Length'] = "#{File.size(file_path)}"
25
+ req.headers['Content-Length'] = File.size(file_path).to_s
14
26
  req.body = Faraday::UploadIO.new(file_path, 'application/zip')
15
27
  end
16
28
  case response.status
17
29
  when 200
18
- UI.success("Your app is processing, you can find the results at https://emergetools.com/build/#{upload_id}")
30
+ UI.success("🎉 Your app is processing, you can find the results at https://emergetools.com/build/#{upload_id}")
19
31
  return upload_id
20
32
  else
21
33
  UI.error("Upload failed")
22
34
  end
23
35
  return nil
24
36
  end
37
+
38
+ def self.make_git_params
39
+ git_result = if Helper::Github.is_supported_github_event?
40
+ UI.message("Fetching Git info from Github event")
41
+ GitResult.new(
42
+ sha: Helper::Github.sha,
43
+ base_sha: Helper::Github.base_sha,
44
+ branch: Helper::Github.branch,
45
+ pr_number: Helper::Github.pr_number,
46
+ repo_name: Helper::Github.repo_name
47
+ )
48
+ else
49
+ UI.message("Fetching Git info from system Git")
50
+ GitResult.new(
51
+ sha: Helper::Git.sha,
52
+ base_sha: Helper::Git.base_sha,
53
+ branch: Helper::Git.branch
54
+ )
55
+ end
56
+ UI.message("Got git result #{git_result.inspect}")
57
+ git_result
58
+ end
25
59
  end
26
60
  end
27
61
  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.8.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.8.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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -163,6 +163,8 @@ files:
163
163
  - lib/fastlane/plugin/emerge/actions/emerge_comment_action.rb
164
164
  - lib/fastlane/plugin/emerge/actions/emerge_order_file_action.rb
165
165
  - lib/fastlane/plugin/emerge/helper/emerge_helper.rb
166
+ - lib/fastlane/plugin/emerge/helper/git.rb
167
+ - lib/fastlane/plugin/emerge/helper/github.rb
166
168
  - lib/fastlane/plugin/emerge/version.rb
167
169
  homepage: https://github.com/EmergeTools/fastlane-plugin-emerge
168
170
  licenses: