Skip to content

Commit 87a6fd0

Browse files
committed
feat: option to use the matchers file inside the Official GitHub Action
1 parent a6711f9 commit 87a6fd0

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

pkg/printers/githubaction_problem_matchers.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"os"
88
"path/filepath"
9+
"strconv"
910

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

7475
func (p *GitHubActionProblemMatchers) Print(issues []result.Issue) error {
75-
// Note: the file with the problem matcher definition should not be removed.
76-
// A sleep can mitigate this problem but this will be flaky.
77-
//
78-
// Result if the file is removed prematurely:
79-
// Error: Unable to process command '::add-matcher::/tmp/golangci-lint-action-problem-matchers.json' successfully.
80-
// Error: Could not find file '/tmp/golangci-lint-action-problem-matchers.json'.
81-
filename, err := p.storeProblemMatcher()
82-
if err != nil {
83-
return err
84-
}
85-
86-
_, _ = fmt.Fprintln(p.w, "::debug::problem matcher definition file: "+filename)
76+
// Used by the official GitHub Action (https://github.com/golangci/golangci-lint-action).
77+
// The problem matchers is embedded inside the GitHub Action to avoid errors:
78+
// https://github.com/golangci/golangci-lint/issues/4695
79+
if ok, _ := strconv.ParseBool(os.Getenv("GOLANGCI_LINT_SKIP_GHA_PM_INSTALL")); !ok {
80+
// Note: the file with the problem matcher definition should not be removed.
81+
// A sleep can mitigate this problem but this will be flaky.
82+
//
83+
// Result if the file is removed prematurely:
84+
// Error: Unable to process command '::add-matcher::/tmp/golangci-lint-action-problem-matchers.json' successfully.
85+
// Error: Could not find file '/tmp/golangci-lint-action-problem-matchers.json'.
86+
filename, err := p.storeProblemMatcher()
87+
if err != nil {
88+
return err
89+
}
8790

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

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

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

0 commit comments

Comments
 (0)