mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-05-08 14:43:57 +08:00
Aligns runner log output more closely with `actions/runner`: - Strip the whale, rocket, cloud, construction, chequered-flag, and exclamation-mark glyphs from log lines and drop the now-unused `logPrefix` constant. - Reword `no outputs used step '%s'` → `No outputs registered for step '%s'` (the original was ungrammatical and inaccurate — it fires when `set-output` references an unknown step ID). - Wrap the docker pull/network/create/start phase of job container startup in a `::group::Starting job container` / `::endgroup::` collapsible section, mirroring `actions/runner`. Since act drives Docker through the SDK rather than the CLI, we can't echo `##[command]/usr/bin/docker create ...` lines verbatim — instead the helper emits a summary inside the group: ``` ::group::Starting job container image: <image> name: <container-name> network: <network-name> ::endgroup:: ``` - Extracted the emit into a `printStartJobContainerGroup` helper (parallel to `printRunActionHeader` in `step_run.go`) and added a golden-style test `TestPrintStartJobContainerGroupGolden`. - Drive-by: replace two remaining literal `"raw_output"` strings in `run_context.go` with the existing `rawOutputField` constant. Closes #935 --- This PR was written with the help of Claude Opus 4.7 Reviewed-on: https://gitea.com/gitea/runner/pulls/940 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-committed-by: silverwind <me@silverwind.io>
86 lines
1.9 KiB
Go
86 lines
1.9 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd))
|
|
|
|
package container
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/json"
|
|
"errors"
|
|
"io"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type dockerMessage struct {
|
|
ID string `json:"id"`
|
|
Stream string `json:"stream"`
|
|
Error string `json:"error"`
|
|
ErrorDetail struct {
|
|
Message string
|
|
}
|
|
Status string `json:"status"`
|
|
Progress string `json:"progress"`
|
|
}
|
|
|
|
func logDockerResponse(logger logrus.FieldLogger, dockerResponse io.ReadCloser, isError bool) error {
|
|
if dockerResponse == nil {
|
|
return nil
|
|
}
|
|
defer dockerResponse.Close()
|
|
|
|
scanner := bufio.NewScanner(dockerResponse)
|
|
msg := dockerMessage{}
|
|
|
|
for scanner.Scan() {
|
|
line := scanner.Bytes()
|
|
|
|
msg.ID = ""
|
|
msg.Stream = ""
|
|
msg.Error = ""
|
|
msg.ErrorDetail.Message = ""
|
|
msg.Status = ""
|
|
msg.Progress = ""
|
|
|
|
if err := json.Unmarshal(line, &msg); err != nil {
|
|
writeLog(logger, false, "Unable to unmarshal line [%s] ==> %v", string(line), err)
|
|
continue
|
|
}
|
|
|
|
if msg.Error != "" {
|
|
writeLog(logger, isError, "%s", msg.Error)
|
|
return errors.New(msg.Error)
|
|
}
|
|
|
|
if msg.ErrorDetail.Message != "" {
|
|
writeLog(logger, isError, "%s", msg.ErrorDetail.Message)
|
|
return errors.New(msg.Error)
|
|
}
|
|
|
|
if msg.Status != "" {
|
|
if msg.Progress != "" {
|
|
writeLog(logger, isError, "%s :: %s :: %s\n", msg.Status, msg.ID, msg.Progress)
|
|
} else {
|
|
writeLog(logger, isError, "%s :: %s\n", msg.Status, msg.ID)
|
|
}
|
|
} else if msg.Stream != "" {
|
|
writeLog(logger, isError, "%s", msg.Stream)
|
|
} else {
|
|
writeLog(logger, false, "Unable to handle line: %s", string(line))
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func writeLog(logger logrus.FieldLogger, isError bool, format string, args ...any) {
|
|
if isError {
|
|
logger.Errorf(format, args...)
|
|
} else {
|
|
logger.Debugf(format, args...)
|
|
}
|
|
}
|