Skip to content

Commit

Permalink
feat: option to use the matchers file inside the Official GitHub Action
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed May 6, 2024
1 parent a6711f9 commit 87a6fd0
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions pkg/printers/githubaction_problem_matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"strconv"

"github.com/golangci/golangci-lint/pkg/result"
)
Expand Down Expand Up @@ -72,20 +73,24 @@ func NewGitHubActionProblemMatchers(w io.Writer) *GitHubActionProblemMatchers {
}

func (p *GitHubActionProblemMatchers) Print(issues []result.Issue) error {
// Note: the file with the problem matcher definition should not be removed.
// A sleep can mitigate this problem but this will be flaky.
//
// Result if the file is removed prematurely:
// Error: Unable to process command '::add-matcher::/tmp/golangci-lint-action-problem-matchers.json' successfully.
// Error: Could not find file '/tmp/golangci-lint-action-problem-matchers.json'.
filename, err := p.storeProblemMatcher()
if err != nil {
return err
}

_, _ = fmt.Fprintln(p.w, "::debug::problem matcher definition file: "+filename)
// Used by the official GitHub Action (https://github.com/golangci/golangci-lint-action).
// The problem matchers is embedded inside the GitHub Action to avoid errors:
// https://github.com/golangci/golangci-lint/issues/4695
if ok, _ := strconv.ParseBool(os.Getenv("GOLANGCI_LINT_SKIP_GHA_PM_INSTALL")); !ok {
// Note: the file with the problem matcher definition should not be removed.
// A sleep can mitigate this problem but this will be flaky.
//
// Result if the file is removed prematurely:
// Error: Unable to process command '::add-matcher::/tmp/golangci-lint-action-problem-matchers.json' successfully.
// Error: Could not find file '/tmp/golangci-lint-action-problem-matchers.json'.
filename, err := p.storeProblemMatcher()
if err != nil {
return err
}

_, _ = fmt.Fprintln(p.w, "::add-matcher::"+filename)
_, _ = fmt.Fprintln(p.w, "::debug::problem matcher definition file: "+filename)
_, _ = fmt.Fprintln(p.w, "::add-matcher::"+filename)
}

for ind := range issues {
_, err := fmt.Fprintln(p.w, formatIssueAsProblemMatcher(&issues[ind]))
Expand Down Expand Up @@ -115,6 +120,9 @@ func (p *GitHubActionProblemMatchers) storeProblemMatcher() (string, error) {
return file.Name(), nil
}

// generateProblemMatcher generated the problem matchers file.
// Should be synced with the official GitHub Action.
// https://github.com/golangci/golangci-lint-action/blob/master/problem-matchers.json
func generateProblemMatcher() GHProblemMatchers {
return GHProblemMatchers{
Matchers: []GHMatcher{
Expand Down

0 comments on commit 87a6fd0

Please sign in to comment.