Skip to content

Commit

Permalink
GH Actions CI Additions + Linter fixups (#242)
Browse files Browse the repository at this point in the history
* Add basic PR CI/CD checks.

This commit adds two manual Github Actions workflows, and one automated
workflow that runs both jobs on every PR commit.

The workflows include:

 - Automated linting with golangci-lint
 - Automated `go test ./...`

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>

* Linter ignores for dot imports.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>

* Fix linter issues with changes + ignores.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>

* Fix prealloc linter suggestions.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>

* Switch to `ubuntu-latest` + use GH Action for golangci-lint.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>

* Disable MacOS tests.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
  • Loading branch information
philipaconrad committed Sep 14, 2022
1 parent 372cb17 commit b3be96f
Show file tree
Hide file tree
Showing 48 changed files with 217 additions and 25 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/manual-go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Manual Go Test Run

on:
workflow_dispatch:

# When a new revision is pushed to a PR, cancel all in-progress CI runs for that
# PR. See https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
go-test:
name: Go Test (${{ matrix.os }})
runs-on: ${{ matrix.run }}
strategy:
fail-fast: false
matrix:
include:
- os: linux
run: ubuntu-latest
# MacOS is disabled due to the high cost multiplier on GH Actions.
#- os: darwin
# run: macos-latest
# Windows not allowed currently because of line-ending conversion issues.
#- os: windows
# run: windows-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- id: go_version
name: Read go version
run: echo "::set-output name=go_version::$(cat .go-version)"

- name: Install Go (${{ steps.go_version.outputs.go_version }})
uses: actions/setup-go@v3
with:
go-version: ${{ steps.go_version.outputs.go_version }}

- name: Unit Test Golang
run: go test ./...
timeout-minutes: 30
25 changes: 25 additions & 0 deletions .github/workflows/manual-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Manual Linter Run

on:
workflow_dispatch:

# When a new revision is pushed to a PR, cancel all in-progress CI runs for that
# PR. See https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
go-lint:
name: Go Lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Golang Style and Lint Check
uses: golangci/golangci-lint-action@v3
timeout-minutes: 30
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
56 changes: 56 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: PR Check

on: [pull_request]

# When a new revision is pushed to a PR, cancel all in-progress CI runs for that
# PR. See https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
go-lint:
name: Go Lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Golang Style and Lint Check
uses: golangci/golangci-lint-action@v3
timeout-minutes: 30
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

go-test:
name: Go Test (${{ matrix.os }})
runs-on: ${{ matrix.run }}
strategy:
fail-fast: false
matrix:
include:
- os: linux
run: ubuntu-latest
# MacOS is disabled due to the high cost multiplier on GH Actions.
#- os: darwin
# run: macos-latest
# Windows not allowed currently because of line-ending conversion issues.
#- os: windows
# run: windows-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- id: go_version
name: Read go version
run: echo "::set-output name=go_version::$(cat .go-version)"

- name: Install Go (${{ steps.go_version.outputs.go_version }})
uses: actions/setup-go@v3
with:
go-version: ${{ steps.go_version.outputs.go_version }}

- name: Unit Test Golang
run: go test ./...
timeout-minutes: 30
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.19.1
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ issues:
- errcheck
- gosec
- rowserrcheck
- makezero
- makezero
4 changes: 2 additions & 2 deletions ast/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (path *Path) UnmarshalJSON(b []byte) error {

type PathIndex int

func (_ PathIndex) isPathElement() {}
func (PathIndex) isPathElement() {}

type PathName string

func (_ PathName) isPathElement() {}
func (PathName) isPathElement() {}
4 changes: 2 additions & 2 deletions ast/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ type Argument struct {
Position *Position `dump:"-"`
}

func (f *Field) ArgumentMap(vars map[string]interface{}) map[string]interface{} {
return arg2map(f.Definition.Arguments, f.Arguments, vars)
func (s *Field) ArgumentMap(vars map[string]interface{}) map[string]interface{} {
return arg2map(s.Definition.Arguments, s.Arguments, vars)
}
4 changes: 2 additions & 2 deletions ast/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ func (t *Type) IsCompatible(other *Type) bool {
return true
}

func (v *Type) Dump() string {
return v.String()
func (t *Type) Dump() string {
return t.String()
}
1 change: 1 addition & 0 deletions formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Formatter interface {
FormatQueryDocument(doc *ast.QueryDocument)
}

//nolint:revive // Ignore "stuttering" name format.FormatterOption
type FormatterOption func(*formatter)

func WithIndent(indent string) FormatterOption {
Expand Down
2 changes: 2 additions & 0 deletions gqlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/vektah/gqlparser/v2/gqlerror"
"github.com/vektah/gqlparser/v2/parser"
"github.com/vektah/gqlparser/v2/validator"

// Blank import is used to load up the validator rules.
_ "github.com/vektah/gqlparser/v2/validator/rules"
)

Expand Down
12 changes: 7 additions & 5 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ func (s *Lexer) ReadToken() (token Token, err error) {
case '|':
return s.makeValueToken(Pipe, "")
case '#':
s.readComment()
if comment, err := s.readComment(); err != nil {
return comment, err
}
return s.ReadToken()

case '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z':
Expand Down Expand Up @@ -254,9 +256,9 @@ func (s *Lexer) readNumber() (Token, error) {

if float {
return s.makeToken(Float)
} else {
return s.makeToken(Int)
}
return s.makeToken(Int)

}

// acceptByte if it matches any of given bytes, returning true if it found anything
Expand Down Expand Up @@ -393,8 +395,8 @@ func (s *Lexer) readString() (Token, error) {
case 't':
buf.WriteByte('\t')
default:
s.end += 1
s.endRunes += 1
s.end++
s.endRunes++
return s.makeError("Invalid character escape sequence: \\%s.", string(escape))
}
s.end += 2
Expand Down
3 changes: 2 additions & 1 deletion lexer/lexer_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package lexer

import (
"github.com/vektah/gqlparser/v2/gqlerror"
"testing"

"github.com/vektah/gqlparser/v2/gqlerror"

"github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/parser/testrunner"
)
Expand Down
1 change: 1 addition & 0 deletions parser/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package parser
import (
"github.com/vektah/gqlparser/v2/lexer"

//nolint:revive
. "github.com/vektah/gqlparser/v2/ast"
)

Expand Down
5 changes: 3 additions & 2 deletions parser/query_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package parser

import (
"github.com/vektah/gqlparser/v2/gqlerror"
"testing"

"github.com/vektah/gqlparser/v2/gqlerror"

"github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/parser/testrunner"
)
Expand All @@ -19,7 +20,7 @@ func TestQueryDocument(t *testing.T) {
}
}
return testrunner.Spec{
AST: ast.Dump(doc),
AST: ast.Dump(doc),
}
})
}
1 change: 1 addition & 0 deletions parser/schema.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parser

import (
//nolint:revive
. "github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/lexer"
)
Expand Down
3 changes: 2 additions & 1 deletion parser/schema_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package parser

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/vektah/gqlparser/v2/gqlerror"
"testing"

"github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/parser/testrunner"
Expand Down
2 changes: 1 addition & 1 deletion validator/imported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestValidation(t *testing.T) {
d.pattern = regexp.MustCompile("^" + d.Rule + "$")
}

var schemas []*ast.Schema
var schemas = make([]*ast.Schema, 0, len(rawSchemas))
for i, schema := range rawSchemas {
schema, err := gqlparser.LoadSchema(&ast.Source{Input: schema, Name: fmt.Sprintf("schemas.yml[%d]", i)})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions validator/prelude.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package validator

import (
_ "embed"

"github.com/vektah/gqlparser/v2/ast"
)

Expand Down
9 changes: 6 additions & 3 deletions validator/rules/fields_on_correct_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"

"github.com/vektah/gqlparser/v2/ast"

//nolint:revive // Validator rules each use dot imports for convenience.
. "github.com/vektah/gqlparser/v2/validator"
)

Expand Down Expand Up @@ -41,11 +43,12 @@ func getSuggestedTypeNames(walker *Walker, parent *ast.Definition, name string)
return nil
}

var suggestedObjectTypes []string
possibleTypes := walker.Schema.GetPossibleTypes(parent)
var suggestedObjectTypes = make([]string, 0, len(possibleTypes))
var suggestedInterfaceTypes []string
interfaceUsageCount := map[string]int{}

for _, possibleType := range walker.Schema.GetPossibleTypes(parent) {
for _, possibleType := range possibleTypes {
field := possibleType.Fields.ForName(name)
if field == nil {
continue
Expand Down Expand Up @@ -85,7 +88,7 @@ func getSuggestedFieldNames(parent *ast.Definition, name string) []string {
return nil
}

var possibleFieldNames []string
var possibleFieldNames = make([]string, 0, len(parent.Fields))
for _, field := range parent.Fields {
possibleFieldNames = append(possibleFieldNames, field.Name)
}
Expand Down
2 changes: 2 additions & 0 deletions validator/rules/fragments_on_composite_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"

"github.com/vektah/gqlparser/v2/ast"

//nolint:revive // Validator rules each use dot imports for convenience.
. "github.com/vektah/gqlparser/v2/validator"
)

Expand Down
2 changes: 2 additions & 0 deletions validator/rules/known_argument_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package validator

import (
"github.com/vektah/gqlparser/v2/ast"

//nolint:revive // Validator rules each use dot imports for convenience.
. "github.com/vektah/gqlparser/v2/validator"
)

Expand Down
4 changes: 3 additions & 1 deletion validator/rules/known_directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package validator

import (
"github.com/vektah/gqlparser/v2/ast"

//nolint:revive // Validator rules each use dot imports for convenience.
. "github.com/vektah/gqlparser/v2/validator"
)

Expand All @@ -12,7 +14,7 @@ func init() {
Line int
Column int
}
var seen map[mayNotBeUsedDirective]bool = map[mayNotBeUsedDirective]bool{}
var seen = map[mayNotBeUsedDirective]bool{}
observers.OnDirective(func(walker *Walker, directive *ast.Directive) {
if directive.Definition == nil {
addError(
Expand Down
2 changes: 2 additions & 0 deletions validator/rules/known_fragment_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package validator

import (
"github.com/vektah/gqlparser/v2/ast"

//nolint:revive // Validator rules each use dot imports for convenience.
. "github.com/vektah/gqlparser/v2/validator"
)

Expand Down
2 changes: 2 additions & 0 deletions validator/rules/known_root_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"

"github.com/vektah/gqlparser/v2/ast"

//nolint:revive // Validator rules each use dot imports for convenience.
. "github.com/vektah/gqlparser/v2/validator"
)

Expand Down
2 changes: 2 additions & 0 deletions validator/rules/known_type_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package validator

import (
"github.com/vektah/gqlparser/v2/ast"

//nolint:revive // Validator rules each use dot imports for convenience.
. "github.com/vektah/gqlparser/v2/validator"
)

Expand Down
2 changes: 2 additions & 0 deletions validator/rules/lone_anonymous_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package validator

import (
"github.com/vektah/gqlparser/v2/ast"

//nolint:revive // Validator rules each use dot imports for convenience.
. "github.com/vektah/gqlparser/v2/validator"
)

Expand Down
Loading

0 comments on commit b3be96f

Please sign in to comment.