Skip to content

Commit 253b88c

Browse files
authored
Add roborazzi support (#9)
1 parent 4327379 commit 253b88c

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/commands/upload/snapshots/snapshots.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Snapshots < EmergeCLI::Commands::GlobalOptions
2727
option :pr_number, type: :string, required: false, desc: 'PR number'
2828
option :concurrency, type: :integer, default: 5, desc: 'Number of concurrency for parallel uploads'
2929

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],
3131
desc: 'Client library used for snapshots'
3232
option :project_root, type: :string, required: false, desc: 'Path to the project root'
3333

@@ -88,7 +88,7 @@ def call(image_paths:, **options)
8888

8989
def validate_options(image_paths)
9090
if @options[:client_library] && !@options[:project_root]
91-
raise 'Project path is required when using a client library'
91+
raise 'Project root is required when using a client library'
9292
end
9393
if @options[:project_root] && !@options[:client_library]
9494
raise 'Client library is required when using a project path'
@@ -98,11 +98,17 @@ def validate_options(image_paths)
9898
end
9999

100100
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])
101+
if @options[:client_library]
102+
case @options[:client_library]
103+
when 'swift-snapshot-testing'
104+
ClientLibraries::SwiftSnapshotTesting.new(@options[:project_root])
105+
when 'paparazzi'
106+
ClientLibraries::Paparazzi.new(@options[:project_root])
107+
when 'roborazzi'
108+
ClientLibraries::Roborazzi.new(@options[:project_root])
109+
else
110+
raise "Unsupported client library: #{@options[:client_library]}"
111+
end
106112
else
107113
ClientLibraries::Default.new(image_paths)
108114
end

lib/emerge_cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require_relative './commands/upload/snapshots/snapshots'
33
require_relative './commands/upload/snapshots/client_libraries/swift_snapshot_testing'
44
require_relative './commands/upload/snapshots/client_libraries/paparazzi'
5+
require_relative './commands/upload/snapshots/client_libraries/roborazzi'
56
require_relative './commands/upload/snapshots/client_libraries/default'
67
require_relative './commands/integrate/fastlane'
78
require_relative './commands/config/snapshots/snapshots_ios'

0 commit comments

Comments
 (0)