From 6c6a878403137f04c380ff6bf5bf6a5e323f83b5 Mon Sep 17 00:00:00 2001 From: bircni Date: Sat, 15 Aug 2026 19:57:30 +0000 Subject: [PATCH] enhance: show workflow_dispatch inputs in the "Set up job" section (#1167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trigger-time inputs used to be visible in the job log but are no longer shown after the "Set up job" section was reshaped. This restores them as an "Inputs" group listing each provided input and its value, rendered only when the event payload carries inputs. For a run dispatched with `required=required input`, `with_default=default` and `boolean=true`, the "Set up job" log now shows: ​``` gitea-com-gitea-0003(version:v3.0.2) ▸ Runner Information Task: 268506 Job: test Repository: gitea/runner Triggered by event: workflow_dispatch ▸ Inputs boolean: true required: required input with_default: default ▸ Operating System Ubuntu 24.04.4 LTS linux/amd64 ​``` Closes https://gitea.com/gitea/runner/issues/1166 Reviewed-on: https://gitea.com/gitea/runner/pulls/1167 Reviewed-by: Lunny Xiao --- internal/app/run/setup.go | 20 ++++++++++++++++- internal/app/run/setup_test.go | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/internal/app/run/setup.go b/internal/app/run/setup.go index 1a6e45c0..654e8284 100644 --- a/internal/app/run/setup.go +++ b/internal/app/run/setup.go @@ -5,8 +5,10 @@ package run import ( "fmt" + "maps" "os" "runtime" + "slices" "strconv" "strings" @@ -14,6 +16,7 @@ import ( "gitea.com/gitea/runner/internal/pkg/ver" runnerv1 "gitea.dev/actionslib/runner/v1" + "google.golang.org/protobuf/types/known/structpb" ) // osReleasePath describes the host distribution on Linux; absent elsewhere, where the platform @@ -46,12 +49,27 @@ func (r *Runner) setupLines(task *runnerv1.Task) []string { "Repository: "+fields["repository"].GetStringValue(), "Triggered by event: "+fields["event_name"].GetStringValue(), "::endgroup::", - "::group::Operating System", ) + lines = append(lines, inputLines(fields)...) + lines = append(lines, "::group::Operating System") lines = append(lines, osInfo()...) return append(lines, "::endgroup::") } +// inputLines lists the inputs the run was triggered with, as workflow_dispatch and workflow_call +// carry them in the event payload. Empty when the event has none. +func inputLines(fields map[string]*structpb.Value) []string { + inputs := fields["event"].GetStructValue().GetFields()["inputs"].GetStructValue().GetFields() + if len(inputs) == 0 { + return nil + } + lines := []string{"::group::Inputs"} + for _, name := range slices.Sorted(maps.Keys(inputs)) { + lines = append(lines, fmt.Sprintf("%s: %v", name, inputs[name].AsInterface())) + } + return append(lines, "::endgroup::") +} + // osInfo describes the host the runner executes on. func osInfo() []string { lines := make([]string, 0, 2) diff --git a/internal/app/run/setup_test.go b/internal/app/run/setup_test.go index b9f43734..91b841a9 100644 --- a/internal/app/run/setup_test.go +++ b/internal/app/run/setup_test.go @@ -56,6 +56,45 @@ func TestSetupLines(t *testing.T) { }, r.setupLines(&runnerv1.Task{Id: 268506, Context: taskCtx})) } +func TestSetupLinesInputs(t *testing.T) { + original := osReleasePath + osReleasePath = filepath.Join(t.TempDir(), "absent") + defer func() { osReleasePath = original }() + + r := &Runner{name: "gitea-com-gitea-0003"} + taskCtx, err := structpb.NewStruct(map[string]any{ + "job": "test", + "repository": "gitea/runner", + "event_name": "workflow_dispatch", + "event": map[string]any{ + "inputs": map[string]any{ + "with_default": "default", + "required": "required input", + "boolean": true, + }, + }, + }) + require.NoError(t, err) + + assert.Equal(t, []string{ + "gitea-com-gitea-0003(version:" + ver.Version() + ")", + "::group::Runner Information", + "Task: 1", + "Job: test", + "Repository: gitea/runner", + "Triggered by event: workflow_dispatch", + "::endgroup::", + "::group::Inputs", + "boolean: true", + "required: required input", + "with_default: default", + "::endgroup::", + "::group::Operating System", + fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), + "::endgroup::", + }, r.setupLines(&runnerv1.Task{Id: 1, Context: taskCtx})) +} + func TestPrettyOSName(t *testing.T) { tests := map[string]struct { osRelease string