From 253b88c38314f620bd48997820ddcb9eeddb2ead Mon Sep 17 00:00:00 2001 From: Trevor Elkins Date: Wed, 20 Nov 2024 17:39:12 -0500 Subject: [PATCH] Add roborazzi support (#9) --- .../snapshots/client_libraries/roborazzi.rb | 34 +++++++++++++++++++ lib/commands/upload/snapshots/snapshots.rb | 20 +++++++---- lib/emerge_cli.rb | 1 + 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 lib/commands/upload/snapshots/client_libraries/roborazzi.rb diff --git a/lib/commands/upload/snapshots/client_libraries/roborazzi.rb b/lib/commands/upload/snapshots/client_libraries/roborazzi.rb new file mode 100644 index 0000000..c5c07ae --- /dev/null +++ b/lib/commands/upload/snapshots/client_libraries/roborazzi.rb @@ -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 diff --git a/lib/commands/upload/snapshots/snapshots.rb b/lib/commands/upload/snapshots/snapshots.rb index 7b66322..d4427d2 100644 --- a/lib/commands/upload/snapshots/snapshots.rb +++ b/lib/commands/upload/snapshots/snapshots.rb @@ -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' @@ -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' @@ -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 diff --git a/lib/emerge_cli.rb b/lib/emerge_cli.rb index d1b3270..1e48fc8 100644 --- a/lib/emerge_cli.rb +++ b/lib/emerge_cli.rb @@ -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'