|
6 | 6 | "io"
|
7 | 7 | "os"
|
8 | 8 | "path/filepath"
|
| 9 | + "strconv" |
9 | 10 |
|
10 | 11 | "github.com/golangci/golangci-lint/pkg/result"
|
11 | 12 | )
|
@@ -72,20 +73,24 @@ func NewGitHubActionProblemMatchers(w io.Writer) *GitHubActionProblemMatchers {
|
72 | 73 | }
|
73 | 74 |
|
74 | 75 | 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 | + } |
87 | 90 |
|
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 | + } |
89 | 94 |
|
90 | 95 | for ind := range issues {
|
91 | 96 | _, err := fmt.Fprintln(p.w, formatIssueAsProblemMatcher(&issues[ind]))
|
@@ -115,6 +120,9 @@ func (p *GitHubActionProblemMatchers) storeProblemMatcher() (string, error) {
|
115 | 120 | return file.Name(), nil
|
116 | 121 | }
|
117 | 122 |
|
| 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 |
118 | 126 | func generateProblemMatcher() GHProblemMatchers {
|
119 | 127 | return GHProblemMatchers{
|
120 | 128 | Matchers: []GHMatcher{
|
|
0 commit comments