Skip to content

Commit

Permalink
Add roborazzi support (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-e authored Nov 20, 2024
1 parent 4327379 commit 253b88c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
34 changes: 34 additions & 0 deletions lib/commands/upload/snapshots/client_libraries/roborazzi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module EmergeCLI
module Commands
module Upload
module ClientLibraries
class Roborazzi
def initialize(project_root)
@project_root = project_root
end

def image_files
Dir.glob(File.join(@project_root, '**/build/outputs/roborazzi/**/*.png'))
end

def parse_file_info(image_path)
file_name = image_path.split('build/outputs/roborazzi/').last
base_name = File.basename(file_name, '.png')
parts = base_name.split('.')

# Get the last two parts regardless of whether there's a package name in the file name
# For "com.example.MyTest.testName" -> ["MyTest", "testName"]
# For "MyTest.testName" -> ["MyTest", "testName"]
relevant_parts = parts.last(2)

{
file_name:,
group_name: relevant_parts[0],
variant_name: relevant_parts[1]
}
end
end
end
end
end
end
20 changes: 13 additions & 7 deletions lib/commands/upload/snapshots/snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Snapshots < EmergeCLI::Commands::GlobalOptions
option :pr_number, type: :string, required: false, desc: 'PR number'
option :concurrency, type: :integer, default: 5, desc: 'Number of concurrency for parallel uploads'

option :client_library, type: :string, required: false, values: %w[swift-snapshot-testing paparazzi],
option :client_library, type: :string, required: false, values: %w[swift-snapshot-testing paparazzi roborazzi],
desc: 'Client library used for snapshots'
option :project_root, type: :string, required: false, desc: 'Path to the project root'

Expand Down Expand Up @@ -88,7 +88,7 @@ def call(image_paths:, **options)

def validate_options(image_paths)
if @options[:client_library] && !@options[:project_root]
raise 'Project path is required when using a client library'
raise 'Project root is required when using a client library'
end
if @options[:project_root] && !@options[:client_library]
raise 'Client library is required when using a project path'
Expand All @@ -98,11 +98,17 @@ def validate_options(image_paths)
end

def create_client(image_paths)
case @options[:client_library]
when 'swift-snapshot-testing'
ClientLibraries::SwiftSnapshotTesting.new(@options[:project_root])
when 'paparazzi'
ClientLibraries::Paparazzi.new(@options[:project_root])
if @options[:client_library]
case @options[:client_library]
when 'swift-snapshot-testing'
ClientLibraries::SwiftSnapshotTesting.new(@options[:project_root])
when 'paparazzi'
ClientLibraries::Paparazzi.new(@options[:project_root])
when 'roborazzi'
ClientLibraries::Roborazzi.new(@options[:project_root])
else
raise "Unsupported client library: #{@options[:client_library]}"
end
else
ClientLibraries::Default.new(image_paths)
end
Expand Down
1 change: 1 addition & 0 deletions lib/emerge_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require_relative './commands/upload/snapshots/snapshots'
require_relative './commands/upload/snapshots/client_libraries/swift_snapshot_testing'
require_relative './commands/upload/snapshots/client_libraries/paparazzi'
require_relative './commands/upload/snapshots/client_libraries/roborazzi'
require_relative './commands/upload/snapshots/client_libraries/default'
require_relative './commands/integrate/fastlane'
require_relative './commands/config/snapshots/snapshots_ios'
Expand Down

0 comments on commit 253b88c

Please sign in to comment.