Skip to content

Commit

Permalink
Add more validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborszakacs committed Dec 13, 2024
1 parent 9f2d6f6 commit 26d069b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
19 changes: 18 additions & 1 deletion cli/run_util_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ workflows:

const missingWorkflowInWorkflowVariantDefinitionForDAGPipeline = `
format_version: '13'
pipelines:
dag:
workflows:
a: {}
b: { source: c }
workflows:
a: {}
`

const workflowVariantHasTheSameNameAsAnExistingWorkflowForDAGPipeline = `
format_version: '13'
pipelines:
dag:
workflows:
Expand All @@ -113,6 +124,7 @@ pipelines:
workflows:
a: {}
b: {}
c: {}
`

const duplicatedDependencyDAGPipeline = `
Expand Down Expand Up @@ -186,7 +198,12 @@ func TestValidation(t *testing.T) {
{
name: "Workflow is missing from the Workflow Variant definition",
config: missingWorkflowInWorkflowVariantDefinitionForDAGPipeline,
wantErr: "failed to get Bitrise config (bitrise.yml) from base 64 data: Failed to parse bitrise config, error: workflow (c) defined in pipeline (dag) is not found in the workflow definitions",
wantErr: "failed to get Bitrise config (bitrise.yml) from base 64 data: Failed to parse bitrise config, error: workflow (c) referenced in pipeline (dag) in workflow variant (b) is not found in the workflow definitions",
},
{
name: "Workflow variant has the same name as an existing workflow",
config: workflowVariantHasTheSameNameAsAnExistingWorkflowForDAGPipeline,
wantErr: "failed to get Bitrise config (bitrise.yml) from base 64 data: Failed to parse bitrise config, error: workflow (b) defined in pipeline (dag) is a variant of another workflow, but it is also defined as a workflow",
},
{
name: "Utility workflow is referenced in the DAG pipeline",
Expand Down
15 changes: 10 additions & 5 deletions models/models_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,18 @@ func validateDAGPipeline(pipelineID string, pipeline *PipelineModel, config *Bit
}

isWorkflowVariant := pipelineWorkflow.Source != ""
workflowDefinitionToCheck := pipelineWorkflowID
if isWorkflowVariant {
workflowDefinitionToCheck = pipelineWorkflow.Source
}
if _, ok := config.Workflows[pipelineWorkflow.Source]; !ok {
return fmt.Errorf("workflow (%s) referenced in pipeline (%s) in workflow variant (%s) is not found in the workflow definitions", pipelineWorkflow.Source, pipelineID, pipelineWorkflowID)
}

if _, ok := config.Workflows[workflowDefinitionToCheck]; !ok {
return fmt.Errorf("workflow (%s) defined in pipeline (%s) is not found in the workflow definitions", workflowDefinitionToCheck, pipelineID)
if _, ok := config.Workflows[pipelineWorkflowID]; ok {
return fmt.Errorf("workflow (%s) defined in pipeline (%s) is a variant of another workflow, but it is also defined as a workflow", pipelineWorkflowID, pipelineID)
}
} else {
if _, ok := config.Workflows[pipelineWorkflowID]; !ok {
return fmt.Errorf("workflow (%s) defined in pipeline (%s) is not found in the workflow definitions", pipelineWorkflowID, pipelineID)
}
}

uniqueItems := make(map[string]bool)
Expand Down

0 comments on commit 26d069b

Please sign in to comment.