diff --git a/utils/workflow.go b/utils/workflow.go index fb754b6..b174734 100644 --- a/utils/workflow.go +++ b/utils/workflow.go @@ -85,20 +85,21 @@ func getWorkflowEvent() string { } func setOutputVariables(prevStepId, outputFile string, outputVars []string) step { - if len(outputVars) == 0 { + skip := len(outputFile) == 0 || len(outputVars) == 0 + if skip { logrus.Infof("No output variables detected in action.yml; skipping output file generation.") - return step{} } + cmd := "" for _, outputVar := range outputVars { cmd += fmt.Sprintf("%s=${{ steps.%s.outputs.%s }}\n", outputVar, prevStepId, outputVar) } cmd = fmt.Sprintf("echo \"%s\" > %s", cmd, outputFile) - s := step{ Name: "output variables", Run: cmd, + If: fmt.Sprintf("%t", !skip), } return s } diff --git a/utils/workflow_test.go b/utils/workflow_test.go index 51c6d8e..44e35ab 100644 --- a/utils/workflow_test.go +++ b/utils/workflow_test.go @@ -40,7 +40,9 @@ func TestCreateWorkflowFile(t *testing.T) { assert.NoError(t, err) content, err = os.ReadFile(workflowFile) assert.NoError(t, err) - assert.NotContains(t, string(content), "run: echo") + assert.Contains(t, string(content), "name: output variables") + assert.Contains(t, string(content), "run: echo \"\" >") + assert.Contains(t, string(content), "if: \"false\"") } func TestSetOutputVariables(t *testing.T) { @@ -56,6 +58,7 @@ func TestSetOutputVariables(t *testing.T) { // No output variables step = setOutputVariables(prevStepId, outputFile, []string{}) - assert.Empty(t, step.Name) - assert.Empty(t, step.Run) + assert.Equal(t, "output variables", step.Name) + assert.Contains(t, step.Run, "echo \"\" > /tmp/output") + assert.Contains(t, step.If, "false") }