mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-18 11:06:18 +00:00
enhance: show workflow_dispatch inputs in the "Set up job" section (#1167)
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 <xiaolunwen@gmail.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user