Skip to content

Commit

Permalink
support detect in inputs array.
Browse files Browse the repository at this point in the history
Signed-off-by: Chao Li <chaol@vmware.com>
  • Loading branch information
evanchaoli committed Mar 23, 2021
1 parent f461da2 commit 4006cb7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
25 changes: 20 additions & 5 deletions atc/exec/put_inputs.go
Expand Up @@ -45,11 +45,13 @@ func (i allInputs) FindAll(artifacts *build.Repository) (map[string]runtime.Arti

type specificInputs struct {
inputs []string
params atc.Params
}

func NewSpecificInputs(inputs []string) PutInputs {
func NewSpecificInputs(inputs []string, params atc.Params) PutInputs {
return &specificInputs{
inputs: inputs,
params: params,
}
}

Expand All @@ -58,14 +60,27 @@ func (i specificInputs) FindAll(artifacts *build.Repository) (map[string]runtime

inputs := map[string]runtime.Artifact{}

for _, i := range i.inputs {
artifact, found := artifactsMap[build.ArtifactName(i)]
for _, input := range i.inputs {
if input == atc.InputsDetect {
detectedInputs, err := NewDetectInputs(i.params).FindAll(artifacts)
if err != nil {
return nil, err
}

for k, v := range detectedInputs {
inputs[k] = v
}

continue
}

artifact, found := artifactsMap[build.ArtifactName(input)]
if !found {
return nil, PutInputNotFoundError{Input: i}
return nil, PutInputNotFoundError{Input: input}
}

pi := putInput{
name: build.ArtifactName(i),
name: build.ArtifactName(input),
artifact: artifact,
}

Expand Down
4 changes: 1 addition & 3 deletions atc/exec/put_step.go
Expand Up @@ -134,13 +134,11 @@ func (step *PutStep) run(ctx context.Context, state RunState, delegate PutDelega
putInputs = NewAllInputs()
} else if step.plan.Inputs.All {
putInputs = NewAllInputs()
} else if step.plan.Inputs.Detect {
putInputs = NewDetectInputs(step.plan.Params)
} else {
// Covers both cases where inputs are specified and when there are no
// inputs specified and "all" field is given a false boolean, which will
// result in no inputs attached
putInputs = NewSpecificInputs(step.plan.Inputs.Specified)
putInputs = NewSpecificInputs(step.plan.Inputs.Specified, step.plan.Params)
}

inputsMap, err := putInputs.FindAll(state.ArtifactRepository())
Expand Down
2 changes: 1 addition & 1 deletion atc/exec/put_step_test.go
Expand Up @@ -343,7 +343,7 @@ var _ = Describe("PutStep", func() {
Context("when the inputs are detected", func() {
BeforeEach(func() {
putPlan.Inputs = &atc.InputsConfig{
Detect: true,
Specified: []string{atc.InputsDetect},
}
})

Expand Down
20 changes: 10 additions & 10 deletions atc/steps.go
Expand Up @@ -703,11 +703,13 @@ func (c *VersionConfig) MarshalJSON() ([]byte, error) {
return json.Marshal("")
}

const InputsAll = "all"
const InputsDetect = "detect"

// A InputsConfig represents the choice to include every artifact within the
// job as an input to the put step or specific ones.
type InputsConfig struct {
All bool
Detect bool
Specified []string
}

Expand All @@ -721,8 +723,13 @@ func (c *InputsConfig) UnmarshalJSON(inputs []byte) error {

switch actual := data.(type) {
case string:
c.All = actual == "all"
c.Detect = actual == "detect"
if actual == InputsAll {
c.All = true
} else if actual == InputsDetect {
c.Specified = []string{InputsDetect}
} else {
return fmt.Errorf("unknown for put inputs %s", actual)
}
case []interface{}:
inputs := []string{}

Expand All @@ -743,18 +750,11 @@ func (c *InputsConfig) UnmarshalJSON(inputs []byte) error {
return nil
}

const InputsAll = "all"
const InputsDetect = "detect"

func (c InputsConfig) MarshalJSON() ([]byte, error) {
if c.All {
return json.Marshal(InputsAll)
}

if c.Detect {
return json.Marshal(InputsDetect)
}

if c.Specified != nil {
return json.Marshal(c.Specified)
}
Expand Down

0 comments on commit 4006cb7

Please sign in to comment.