Skip to content

Commit

Permalink
don't spam duplicate warnings in github_context
Browse files Browse the repository at this point in the history
Thanks to go-git/go-git#530, act will spam the
console/log with a billion warnings like this:

WARN[0000] unable to get git repo: branch config: invalid merge

when a GitHub PR branch is checked out.
  • Loading branch information
chris-laplante committed Sep 25, 2023
1 parent 2be4def commit 200db77
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pkg/model/github_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import (
"context"
"fmt"
"strings"
"sync"

"github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/common/git"
)

var (
loggedWarnings = make(map[string]bool)
mu sync.Mutex
)

type GithubContext struct {
Event map[string]interface{} `json:"event"`
EventPath string `json:"event_path"`
Expand Down Expand Up @@ -168,7 +174,11 @@ func (ghc *GithubContext) SetRepositoryAndOwner(ctx context.Context, githubInsta
if ghc.Repository == "" {
repo, err := git.FindGithubRepo(ctx, repoPath, githubInstance, remoteName)
if err != nil {
common.Logger(ctx).Warningf("unable to get git repo: %v", err)
warningMsg := fmt.Sprintf("unable to get git repo: %v", err)
if !hasLoggedWarning(warningMsg) {
common.Logger(ctx).Warningf(warningMsg)
markWarningAsLogged(warningMsg)
}
return
}
ghc.Repository = repo
Expand Down Expand Up @@ -211,3 +221,16 @@ func (ghc *GithubContext) SetBaseAndHeadRef() {
}
}
}

func hasLoggedWarning(msg string) bool {
mu.Lock()
defer mu.Unlock()
_, exists := loggedWarnings[msg]
return exists
}

func markWarningAsLogged(msg string) {
mu.Lock()
defer mu.Unlock()
loggedWarnings[msg] = true
}

0 comments on commit 200db77

Please sign in to comment.