Skip to content

Commit

Permalink
Merge pull request #124 from agrare/skip_invalid_workflows_during_sync
Browse files Browse the repository at this point in the history
Skip invalid workflows during sync

(cherry picked from commit 0606398)
  • Loading branch information
Fryguy committed Jan 16, 2025
1 parent 983faac commit 4d19b82
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def sync_from_git_repository(to_delete)

payload = worktree.read_file(filename)
workflow = create_workflow_from_payload(filename, payload, fail_on_invalid_workflow: false)
to_delete.delete(workflow.name)

to_delete.delete(workflow.name) if workflow
end
end
end
Expand All @@ -68,21 +69,24 @@ def sync_from_content(to_delete)
payload = File.read(filename)
workflow = create_workflow_from_payload(workflow_name, payload, fail_on_invalid_workflow: true)

to_delete.delete(workflow.name)
to_delete.delete(workflow.name) if workflow
end
end
end

def create_workflow_from_payload(name, payload, fail_on_invalid_workflow:)
floe_workflow =
floe_workflow, payload_error =
begin
Floe::Workflow.new(payload)
rescue Floe::InvalidWorkflowError
rescue Floe::InvalidWorkflowError, NotImplementedError => err
_log.warn("Invalid ASL file [#{name}]: #{err}")
raise if fail_on_invalid_workflow

nil
[nil, err.message]
end

return if payload_error

description = floe_workflow&.comment

configuration_script_payloads.find_or_initialize_by(:name => name).tap do |wf|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,33 @@ def files_in_repository(git_repo_dir)
record = build_record

expect(record.configuration_script_payloads.first).to have_attributes(
:name => "hello_world.asl",
:description => "hello world",
:payload => a_string_including("\"Comment\": \"hello world\""),
:payload_type => "json"
:name => "hello_world.asl",
:description => "hello world",
:payload => a_string_including("\"Comment\": \"hello world\""),
:payload_type => "json",
:payload_valid => true,
:payload_error => nil
)
end

context "with workflows with invalid json" do
let(:repo_dir_structure) { %w[invalid_json.asl] }

it "skips the invalid workflow file" do
record = build_record
expect(record.configuration_script_payloads).to be_empty
end
end

context "with workflows with missing states" do
let(:repo_dir_structure) { %w[missing_states.asl] }

it "skips the invalid workflow file" do
record = build_record
expect(record.configuration_script_payloads).to be_empty
end
end

context "with a nested dir" do
let(:nested_repo) { File.join(clone_dir, "hello_world_nested") }

Expand Down
19 changes: 15 additions & 4 deletions spec/support/fake_workflows_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ def file_content(full_path)
dummy_workflow_data_for(full_path) if full_path.fnmatch?("**/*.asl", File::FNM_EXTGLOB)
end

def dummy_workflow_data_for(_filename)
<<~WORKFLOW_DATA
{"Comment": "hello world", "States": {"Start": {"Type": "Succeed"}}, "StartAt": "Start"}
WORKFLOW_DATA
def dummy_workflow_data_for(filename)
case filename.to_s
when /invalid_json.asl$/
<<~WORKFLOW_DATA
{"Invalid Json"
WORKFLOW_DATA
when /missing_states.asl$/
<<~WORKFLOW_DATA
{"Comment": "Missing States"}
WORKFLOW_DATA
else
<<~WORKFLOW_DATA
{"Comment": "hello world", "States": {"Start": {"Type": "Succeed"}}, "StartAt": "Start"}
WORKFLOW_DATA
end
end
end
end
Expand Down

0 comments on commit 4d19b82

Please sign in to comment.