emerge 0.1.0 → 0.2.1

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: 8b51ab2fab1683825f19ebb9be0eb07b7901cb49d194adcfcb3488ebf17440dd
4
- data.tar.gz: cb8d2ead013d712c99e5213a7d4d39cac1b2ad67afa0d51aaed3b06e86a43605
3
+ metadata.gz: f4bfa9e9a7d920f4f41ca06eef1283b73be375bffda3d414c27b55eeb11c1cef
4
+ data.tar.gz: ed994835ee23a65f5ccfbec7acc84114f363f82f2464b4147939bb32b2664c3f
5
5
  SHA512:
6
- metadata.gz: 1360c8d0acde63b549d69c23468fdd24b7c4a37e399988faec47e88060d9edf7e9abf945657f6deaa4af052c9b9cc307b6f4cd2c5eefe741bc3e9cce4dbff1b0
7
- data.tar.gz: 7c515b04f02ef2c28e9452f9edeb36d62bf4754fe52c0a78b727b202c233a1291d418cab3d341e2eab527afd7fd5ffc77726b2e7af85c46693538fc273cfd3c6
6
+ metadata.gz: de61137a2b6d33d3c6e3e8f8ab63b705658098d42c613a991f69102f01b93d3b374010939c087af06c8becfd20cb77c1f4279092ff5dc12556d803b607698a30
7
+ data.tar.gz: bde1f8a729fd46b45600e8fcc50921399e334c1bf50b071c222bac4c81050a200819baeb643fbbab91fa1ef13c9b9dc5123258416e1c88fe2fd9cd284efb58f0
@@ -0,0 +1,101 @@
1
+ require 'xcodeproj'
2
+
3
+ module EmergeCLI
4
+ module Commands
5
+ module Config
6
+ class OrderFilesIOS < EmergeCLI::Commands::GlobalOptions
7
+ desc 'Configure order files for iOS'
8
+
9
+ # Optional options
10
+ option :skip_download_script, type: :boolean, required: false, desc: 'Only enable linkmaps'
11
+ option :project_path, type: :string, required: false,
12
+ desc: 'Path to the xcode project (will use first found if not provided)'
13
+
14
+ # Constants
15
+ LINK_MAPS_CONFIG = 'LD_GENERATE_MAP_FILE'.freeze
16
+ LINK_MAPS_PATH = 'LD_MAP_FILE_PATH'.freeze
17
+ PATH_TO_LINKMAP = '$(TARGET_TEMP_DIR)/$(PRODUCT_NAME)-LinkMap-$(CURRENT_VARIANT)-$(CURRENT_ARCH).txt'.freeze
18
+ ORDER_FILE = 'ORDER_FILE'.freeze
19
+ ORDER_FILE_PATH = '$(PROJECT_DIR)/orderfiles/orderfile.txt'.freeze
20
+
21
+ def initialize; end
22
+
23
+ def call(**options)
24
+ @options = options
25
+ before(options)
26
+
27
+ if @options[:project_path]
28
+ project = Xcodeproj::Project.open(@options[:project_path])
29
+ else
30
+ project = Xcodeproj::Project.open(Dir.glob('*.xcodeproj').first)
31
+ Logger.warn 'No project path provided, using first found xcodeproj in current directory'
32
+ end
33
+
34
+ enable_linkmaps(project)
35
+
36
+ add_order_files_download_script(project) unless @options[:skip_download_script]
37
+
38
+ project.save
39
+ end
40
+
41
+ private
42
+
43
+ def enable_linkmaps(project)
44
+ Logger.info 'Enabling Linkmaps'
45
+ project.targets.each do |target|
46
+ # Only do it for app targets
47
+ next unless target.product_type == 'com.apple.product-type.application'
48
+
49
+ Logger.info " Target: #{target.name}"
50
+ target.build_configurations.each do |config|
51
+ config.build_settings[LINK_MAPS_CONFIG] = 'YES'
52
+ config.build_settings[LINK_MAPS_PATH] = PATH_TO_LINKMAP
53
+ end
54
+ end
55
+ end
56
+
57
+ def add_order_files_download_script(project)
58
+ Logger.info 'Adding order files download script'
59
+ project.targets.each do |target|
60
+ # Only do it for app targets
61
+ next unless target.product_type == 'com.apple.product-type.application'
62
+
63
+ Logger.info " Target: #{target.name}"
64
+
65
+ # Create the script phase if it doesn't exist
66
+ phase = target.shell_script_build_phases.find { |item| item.name == 'EmergeTools Download Order Files' }
67
+ if phase.nil?
68
+ Logger.info " Creating script 'EmergeTools Download Order Files'"
69
+ phase = target.new_shell_script_build_phase('EmergeTools Download Order Files')
70
+ phase.shell_script = <<~BASH
71
+ if [ "$CONFIGURATION" != "Release" ]; then
72
+ echo "Skipping script for non-Release build"
73
+ exit 0
74
+ fi
75
+
76
+ if curl --fail "https://order-files-prod.emergetools.com/$PRODUCT_BUNDLE_IDENTIFIER/$MARKETING_VERSION" \
77
+ -H "X-API-Token: $EMERGE_API_TOKEN" -o ORDER_FILE.gz ; then
78
+ mkdir -p "$PROJECT_DIR/orderfiles"
79
+ gunzip -c ORDER_FILE.gz > $PROJECT_DIR/orderfiles/orderfile.txt
80
+ else
81
+ echo "cURL request failed. Creating an empty file."
82
+ mkdir -p "$PROJECT_DIR/orderfiles"
83
+ touch "$PROJECT_DIR/orderfiles/orderfile.txt"
84
+ fi;
85
+ BASH
86
+ phase.output_paths = ['$(PROJECT_DIR)/orderfiles/orderfile.txt']
87
+ else
88
+ Logger.info " 'EmergeTools Download Order Files' already exists"
89
+ end
90
+ # Make sure it is the first build phase
91
+ target.build_phases.move(phase, 0)
92
+
93
+ target.build_configurations.each do |config|
94
+ config.build_settings[ORDER_FILE] = ORDER_FILE_PATH
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,34 @@
1
+ module EmergeCLI
2
+ module Commands
3
+ module Upload
4
+ module ClientLibraries
5
+ class Roborazzi
6
+ def initialize(project_root)
7
+ @project_root = project_root
8
+ end
9
+
10
+ def image_files
11
+ Dir.glob(File.join(@project_root, '**/build/outputs/roborazzi/**/*.png'))
12
+ end
13
+
14
+ def parse_file_info(image_path)
15
+ file_name = image_path.split('build/outputs/roborazzi/').last
16
+ base_name = File.basename(file_name, '.png')
17
+ parts = base_name.split('.')
18
+
19
+ # Get the last two parts regardless of whether there's a package name in the file name
20
+ # For "com.example.MyTest.testName" -> ["MyTest", "testName"]
21
+ # For "MyTest.testName" -> ["MyTest", "testName"]
22
+ relevant_parts = parts.last(2)
23
+
24
+ {
25
+ file_name:,
26
+ group_name: relevant_parts[0],
27
+ variant_name: relevant_parts[1]
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -27,7 +27,7 @@ module EmergeCLI
27
27
  option :pr_number, type: :string, required: false, desc: 'PR number'
28
28
  option :concurrency, type: :integer, default: 5, desc: 'Number of concurrency for parallel uploads'
29
29
 
30
- option :client_library, type: :string, required: false, values: %w[swift-snapshot-testing paparazzi],
30
+ option :client_library, type: :string, required: false, values: %w[swift-snapshot-testing paparazzi roborazzi],
31
31
  desc: 'Client library used for snapshots'
32
32
  option :project_root, type: :string, required: false, desc: 'Path to the project root'
33
33
 
@@ -48,6 +48,7 @@ module EmergeCLI
48
48
 
49
49
  start_time = Time.now
50
50
  run_id = nil
51
+ success = false
51
52
 
52
53
  begin
53
54
  api_token = @options[:api_token] || ENV['EMERGE_API_TOKEN']
@@ -76,19 +77,23 @@ module EmergeCLI
76
77
  Logger.info "Time taken: #{(Time.now - start_time).round(2)} seconds"
77
78
  @profiler.report
78
79
  Logger.info "✅ View your snapshots at https://emergetools.com/snapshot/#{run_id}"
80
+ success = true
79
81
  rescue StandardError => e
80
82
  Logger.error "CLI Error: #{e.message}"
81
83
  Sync { report_error(run_id, e.message, 'crash') } if run_id
84
+ raise e # Re-raise the error to dry-cli
82
85
  ensure
83
86
  @network&.close
84
87
  end
88
+
89
+ success
85
90
  end
86
91
 
87
92
  private
88
93
 
89
94
  def validate_options(image_paths)
90
95
  if @options[:client_library] && !@options[:project_root]
91
- raise 'Project path is required when using a client library'
96
+ raise 'Project root is required when using a client library'
92
97
  end
93
98
  if @options[:project_root] && !@options[:client_library]
94
99
  raise 'Client library is required when using a project path'
@@ -98,11 +103,17 @@ module EmergeCLI
98
103
  end
99
104
 
100
105
  def create_client(image_paths)
101
- case @options[:client_library]
102
- when 'swift-snapshot-testing'
103
- ClientLibraries::SwiftSnapshotTesting.new(@options[:project_root])
104
- when 'paparazzi'
105
- ClientLibraries::Paparazzi.new(@options[:project_root])
106
+ if @options[:client_library]
107
+ case @options[:client_library]
108
+ when 'swift-snapshot-testing'
109
+ ClientLibraries::SwiftSnapshotTesting.new(@options[:project_root])
110
+ when 'paparazzi'
111
+ ClientLibraries::Paparazzi.new(@options[:project_root])
112
+ when 'roborazzi'
113
+ ClientLibraries::Roborazzi.new(@options[:project_root])
114
+ else
115
+ raise "Unsupported client library: #{@options[:client_library]}"
116
+ end
106
117
  else
107
118
  ClientLibraries::Default.new(image_paths)
108
119
  end
@@ -110,6 +121,7 @@ module EmergeCLI
110
121
 
111
122
  def find_image_files(client)
112
123
  found_images = client.image_files
124
+ raise 'No images found. Please check your image paths or project configuration.' if found_images.empty?
113
125
  Logger.info "Found #{found_images.size} images"
114
126
  found_images
115
127
  end
data/lib/emerge_cli.rb CHANGED
@@ -2,9 +2,11 @@ require_relative './commands/global_options'
2
2
  require_relative './commands/upload/snapshots/snapshots'
3
3
  require_relative './commands/upload/snapshots/client_libraries/swift_snapshot_testing'
4
4
  require_relative './commands/upload/snapshots/client_libraries/paparazzi'
5
+ require_relative './commands/upload/snapshots/client_libraries/roborazzi'
5
6
  require_relative './commands/upload/snapshots/client_libraries/default'
6
7
  require_relative './commands/integrate/fastlane'
7
8
  require_relative './commands/config/snapshots/snapshots_ios'
9
+ require_relative './commands/config/orderfiles/orderfiles_ios'
8
10
 
9
11
  require_relative './utils/git_info_provider'
10
12
  require_relative './utils/git_result'
@@ -29,7 +31,8 @@ module EmergeCLI
29
31
  end
30
32
 
31
33
  register 'configure' do |prefix|
32
- prefix.register 'snapshots-ios', Commands::Config::SnapshotsIOS, aliases: ['c']
34
+ prefix.register 'snapshots-ios', Commands::Config::SnapshotsIOS
35
+ prefix.register 'order-files-ios', Commands::Config::OrderFilesIOS
33
36
  end
34
37
  end
35
38
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module EmergeCli
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emerge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emerge Tools
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-19 00:00:00.000000000 Z
11
+ date: 2024-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.12.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: xcodeproj
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.27.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.27.0
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: minitest
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -231,11 +245,13 @@ files:
231
245
  - CHANGELOG.md
232
246
  - README.md
233
247
  - exe/emerge
248
+ - lib/commands/config/orderfiles/orderfiles_ios.rb
234
249
  - lib/commands/config/snapshots/snapshots_ios.rb
235
250
  - lib/commands/global_options.rb
236
251
  - lib/commands/integrate/fastlane.rb
237
252
  - lib/commands/upload/snapshots/client_libraries/default.rb
238
253
  - lib/commands/upload/snapshots/client_libraries/paparazzi.rb
254
+ - lib/commands/upload/snapshots/client_libraries/roborazzi.rb
239
255
  - lib/commands/upload/snapshots/client_libraries/swift_snapshot_testing.rb
240
256
  - lib/commands/upload/snapshots/snapshots.rb
241
257
  - lib/emerge_cli.rb