Skip to content

Commit

Permalink
Merge branch 'main' into fix/allow-events-yaml-unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 authored Apr 12, 2024
2 parents ff4eeb9 + c5cba4e commit c83df11
Show file tree
Hide file tree
Showing 28 changed files with 115 additions and 66 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ jobs:
# Check that go fmt ./... produces a zero diff; clean up any changes afterwards.
go fmt ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code)
# Check that go fix ./... produces a zero diff; clean up any changes afterwards.
go fix ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code)
#
# Renable this after https://github.com/golang/go/commit/7fd62ba821b1044e8e4077df052b0a1232672d57
# has been released.
# go fix ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code)
92 changes: 52 additions & 40 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ linters-settings:
lines: 160
statements: 70

# https://github.com/daixiang0/gci
# ensure import order is consistent
# gci write --custom-order -s standard -s default -s blank -s dot -s "prefix(github.com/go-vela)" .
gci:
custom-order: true
sections:
- standard
- default
- blank
- dot
- prefix(github.com/go-vela)

# https://github.com/denis-tingaikin/go-header
goheader:
template: |-
Expand Down Expand Up @@ -60,45 +72,45 @@ linters:

# enable a specific set of linters to run
enable:
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- contextcheck # check the function whether use a non-inherited context
- deadcode # finds unused code
- dupl # code clone detection
- errcheck # checks for unchecked errors
- errorlint # find misuses of errors
- exportloopref # check for exported loop vars
- funlen # detects long functions
- goconst # finds repeated strings that could be replaced by a constant
- gocyclo # computes and checks the cyclomatic complexity of functions
- godot # checks if comments end in a period
- gofmt # checks whether code was gofmt-ed
- goheader # checks is file header matches to pattern
- goimports # fixes imports and formats code in same style as gofmt
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects code for security problems
- gosimple # linter that specializes in simplifying a code
- govet # reports suspicious constructs, ex. Printf calls whose arguments don't align with the format string
- ineffassign # detects when assignments to existing variables aren't used
- makezero # finds slice declarations with non-zero initial length
- misspell # finds commonly misspelled English words in comments
- nakedret # finds naked returns in functions greater than a specified function length
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- noctx # noctx finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
- revive # linter for go
- staticcheck # applies static analysis checks, go vet on steroids
- structcheck # finds unused struct fields
- stylecheck # replacement for golint
- tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- typecheck # parses and type-checks go code, like the front-end of a go compiler
- unconvert # remove unnecessary type conversions
- unparam # reports unused function parameters
- unused # checks for unused constants, variables, functions and types
- varcheck # finds unused global variables and constants
- whitespace # detects leading and trailing whitespace
- wsl # forces code to use empty lines
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- contextcheck # check the function whether use a non-inherited context
- deadcode # finds unused code
- dupl # code clone detection
- errcheck # checks for unchecked errors
- errorlint # find misuses of errors
- exportloopref # check for exported loop vars
- funlen # detects long functions
- gci # consistent import ordering
- goconst # finds repeated strings that could be replaced by a constant
- gocyclo # computes and checks the cyclomatic complexity of functions
- godot # checks if comments end in a period
- gofmt # checks whether code was gofmt-ed
- goheader # checks is file header matches to pattern
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects code for security problems
- gosimple # linter that specializes in simplifying a code
- govet # reports suspicious constructs, ex. Printf calls whose arguments don't align with the format string
- ineffassign # detects when assignments to existing variables aren't used
- makezero # finds slice declarations with non-zero initial length
- misspell # finds commonly misspelled English words in comments
- nakedret # finds naked returns in functions greater than a specified function length
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- noctx # noctx finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
- revive # linter for go
- staticcheck # applies static analysis checks, go vet on steroids
- structcheck # finds unused struct fields
- stylecheck # replacement for golint
- tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- typecheck # parses and type-checks go code, like the front-end of a go compiler
- unconvert # remove unnecessary type conversions
- unparam # reports unused function parameters
- unused # checks for unused constants, variables, functions and types
- varcheck # finds unused global variables and constants
- whitespace # detects leading and trailing whitespace
- wsl # forces code to use empty lines

# static list of linters we know golangci can run but we've
# chosen to leave disabled for now
Expand All @@ -112,13 +124,13 @@ linters:
# - exhaustivestruct - style preference
# - forbidigo - unused
# - forcetypeassert - unused
# - gci - use goimports
# - gochecknoinits - unused
# - gochecknoglobals - global variables allowed
# - gocognit - unused complexity metric
# - gocritic - style preference
# - godox - to be used in the future
# - goerr113 - to be used in the future
# - goimports - use gci
# - golint - archived, replaced with revive
# - gofumpt - use gofmt
# - gomnd - get too many false-positives
Expand Down
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,24 @@ schema:
@go get github.com/alecthomas/jsonschema
@go get github.com/iancoleman/orderedmap
@go run cmd/schema/main.go > schema.json

# The `lint` target is intended to lint the
# Go source code with golangci-lint.
#
# Usage: `make lint`
.PHONY: lint
lint:
@echo
@echo "### Linting Go Code"
@golangci-lint run ./...

# The `lintfix` target is intended to lint the
# Go source code with golangci-lint and apply
# any fixes that can be automatically applied.
#
# Usage: `make lintfix`
.PHONY: lintfix
lintfix:
@echo
@echo "### Fixing Go code with linter"
@golangci-lint run ./... --fix
3 changes: 2 additions & 1 deletion database/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"errors"
"fmt"

"github.com/lib/pq"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/raw"
"github.com/lib/pq"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions database/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"database/sql"
"testing"

"github.com/go-vela/types/library"
"github.com/go-vela/types/raw"
"github.com/google/go-cmp/cmp"
"github.com/lib/pq"

"github.com/go-vela/types/library"
"github.com/go-vela/types/raw"
)

func TestDatabase_Deployment_Nullify(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"encoding/base64"
"errors"

"github.com/lib/pq"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/lib/pq"
)

var (
Expand Down
1 change: 1 addition & 0 deletions database/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"

"github.com/adhocore/gronx"

"github.com/go-vela/types/library"
)

Expand Down
4 changes: 2 additions & 2 deletions database/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"errors"
"strings"

"github.com/lib/pq"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"

"github.com/lib/pq"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion database/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"errors"
"regexp"

"github.com/lib/pq"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/lib/pq"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion database/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"database/sql"
"errors"

"github.com/lib/pq"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/lib/pq"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/go-vela/types

go 1.21
go 1.21.9

require (
github.com/adhocore/gronx v1.8.1
Expand Down
3 changes: 1 addition & 2 deletions library/actions/pull.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
//
//nolint:dupl // similar code to push.go

package actions

import "github.com/go-vela/types/constants"
Expand Down
3 changes: 1 addition & 2 deletions library/actions/push.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
//
//nolint:dupl // similar code to comment.go

package actions

import "github.com/go-vela/types/constants"
Expand Down
3 changes: 2 additions & 1 deletion library/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"testing"
"time"

"github.com/go-vela/types/raw"
"github.com/google/go-cmp/cmp"

"github.com/go-vela/types/raw"
)

func TestLibrary_Build_Duration(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion library/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"reflect"
"testing"

"github.com/google/go-cmp/cmp"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library/actions"
"github.com/google/go-cmp/cmp"
)

func TestLibrary_Events_Getters(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions library/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,6 @@ func (r *Repo) SetApproveBuild(v string) {
}

// String implements the Stringer interface for the Repo type.
//
//nolint:dupl // ignore duplicate with test func
func (r *Repo) String() string {
return fmt.Sprintf(`{
Active: %t,
Expand Down
3 changes: 2 additions & 1 deletion library/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"reflect"
"testing"

"github.com/go-vela/types/constants"
"github.com/google/go-cmp/cmp"

"github.com/go-vela/types/constants"
)

func TestLibrary_Repo_Environment(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion library/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library/actions"
"github.com/go-vela/types/pipeline"
"github.com/google/go-cmp/cmp"
)

func TestLibrary_Secret_Sanitize(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions yaml/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/buildkite/yaml"

"github.com/go-vela/types/library"
"github.com/go-vela/types/raw"
)
Expand Down
1 change: 1 addition & 0 deletions yaml/ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/buildkite/yaml"

"github.com/go-vela/types/pipeline"
)

Expand Down
1 change: 1 addition & 0 deletions yaml/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/buildkite/yaml"

"github.com/go-vela/types/pipeline"
)

Expand Down
1 change: 1 addition & 0 deletions yaml/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/buildkite/yaml"

"github.com/go-vela/types/pipeline"
"github.com/go-vela/types/raw"
)
Expand Down
4 changes: 2 additions & 2 deletions yaml/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package yaml
import (
"fmt"

"github.com/buildkite/yaml"

"github.com/go-vela/types/pipeline"
"github.com/go-vela/types/raw"

"github.com/buildkite/yaml"
)

type (
Expand Down
4 changes: 2 additions & 2 deletions yaml/stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"reflect"
"testing"

"github.com/go-vela/types/pipeline"

"github.com/buildkite/yaml"

"github.com/go-vela/types/pipeline"
)

func TestYaml_StageSlice_ToPipeline(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions yaml/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"reflect"
"testing"

"github.com/buildkite/yaml"

"github.com/go-vela/types/pipeline"
"github.com/go-vela/types/raw"

"github.com/buildkite/yaml"
)

func TestYaml_StepSlice_ToPipeline(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions yaml/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/buildkite/yaml"

"github.com/go-vela/types/library"
)

Expand Down
Loading

0 comments on commit c83df11

Please sign in to comment.