output: convert backslashes to forward slashes for GitHub Action annotations printer (#4149)
Some checks failed
Release a tag / release (push) Has been cancelled
Release a tag / docker-release (map[Dockerfile:build/Dockerfile]) (push) Has been cancelled
Release a tag / docker-release (map[Dockerfile:build/alpine.Dockerfile]) (push) Has been cancelled
Some checks failed
Release a tag / release (push) Has been cancelled
Release a tag / docker-release (map[Dockerfile:build/Dockerfile]) (push) Has been cancelled
Release a tag / docker-release (map[Dockerfile:build/alpine.Dockerfile]) (push) Has been cancelled
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
3d582093e6
commit
9b20d49dc2
@ -3,6 +3,7 @@ package printers
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/result"
|
"github.com/golangci/golangci-lint/pkg/result"
|
||||||
)
|
)
|
||||||
@ -26,7 +27,12 @@ func formatIssueAsGithub(issue *result.Issue) string {
|
|||||||
severity = issue.Severity
|
severity = issue.Severity
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := fmt.Sprintf("::%s file=%s,line=%d", severity, issue.FilePath(), issue.Line())
|
// Convert backslashes to forward slashes.
|
||||||
|
// This is needed when running on windows.
|
||||||
|
// Otherwise, GitHub won't be able to show the annotations pointing to the file path with backslashes.
|
||||||
|
file := filepath.ToSlash(issue.FilePath())
|
||||||
|
|
||||||
|
ret := fmt.Sprintf("::%s file=%s,line=%d", severity, file, issue.Line())
|
||||||
if issue.Pos.Column != 0 {
|
if issue.Pos.Column != 0 {
|
||||||
ret += fmt.Sprintf(",col=%d", issue.Pos.Column)
|
ret += fmt.Sprintf(",col=%d", issue.Pos.Column)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ package printers
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -72,3 +73,24 @@ func TestFormatGithubIssue(t *testing.T) {
|
|||||||
sampleIssue.Pos.Column = 0
|
sampleIssue.Pos.Column = 0
|
||||||
require.Equal(t, "::error file=path/to/file.go,line=10::some issue (sample-linter)", formatIssueAsGithub(&sampleIssue))
|
require.Equal(t, "::error file=path/to/file.go,line=10::some issue (sample-linter)", formatIssueAsGithub(&sampleIssue))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFormatGithubIssueWindows(t *testing.T) {
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
t.Skip("Skipping test on non Windows")
|
||||||
|
}
|
||||||
|
|
||||||
|
sampleIssue := result.Issue{
|
||||||
|
FromLinter: "sample-linter",
|
||||||
|
Text: "some issue",
|
||||||
|
Pos: token.Position{
|
||||||
|
Filename: "path\\to\\file.go",
|
||||||
|
Offset: 2,
|
||||||
|
Line: 10,
|
||||||
|
Column: 4,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.Equal(t, "::error file=path/to/file.go,line=10,col=4::some issue (sample-linter)", formatIssueAsGithub(&sampleIssue))
|
||||||
|
|
||||||
|
sampleIssue.Pos.Column = 0
|
||||||
|
require.Equal(t, "::error file=path/to/file.go,line=10::some issue (sample-linter)", formatIssueAsGithub(&sampleIssue))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user