Skip to content

Commit 5e963e0

Browse files
Fix: Fix output (#203)
* fix compatibility for output Signed-off-by: Pushparaj Shetty KS <[email protected]> Signed-off-by: Pushparaj Shetty K S <[email protected]> * ran make reviewable Signed-off-by: Pushparaj Shetty KS <[email protected]> Signed-off-by: Pushparaj Shetty K S <[email protected]> * update actions/cache version to v3 Signed-off-by: Pushparaj Shetty KS <[email protected]> Signed-off-by: Pushparaj Shetty K S <[email protected]> * update logic in Output function Signed-off-by: Pushparaj Shetty K S <[email protected]> --------- Signed-off-by: Pushparaj Shetty KS <[email protected]> Signed-off-by: Pushparaj Shetty K S <[email protected]> Co-authored-by: Pushparaj Shetty K S <[email protected]>
1 parent 23468c9 commit 5e963e0

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

.github/workflows/unit-test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
submodules: true
5252

5353
- name: Cache Go Dependencies
54-
uses: actions/cache@v2
54+
uses: actions/cache@v3
5555
with:
5656
path: .work/pkg
5757
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}

pkg/context/context.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"k8s.io/apimachinery/pkg/types"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535

36-
"github.com/kubevela/pkg/cue/util"
3736
"github.com/kubevela/pkg/util/rand"
3837
"github.com/kubevela/pkg/util/singleton"
3938
"github.com/kubevela/workflow/pkg/cue/model/sets"
@@ -160,7 +159,7 @@ func (wf *WorkflowContext) Commit(ctx context.Context) error {
160159
}
161160

162161
func (wf *WorkflowContext) writeToStore() error {
163-
varStr, err := util.ToString(wf.vars)
162+
varStr, err := sets.ToString(wf.vars)
164163
if err != nil {
165164
return err
166165
}

pkg/hooks/data_passing.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ func Output(ctx wfContext.Context, taskValue cue.Value, step v1alpha1.WorkflowSt
6464
SetAdditionalNameInStatus(stepStatus, step.Name, step.Properties, status)
6565
for _, output := range step.Outputs {
6666
v, err := value.LookupValueByScript(taskValue, output.ValueFrom)
67-
if err != nil && strings.Contains(err.Error(), "not exist") && !strings.Contains(output.ValueFrom, "$returns.") {
68-
parts := strings.Split(output.ValueFrom, ".")
67+
if (err != nil && strings.Contains(err.Error(), "not exist") || v.Err() != nil) && !strings.Contains(output.ValueFrom, "$returns.") {
68+
parts := strings.Split(output.ValueFrom, "output.")
6969
if len(parts) > 1 {
70-
v, err = value.LookupValueByScript(taskValue, fmt.Sprintf("%s.$returns.%s", parts[0], strings.Join(parts[1:], ".")))
70+
if parts[0] == "" {
71+
v, err = value.LookupValueByScript(taskValue, fmt.Sprintf("output.$returns.%s", strings.Join(parts[1:], ".")))
72+
} else {
73+
v, err = value.LookupValueByScript(taskValue, fmt.Sprintf("%soutput.$returns.%s", parts[0], strings.Join(parts[1:], ".")))
74+
}
75+
7176
} else {
7277
v, err = value.LookupValueByScript(taskValue, fmt.Sprintf("%s.$returns", output.ValueFrom))
7378
}

pkg/hooks/data_passing_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ func TestOutput(t *testing.T) {
138138
r.Equal(int(resultInt), 99)
139139
r.Equal(stepStatus["mystep"].Phase, v1alpha1.WorkflowStepPhaseSucceeded)
140140

141-
142141
taskValue = cuectx.CompileString(`output: $returns: score: 99`)
143142
stepStatus = make(map[string]v1alpha1.StepStatus)
144143
err = Output(wfCtx, taskValue, v1alpha1.WorkflowStep{

0 commit comments

Comments
 (0)