mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-10-30 11:58:49 +08:00
Removes dead code and redundant logic and consolidates tests, so there is less to read and maintain. No behavior change. 1. **act/runner**: inline single-use wrappers, compile regexes once instead of per call, embed the trampoline as a string, drop the unused legacy result of `parseActionCommand` 2. **act/container**: `sanitizeConfig` and `mergeContainerConfigs` stop returning the configs they already mutate in place, drop never-set option fields and the unused `user` parameter of `ExecWithCmdLine` 3. **act/common and cache server**: drop the unused `Trace`/`Tracef` loggers and the short SHA of `FindGitRevision`, `RegisterJob` releases through `RevokeJob` 4. **daemon, poller and reporter**: one shutdown wait for both poll modes, drop an unreachable fetch timeout branch, guard the reporter's last report time with its existing lock instead of an atomic 5. **build**: drop unused Makefile and release workflow variables, collapse the goreleaser ignore list to the same build targets 6. **tests**: fold near-duplicate tests into tables with shared setup Throughout, hand-rolled logic gives way to `cmp.Or`, `strings.Cut`, `slices` and `min`/`max`. Reviewed-on: https://gitea.com/gitea/runner/pulls/1335 Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io>
91 lines
3.0 KiB
Go
91 lines
3.0 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package run
|
|
|
|
import (
|
|
"fmt"
|
|
"maps"
|
|
"os"
|
|
"runtime"
|
|
"slices"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"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
|
|
// falls back to the Go runtime alone. A var so tests can point it at a fixture.
|
|
var osReleasePath = "/etc/os-release"
|
|
|
|
// setupLines names the runner, then reports what it was asked to run and the host it runs on, each
|
|
// in its own group.
|
|
func (r *Runner) setupLines(task *runnerv1.Task) []string {
|
|
fields := task.Context.Fields
|
|
lines := []string{
|
|
fmt.Sprintf("%s(version:%s)", r.name, ver.Version()),
|
|
"::group::Runner Information",
|
|
}
|
|
if names := r.labels.Names(); len(names) > 0 {
|
|
lines = append(lines, "Runner labels: "+strings.Join(names, ", "))
|
|
}
|
|
lines = append(lines,
|
|
// The task id correlates the job log with the runner's log and the server's task list.
|
|
fmt.Sprintf("Task: %d", task.Id),
|
|
"Job: "+fields["job"].GetStringValue(),
|
|
"Repository: "+fields["repository"].GetStringValue(),
|
|
"Triggered by event: "+fields["event_name"].GetStringValue(),
|
|
"::endgroup::",
|
|
)
|
|
lines = append(lines, inputLines(fields)...)
|
|
lines = append(lines, "::group::Operating System")
|
|
if name := prettyOSName(); name != "" {
|
|
lines = append(lines, name)
|
|
}
|
|
return append(lines, fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), "::endgroup::")
|
|
}
|
|
|
|
// inputLines lists the inputs of the job: those Gitea resolved for a called workflow's job,
|
|
// or the ones a workflow_dispatch event carries in its payload. Empty when there are none.
|
|
func inputLines(fields map[string]*structpb.Value) []string {
|
|
inputs := fields["event"].GetStructValue().GetFields()["inputs"].GetStructValue().GetFields()
|
|
// For a called workflow's job, restore its inputs from `gitea_workflow_call`.
|
|
// See https://github.com/go-gitea/gitea/pull/39452.
|
|
if workflowCall := fields["gitea_workflow_call"].GetStructValue(); workflowCall != nil {
|
|
inputs = workflowCall.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::")
|
|
}
|
|
|
|
// prettyOSName reads PRETTY_NAME (e.g. "Ubuntu 24.04.4 LTS") from os-release, or "" when absent.
|
|
func prettyOSName() string {
|
|
data, err := os.ReadFile(osReleasePath)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
for line := range strings.SplitSeq(string(data), "\n") {
|
|
key, value, ok := strings.Cut(strings.TrimSpace(line), "=")
|
|
if !ok || key != "PRETTY_NAME" {
|
|
continue
|
|
}
|
|
// Values are shell-quoted, but the quotes are optional.
|
|
if unquoted, err := strconv.Unquote(value); err == nil {
|
|
return unquoted
|
|
}
|
|
return value
|
|
}
|
|
return ""
|
|
}
|