Skip to content

Commit 25c4792

Browse files
authored
Merge pull request #97 from Shopify/auto-locate-workflow
Automatically find project workflows by name on execute
2 parents 469d1c8 + 52d8c1d commit 25c4792

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ roast execute workflow.yml target_file.rb
124124
125125
# Or for a targetless workflow (API calls, data generation, etc.)
126126
roast execute workflow.yml
127+
128+
# Roast will automatically search in `project_root/roast/workflow_name` if the path is incomplete.
129+
roast execute my_cool_workflow # Equivalent to `roast execute roast/my_cool_workflow/workflow.yml
127130
```
128131

129132
### Understanding Workflows

lib/roast.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ def execute(*paths)
2828
raise Thor::Error, "Workflow configuration file is required" if paths.empty?
2929

3030
workflow_path, *files = paths
31-
expanded_workflow_path = File.expand_path(workflow_path)
31+
32+
expanded_workflow_path = if workflow_path.include?("workflow.yml")
33+
File.expand_path(workflow_path)
34+
else
35+
File.expand_path("roast/#{workflow_path}/workflow.yml")
36+
end
37+
3238
raise Thor::Error, "Expected a Roast workflow configuration file, got directory: #{expanded_workflow_path}" if File.directory?(expanded_workflow_path)
3339

3440
Roast::Workflow::ConfigurationParser.new(expanded_workflow_path, files, options.transform_keys(&:to_sym)).begin!

test/roast/cli_test.rb

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "mocha/minitest"
5+
require "roast"
6+
7+
class RoastCLITest < ActiveSupport::TestCase
8+
def test_execute_with_workflow_yml_path
9+
workflow_path = "path/to/workflow.yml"
10+
expanded_path = File.expand_path(workflow_path)
11+
12+
# Mock the ConfigurationParser to prevent actual execution
13+
mock_parser = mock("ConfigurationParser")
14+
mock_parser.expects(:begin!).once
15+
Roast::Workflow::ConfigurationParser.expects(:new).with(expanded_path, [], {}).returns(mock_parser)
16+
17+
# Make sure File.directory? returns false to avoid the directory error
18+
File.expects(:directory?).with(expanded_path).returns(false)
19+
20+
# Execute the CLI command
21+
cli = Roast::CLI.new
22+
cli.execute(workflow_path)
23+
end
24+
25+
def test_execute_with_conventional_path
26+
workflow_name = "my_workflow"
27+
conventional_path = "roast/#{workflow_name}/workflow.yml"
28+
expanded_path = File.expand_path(conventional_path)
29+
30+
# Mock the ConfigurationParser to prevent actual execution
31+
mock_parser = mock("ConfigurationParser")
32+
mock_parser.expects(:begin!).once
33+
Roast::Workflow::ConfigurationParser.expects(:new).with(expanded_path, [], {}).returns(mock_parser)
34+
35+
# Make sure File.directory? returns false to avoid the directory error
36+
File.expects(:directory?).with(expanded_path).returns(false)
37+
38+
# Execute the CLI command
39+
cli = Roast::CLI.new
40+
cli.execute(workflow_name)
41+
end
42+
43+
def test_execute_with_directory_path_raises_error
44+
workflow_path = "path/to/directory"
45+
expanded_path = File.expand_path("roast/#{workflow_path}/workflow.yml")
46+
47+
# Make the directory check return true to trigger the error
48+
File.expects(:directory?).with(expanded_path).returns(true)
49+
50+
# Execute the CLI command and expect an error
51+
cli = Roast::CLI.new
52+
assert_raises(Thor::Error) do
53+
cli.execute(workflow_path)
54+
end
55+
end
56+
57+
def test_execute_with_files_passes_files_to_parser
58+
workflow_path = "path/to/workflow.yml"
59+
expanded_path = File.expand_path(workflow_path)
60+
files = ["file1.rb", "file2.rb"]
61+
62+
# Mock the ConfigurationParser to prevent actual execution
63+
mock_parser = mock("ConfigurationParser")
64+
mock_parser.expects(:begin!).once
65+
Roast::Workflow::ConfigurationParser.expects(:new).with(expanded_path, files, {}).returns(mock_parser)
66+
67+
# Make sure File.directory? returns false to avoid the directory error
68+
File.expects(:directory?).with(expanded_path).returns(false)
69+
70+
# Execute the CLI command
71+
cli = Roast::CLI.new
72+
cli.execute(workflow_path, *files)
73+
end
74+
75+
def test_execute_with_options_passes_options_to_parser
76+
workflow_path = "path/to/workflow.yml"
77+
expanded_path = File.expand_path(workflow_path)
78+
options = { "verbose" => true, "concise" => false }
79+
80+
# Mock the ConfigurationParser to prevent actual execution
81+
mock_parser = mock("ConfigurationParser")
82+
mock_parser.expects(:begin!).once
83+
Roast::Workflow::ConfigurationParser.expects(:new).with(expanded_path, [], options.transform_keys(&:to_sym)).returns(mock_parser)
84+
85+
# Make sure File.directory? returns false to avoid the directory error
86+
File.expects(:directory?).with(expanded_path).returns(false)
87+
88+
# Create CLI with options
89+
cli = Roast::CLI.new([], options)
90+
cli.execute(workflow_path)
91+
end
92+
end

0 commit comments

Comments
 (0)