1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-11 17:50:58 +00:00

Improve logging (#1171)

* feat: use logger from context wherever possible

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: add step/job id and results to json logs

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* test: value to be masked should not be hard-coded in the action

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* fix: replace values following ::add-mask:: in evaluated strings

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: [DEBUG] identifier for debug logs to distinguish them

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: replace logger with step logger

The container gets injected a job logger, but during the time that steps
are run, we want to use the step logger.
This commit wraps pre/main/post steps in an executor that replaces the
job logger with a step logger.

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: add pre/post stage identifier fields to json log output

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

* feat: add job/step result status to skipped steps/jobs

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>

Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Björn Brauer 2022-06-17 17:55:21 +02:00 committed by GitHub
parent e35ab25fed
commit ad6aeb1969
35 changed files with 363 additions and 292 deletions

View file

@ -1,11 +1,11 @@
package model
import (
"context"
"fmt"
"github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/common/git"
log "github.com/sirupsen/logrus"
)
type GithubContext struct {
@ -63,7 +63,7 @@ func nestedMapLookup(m map[string]interface{}, ks ...string) (rval interface{})
}
}
func withDefaultBranch(b string, event map[string]interface{}) map[string]interface{} {
func withDefaultBranch(ctx context.Context, b string, event map[string]interface{}) map[string]interface{} {
repoI, ok := event["repository"]
if !ok {
repoI = make(map[string]interface{})
@ -71,7 +71,7 @@ func withDefaultBranch(b string, event map[string]interface{}) map[string]interf
repo, ok := repoI.(map[string]interface{})
if !ok {
log.Warnf("unable to set default branch to %v", b)
common.Logger(ctx).Warnf("unable to set default branch to %v", b)
return event
}
@ -89,7 +89,8 @@ func withDefaultBranch(b string, event map[string]interface{}) map[string]interf
var findGitRef = git.FindGitRef
var findGitRevision = git.FindGitRevision
func (ghc *GithubContext) SetRefAndSha(defaultBranch string, repoPath string) {
func (ghc *GithubContext) SetRefAndSha(ctx context.Context, defaultBranch string, repoPath string) {
logger := common.Logger(ctx)
// https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
// https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads
switch ghc.EventName {
@ -113,19 +114,19 @@ func (ghc *GithubContext) SetRefAndSha(defaultBranch string, repoPath string) {
}
if ghc.Ref == "" {
ref, err := findGitRef(repoPath)
ref, err := findGitRef(ctx, repoPath)
if err != nil {
log.Warningf("unable to get git ref: %v", err)
logger.Warningf("unable to get git ref: %v", err)
} else {
log.Debugf("using github ref: %s", ref)
logger.Debugf("using github ref: %s", ref)
ghc.Ref = ref
}
// set the branch in the event data
if defaultBranch != "" {
ghc.Event = withDefaultBranch(defaultBranch, ghc.Event)
ghc.Event = withDefaultBranch(ctx, defaultBranch, ghc.Event)
} else {
ghc.Event = withDefaultBranch("master", ghc.Event)
ghc.Event = withDefaultBranch(ctx, "master", ghc.Event)
}
if ghc.Ref == "" {
@ -134,9 +135,9 @@ func (ghc *GithubContext) SetRefAndSha(defaultBranch string, repoPath string) {
}
if ghc.Sha == "" {
_, sha, err := findGitRevision(repoPath)
_, sha, err := findGitRevision(ctx, repoPath)
if err != nil {
log.Warningf("unable to get git revision: %v", err)
logger.Warningf("unable to get git revision: %v", err)
} else {
ghc.Sha = sha
}