mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-07 09:24:22 +02:00
Revert #1136 and use actionslib instead. revert chore: bump the module path to `/v3`, take the version from the VCS stamp (#1136) gitea can not consume the runner's api by version while it's version mismatches the module version: ``` go: gitea.com/gitea/runner@v3.0.1: invalid version: module contains a go.mod file, so module path must match major version ("gitea.com/gitea/runner/v3") ``` Fix that by bumping the module version now. The existing `v3.0.0` and `v3.0.1` tags stay unusable, so a new tag is needed after this lands. Also drop the version `-X` linker flags, which would otherwise have to repeat the new path in both `Makefile` and `.goreleaser.yaml`, where a stale path makes injection silently no-op. Go has recorded the module version in the build info since 1.24, so `Version()` reads it from there, keeping the variable as an override for builds without a VCS stamp. That part started as https://gitea.com/gitea/runner/pulls/1137 but belongs here: the stamp resolves against the tags that are legal for the module path, so without the `/v3` bump it would report `v1.0.9-0.<ts>-<sha>`. Since `release-nightly.yml` triggers on every push to `main`, splitting them would publish a nightly with a `v1` version. --------- Co-authored-by: bircni <bircni@icloud.com> Reviewed-on: https://gitea.com/gitea/runner/pulls/1136 Reviewed-by: techknowlogick <9+techknowlogick@noreply.gitea.com> Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io> Reviewed-on: https://gitea.com/gitea/runner/pulls/1148 Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com>
84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package run
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"gitea.com/gitea/runner/internal/pkg/report"
|
|
"gitea.com/gitea/runner/internal/pkg/ver"
|
|
|
|
runnerv1 "gitea.dev/actions-proto-go/runner/v1"
|
|
)
|
|
|
|
// 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"
|
|
|
|
// reportSetup opens the job log the way actions/runner opens its "Set up job" step. The action
|
|
// downloads and the closing job name are written later, as the job starts.
|
|
func (r *Runner) reportSetup(reporter *report.Reporter, task *runnerv1.Task) {
|
|
for _, line := range r.setupLines(task) {
|
|
reporter.Logf("%s", line)
|
|
}
|
|
}
|
|
|
|
// 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::",
|
|
"::group::Operating System",
|
|
)
|
|
lines = append(lines, osInfo()...)
|
|
return append(lines, "::endgroup::")
|
|
}
|
|
|
|
// osInfo describes the host the runner executes on.
|
|
func osInfo() []string {
|
|
lines := make([]string, 0, 2)
|
|
if name := prettyOSName(); name != "" {
|
|
lines = append(lines, name)
|
|
}
|
|
return append(lines, fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
|
|
}
|
|
|
|
// 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 ""
|
|
}
|