diff --git a/README.md b/README.md index fac1694..7b92856 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ This action is intended to be used in conjunction with the [OpenTelemetry Collec | `otel-resource-attributes` | Key-value pairs as resource attributes, formatted as comma-separated values: `key1=value1,key2=value2`. | Optional | | `otel-service-name` | The logical name of the service which sets the value of the service.name resource attribute. | Required | | `run` | The command to be executed. | Required | -| `shell` | Override the default shell settings in the runner's operating system. Supported options are `bash`, `pwsh`, `python`, `sh`, `cmd`, `pwsh`, and `powershell`. | Optional | +| `shell` | Override the default shell settings in the runner's operating system. Supported options are `bash`, `pwsh`, `python`, `sh`, `cmd`, `pwsh`, and `powershell`. Default: `bash`. | Optional | +| `stderr-as-info` | If set to `true`, the standard error output will be treated as standard output. Default: `false`. | Optional | | `step-name` | The name of the step. | Required | ### Outputs diff --git a/Taskfile.yml b/Taskfile.yml index 6ee06d6..0dd22f9 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -2,7 +2,7 @@ version: '3' vars: BUILD_VERSION: - sh: echo "0.4.5" + sh: echo "0.5.0" BUILD_DATE: sh: date "+%F %T" COMMIT_ID: diff --git a/action.yaml b/action.yaml index 20346fd..cda023d 100644 --- a/action.yaml +++ b/action.yaml @@ -57,6 +57,12 @@ inputs: You can override the default shell settings in the runner's operating system using the shell keyword. Supported options are bash, pwsh, python, sh, cmd, pwsh and powershell. The default is bash. + stderr-as-info: + required: false + default: false + description: > + If set to 'true', logs stderr as informational messages instead of errors. + Useful for commands that use stderr for standard output. step-name: required: true description: > diff --git a/bin/run-with-telemetry-darwin-amd64 b/bin/run-with-telemetry-darwin-amd64 index 5152417..3cc430c 100755 Binary files a/bin/run-with-telemetry-darwin-amd64 and b/bin/run-with-telemetry-darwin-amd64 differ diff --git a/bin/run-with-telemetry-darwin-arm64 b/bin/run-with-telemetry-darwin-arm64 index a414b4f..e47150d 100755 Binary files a/bin/run-with-telemetry-darwin-arm64 and b/bin/run-with-telemetry-darwin-arm64 differ diff --git a/bin/run-with-telemetry-linux-amd64 b/bin/run-with-telemetry-linux-amd64 index 74e9a3a..275ca34 100755 Binary files a/bin/run-with-telemetry-linux-amd64 and b/bin/run-with-telemetry-linux-amd64 differ diff --git a/bin/run-with-telemetry-linux-armv8 b/bin/run-with-telemetry-linux-armv8 index 96c05f5..5239f0c 100755 Binary files a/bin/run-with-telemetry-linux-armv8 and b/bin/run-with-telemetry-linux-armv8 differ diff --git a/bin/run-with-telemetry-windows-amd64.exe b/bin/run-with-telemetry-windows-amd64.exe index a5dde47..98107cb 100755 Binary files a/bin/run-with-telemetry-windows-amd64.exe and b/bin/run-with-telemetry-windows-amd64.exe differ diff --git a/cmd/run-with-telemetry/main.go b/cmd/run-with-telemetry/main.go index b2c2aeb..1b3441c 100644 --- a/cmd/run-with-telemetry/main.go +++ b/cmd/run-with-telemetry/main.go @@ -46,6 +46,7 @@ type InputParams struct { StepName string JobName string JobAsParent string + StderrAsInfo string } type TextMapCarrier map[string]string @@ -102,7 +103,7 @@ func emitStepSummary(params InputParams, traceID trace.TraceID, spanID trace.Spa githubactions.AddStepSummary(markdownSummary) } -func executeCommand(shell string, command string, span trace.Span, headers map[string]string) (string, int, string, string, error) { +func executeCommand(shell string, command string, span trace.Span, headers map[string]string, stderrAsInfo bool) (string, int, string, string, error) { var cmd *exec.Cmd var args []string @@ -165,12 +166,19 @@ func executeCommand(shell string, command string, span trace.Span, headers map[s } }() + if stderrAsInfo { + githubactions.Infof("Redirecting stderr to info: %t", stderrAsInfo) + } go func() { defer wg.Done() scanner := bufio.NewScanner(stderrPipe) for scanner.Scan() { line := scanner.Text() - githubactions.Errorf("%s", line) + if stderrAsInfo { + githubactions.Infof("%s", line) + } else { + githubactions.Errorf("%s", line) + } stderrBuf.WriteString(line + "\n") } }() @@ -393,6 +401,7 @@ func parseInputParams() InputParams { StepName: githubactions.GetInput("step-name"), JobName: githubactions.GetInput("job-name"), JobAsParent: githubactions.GetInput("job-as-parent"), + StderrAsInfo: githubactions.GetInput("stderr-as-info"), } } @@ -539,7 +548,8 @@ func main() { shell := githubactions.GetInput("shell") githubactions.Infof("Executing command: %s with shell: %s", params.Run, shell) - usedShell, pid, stdout, stderr, err := executeCommand(shell, params.Run, span, params.OtelExporterOtlpHeaders) + stderrAsInfo := strings.ToLower(params.StderrAsInfo) == "true" + usedShell, pid, stdout, stderr, err := executeCommand(shell, params.Run, span, params.OtelExporterOtlpHeaders, stderrAsInfo) if err != nil { githubactions.Errorf("Failed to execute command: %v", err)