Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH Actions CI Additions + Linter fixups #242

Merged
merged 6 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
42 changes: 42 additions & 0 deletions .github/workflows/manual-go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooooo! Ok, this is super fancy! I'm stealing this for use at my day job. Thanks!

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-22.04
- os: darwin
philipaconrad marked this conversation as resolved.
Show resolved Hide resolved
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
22 changes: 22 additions & 0 deletions .github/workflows/manual-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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-22.04
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Golang Style and Lint Check
run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run -v
timeout-minutes: 30
52 changes: 52 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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-22.04
philipaconrad marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Golang Style and Lint Check
run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run -v
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I wonder why you are choosing to run the docker image, rather than the golangci-lint GitHub action from the marketplace? Does the docker version also annotate the PR with inline comments the way the action marketplace golangci-lint does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit, I just copied that part of the workflow over wholesale from OPA's pull-request workflow, and lifted up the underlying shell command for the make check target (the Docker command you saw). 😅

I'll try out the Github action, and see if that works equally well. The less fiddly commands in those workflows, the less stuff that can break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the Github actions version works okay. I pinned it to latest on the linter version.

timeout-minutes: 30

go-test:
name: Go Test (${{ matrix.os }})
runs-on: ${{ matrix.run }}
strategy:
fail-fast: false
matrix:
include:
- os: linux
run: ubuntu-22.04
- os: darwin
philipaconrad marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 2 additions & 0 deletions validator/rules/no_fragment_cycles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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
Loading