diff --git a/main.go b/main.go index 365e9b1..dda3d09 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ var ( ref string // plugin repository reference sha string // plugin repository commit kind string // plugin kind (action, bitrise, harness) - outputfile string // plugin outputfile + outputFile string // plugin outputfile ) func main() { @@ -38,7 +38,6 @@ func main() { flag.StringVar(&ref, "ref", "", "plugin reference") flag.StringVar(&sha, "sha", "", "plugin commit") flag.StringVar(&kind, "kind", "", "plugin kind") - flag.StringVar(&outputfile, "outputfile", "", "filepath to store output variables") flag.Parse() // the user may specific the action plugin alias instead @@ -104,6 +103,8 @@ func main() { os.Exit(1) } + outputFile = os.Getenv("DRONE_OUTPUT") + switch { // execute harness plugin case harness.Is(codedir) || kind == "harness": @@ -131,7 +132,7 @@ func main() { Environ: bitrise.Environ( os.Environ(), ), - Outputfile: outputfile, + OutputFile: outputFile, } if err := execer.Exec(ctx); err != nil { log.Error("step failed", err) @@ -146,7 +147,7 @@ func main() { Stdout: os.Stdout, Stderr: os.Stderr, Environ: os.Environ(), - Outputfile: outputfile, + OutputFile: outputFile, } if err := execer.Exec(ctx); err != nil { log.Error("action step failed", err) diff --git a/plugin/bitrise/execer.go b/plugin/bitrise/execer.go index 3fb780f..f541d63 100644 --- a/plugin/bitrise/execer.go +++ b/plugin/bitrise/execer.go @@ -21,7 +21,7 @@ type Execer struct { Environ []string Stdout io.Writer Stderr io.Writer - Outputfile string + OutputFile string } // Exec executes a bitrise plugin. @@ -149,9 +149,9 @@ func (e *Execer) Exec(ctx context.Context) error { } // save to outputfile if present - if len(e.Outputfile) > 0 { + if len(e.OutputFile) > 0 { if m, err := readEnvStore(e.Source); err == nil && len(m.Envs) > 0 { - if err = saveOutputFromEnvStore(m.Envs, e.Outputfile); err != nil { + if err = saveOutputFromEnvStore(m.Envs, e.OutputFile); err != nil { slog.FromContext(ctx).Error("Unable to save output", err) } } else if err != nil { diff --git a/plugin/github/execer.go b/plugin/github/execer.go index 64c49fa..b13f386 100644 --- a/plugin/github/execer.go +++ b/plugin/github/execer.go @@ -22,7 +22,7 @@ type Execer struct { Name string Environ []string TmpDir string - Outputfile string + OutputFile string Stdout io.Writer Stderr io.Writer } @@ -41,7 +41,7 @@ func (e *Execer) Exec(ctx context.Context) error { workflowFile := filepath.Join(e.TmpDir, "workflow.yml") beforeStepEnvFile := filepath.Join(e.TmpDir, "before.env") afterStepEnvFile := filepath.Join(e.TmpDir, "after.env") - if err := createWorkflowFile(e.Name, envVars, workflowFile, beforeStepEnvFile, afterStepEnvFile, e.Outputfile, outputVars); err != nil { + if err := createWorkflowFile(e.Name, envVars, workflowFile, beforeStepEnvFile, afterStepEnvFile, e.OutputFile, outputVars); err != nil { return err } diff --git a/plugin/github/workflow.go b/plugin/github/workflow.go index c7be355..32445a7 100644 --- a/plugin/github/workflow.go +++ b/plugin/github/workflow.go @@ -46,7 +46,7 @@ const ( ) func createWorkflowFile(action string, envVars map[string]string, - ymlFile, beforeStepEnvFile, afterStepEnvFile string, outputfile string, output_vars []string) error { + ymlFile, beforeStepEnvFile, afterStepEnvFile string, outputFile string, outputVars []string) error { with, err := getWith(envVars) if err != nil { return err @@ -63,7 +63,7 @@ func createWorkflowFile(action string, envVars map[string]string, With: with, Env: env, }, - getOutputVariables(stepId, outputfile, output_vars), + getOutputVariables(stepId, outputFile, outputVars), prePostStep("after", afterStepEnvFile), }, } @@ -112,17 +112,17 @@ func prePostStep(name, envFile string) step { return s } -func getOutputVariables(prevStepId, outputfile string, output_vars []string) step { - skip := len(outputfile) == 0 || len(output_vars) == 0 +func getOutputVariables(prevStepId, outputFile string, outputVars []string) step { + skip := len(outputFile) == 0 || len(outputVars) == 0 cmd := "" - for _, output_var := range output_vars { - cmd += fmt.Sprintf("print(\"%s\"+\"=\"+\"${{ steps.%s.outputs.%s }}\"); ", output_var, prevStepId, output_var) + for _, outputVar := range outputVars { + cmd += fmt.Sprintf("print(\"%s\"+\"=\"+\"${{ steps.%s.outputs.%s }}\"); ", outputVar, prevStepId, outputVar) } if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" { - cmd = fmt.Sprintf("python3 -c '%s' > %s", cmd, outputfile) + cmd = fmt.Sprintf("python3 -c '%s' > %s", cmd, outputFile) } else { - cmd = fmt.Sprintf("python -c '%s' > %s", cmd, outputfile) + cmd = fmt.Sprintf("python -c '%s' > %s", cmd, outputFile) } s := step{ Name: "output variables",