Skip to content

Commit

Permalink
Put step inputs support scalars 'all and 'detect'
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Mar 16, 2023
1 parent 71a25d2 commit 3eb9124
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Pivotal, Inc.
* Copyright (c) 2016, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -189,6 +189,8 @@ public YType yunion(String name, YType... types) {
return new YAtomAndMapUnion(name, atoms.get(0), maps.get(0));
} else if (atoms.size()==0 && maps.size()==0 && arrays.size()==1 && beans.size()==1) {
return new YBeanAndSequenceUnion(name, beans.get(0), arrays.get(0));
} else if (atoms.size()==1 && arrays.size()==1 && maps.size()==0 && beans.size()==0) {
return new YAtomAndSequenceUnion(name, atoms.get(0), arrays.get(0));
}
throw new IllegalArgumentException("Union of this kind of types is not (yet) supported: "+types);
}
Expand Down Expand Up @@ -909,6 +911,36 @@ public boolean isSequenceable() {
return true;
}
}

public class YAtomAndSequenceUnion extends AbstractUnionType {
private final YAtomicType atomic;
private final YSeqType seq;

public YAtomAndSequenceUnion(String name, YAtomicType atomic, YSeqType seq) {
super(name, atomic, seq);
this.atomic = atomic;
this.seq = seq;
}
@Override
public YType inferMoreSpecificType(DynamicSchemaContext dc) {
if (dc.isAtomic()) {
return atomic;
} else if (dc.isSequence()) {
return seq;
}
return super.inferMoreSpecificType(dc);
}

@Override
public boolean isAtomic() {
return true;
}

@Override
public boolean isSequenceable() {
return true;
}
}

public static class YTypedPropertyImpl implements YTypedProperty, Cloneable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public PipelineYmlSchema(ConcourseModel models, GithubInfoProvider github) {
YBeanType putStep = f.ybean("PutStep");
addProp(putStep, "put", t_put_get_name);
addProp(putStep, "resource", t_resource_name);
addProp(putStep, "inputs", t_strings);
addProp(putStep, "inputs", f.yunion("PutStepInputs", t_strings, f.yenum("PutStepInputsAllOrDetect", "all", "detect")));
addProp(putStep, "params", f.contextAware("PutParams", (dc) ->
resourceTypes.getOutParamsType(getResourceType("put", models, dc))
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,46 @@ void putStepInputsReconcile() throws Exception {
" - put: my-git\n" +
" inputs: not-a-list\n"
);
editor.assertProblems("not-a-list|Expecting a 'Sequence'");
editor.assertProblems("not-a-list|Valid values are: [all, detect]");
}

@Test
void putStepInputsReconcileAll() throws Exception {
//See: https://github.com/spring-projects/sts4/issues/341
Editor editor = harness.newEditor(
"resources:\n" +
"- name: my-git\n" +
" type: git\n" +
" source:\n" +
" uri: https://example.com/my-name/my-repo.git\n" +
" branch: master\n" +
"jobs:\n" +
"- name: do-stuff\n" +
" plan:\n" +
" - put: my-git\n" +
" inputs: all\n"
);
editor.assertProblems();
}

void putStepInputsReconcileNoProblems() throws Exception {
//See: https://github.com/spring-projects/sts4/issues/341
Editor editor = harness.newEditor(
"resources:\n" +
"- name: my-git\n" +
" type: git\n" +
" source:\n" +
" uri: https://example.com/my-name/my-repo.git\n" +
" branch: master\n" +
"jobs:\n" +
"- name: do-stuff\n" +
" plan:\n" +
" - put: my-git\n" +
" inputs:\n" +
" - build\n" +
" - test\n"
);
editor.assertProblems();
}

@Test
Expand Down

0 comments on commit 3eb9124

Please sign in to comment.