Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab
indent_size = 4

[Makefile]
indent_style = tab
indent_size = 4

[*.mod]
indent_style = tab
indent_size = 4
6 changes: 6 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
with:
go-version-file: "go.mod"

- name: Lint
uses: golangci/golangci-lint-action@v7
with:
version: latest

- name: Test
run: go test ./...

Expand Down Expand Up @@ -59,6 +64,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
if: github.event_name == 'release' && github.event.action == 'published'
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
Expand Down
26 changes: 26 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "2"

run:
timeout: 10m
modules-download-mode: readonly

formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/Staffbase/yamllint-action

linters:
default: none
enable:
- bodyclose
- gosec
- govet
- ineffassign
- noctx
- staticcheck
- unused
- whitespace
24 changes: 12 additions & 12 deletions yamllint-action.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func parseInput(r io.Reader) Report {
Severity: severity,
}

if _, exist := files[fileName]; exist == false {
if _, exist := files[fileName]; !exist {
files[fileName] = &LinterResult{FilePath: fileName}
}

Expand Down Expand Up @@ -156,15 +156,15 @@ func handlePush(ctx context.Context, client *github.Client, report Report) error
// find the action's checkrun
checkName := os.Getenv("ACTION_NAME")
result, _, err := client.Checks.ListCheckRunsForRef(ctx, owner, repoName, head, &github.ListCheckRunsOptions{
CheckName: github.String(checkName),
Status: github.String("in_progress"),
CheckName: github.Ptr(checkName),
Status: github.Ptr("in_progress"),
})
if err != nil {
return err
}

if len(result.CheckRuns) == 0 {
return fmt.Errorf("Unable to find check run for action: %s", checkName)
return fmt.Errorf("unable to find check run for action: %s", checkName)
}
checkRun := result.CheckRuns[0]

Expand All @@ -177,12 +177,12 @@ func handlePush(ctx context.Context, client *github.Client, report Report) error
if len(t.AssertionResults) > 0 {
for _, a := range t.AssertionResults {
annotations = append(annotations, &github.CheckRunAnnotation{
Path: github.String(path),
StartLine: github.Int(a.Line),
EndLine: github.Int(a.Line),
AnnotationLevel: github.String(a.Severity),
Title: github.String(""),
Message: github.String(a.Message),
Path: github.Ptr(path),
StartLine: github.Ptr(a.Line),
EndLine: github.Ptr(a.Line),
AnnotationLevel: github.Ptr(a.Severity),
Title: github.Ptr(""),
Message: github.Ptr(a.Message),
})
}
}
Expand All @@ -202,8 +202,8 @@ func handlePush(ctx context.Context, client *github.Client, report Report) error
}

output := &github.CheckRunOutput{
Title: github.String("Result"),
Summary: github.String(summary),
Title: github.Ptr("Result"),
Summary: github.Ptr(summary),
Annotations: annotations[i:end],
}

Expand Down
38 changes: 19 additions & 19 deletions yamllint-action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ limitations under the License.
package main

import (
"strings"
"testing"
"strings"
"testing"
)

func TestParseInput(t *testing.T) {
t.Run("standard case", func(t *testing.T) {
testData := `sources/prod/testapp-deploy.yaml:17:11: [warning] wrong indentation: expected 12 but found 10 (indentation)
t.Run("standard case", func(t *testing.T) {
testData := `sources/prod/testapp-deploy.yaml:17:11: [warning] wrong indentation: expected 12 but found 10 (indentation)
sources/prod/testapp2-deploy.yaml:16:11: [warning] wrong indentation: expected 12 but found 10 (indentation)
sources/prod/testapp3-deploy.yaml:16:11: [warning] wrong indentation: expected 12 but found 10 (indentation)
sources/prod/testapp4-deploy.yaml:17:11: [warning] wrong indentation: expected 12 but found 10 (indentation)
Expand All @@ -31,21 +31,21 @@ sources/stage/testapp4-deploy.yaml:17:11: [warning] wrong indentation: expected
sources/dev/testapp-deploy.yaml:17:11: [warning] wrong indentation: expected 12 but found 10 (indentation)
sources/dev/testapp2-deploy.yaml:16:11: [warning] wrong indentation: expected 12 but found 10 (indentation)`

report := parseInput(strings.NewReader(testData))
if report.NumFailedLines != 10 {
t.Errorf("unexpected amount of failed lines: got %d, wanted %d", report.NumFailedLines, 10)
}
report := parseInput(strings.NewReader(testData))
if report.NumFailedLines != 10 {
t.Errorf("unexpected amount of failed lines: got %d, wanted %d", report.NumFailedLines, 10)
}

if report.LinterResults[0].AssertionResults[0].Severity != "warning" {
t.Errorf("unexpected severity found: got %s, wanted %s", report.LinterResults[0].AssertionResults[0].Severity, "warning")
}

if report.LinterResults[6].AssertionResults[0].Severity != "failure" {
t.Errorf("unexpected severity found: got %s, wanted %s", report.LinterResults[4].AssertionResults[0].Severity, "failure")
}
if report.LinterResults[0].AssertionResults[0].Severity != "warning" {
t.Errorf("unexpected severity found: got %s, wanted %s", report.LinterResults[0].AssertionResults[0].Severity, "warning")
}

if report.LinterResults[6].AssertionResults[0].Message != "wrong indentation: expected 12 but found 10 (indentation)" {
t.Errorf("unexpected severity found: got %s, wanted %s", report.LinterResults[4].AssertionResults[0].Message, "wrong indentation: expected 12 but found 10 (indentation)")
}
})
if report.LinterResults[6].AssertionResults[0].Severity != "failure" {
t.Errorf("unexpected severity found: got %s, wanted %s", report.LinterResults[4].AssertionResults[0].Severity, "failure")
}

if report.LinterResults[6].AssertionResults[0].Message != "wrong indentation: expected 12 but found 10 (indentation)" {
t.Errorf("unexpected severity found: got %s, wanted %s", report.LinterResults[4].AssertionResults[0].Message, "wrong indentation: expected 12 but found 10 (indentation)")
}
})
}
Loading