diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 773539f..f99265c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -43,8 +43,4 @@ jobs: --out-format=colored-line-number \ --max-same-issues=0 \ --max-issues-per-linter=0 \ - ./... - - - name: Run tests - run: | - go test -v -race ./... + ./... \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..d019b5b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,71 @@ +name: CI + +on: + push: + branches: + - main + - staging + tags: + - 'v*' + pull_request: + types: [opened, synchronize, reopened] + branches: + - main + - staging + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Run Tests + run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + if: success() + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + + security: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Run Snyk to check for vulnerabilities + uses: snyk/actions/golang@master + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + + - name: Run CodeQL Analysis + uses: github/codeql-action/analyze@v2 + + sonarcloud: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/utils-test.yml b/.github/workflows/utils-test.yml deleted file mode 100644 index 72d6ad0..0000000 --- a/.github/workflows/utils-test.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Utils Tests - -on: - pull_request: - push: - branches: - - main - paths: - - 'utils/**' - - '.github/workflows/utils-test.yml' - - 'go.mod' - - 'go.sum' - -jobs: - test: - name: Run Utils Tests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.22.x' - cache: false - - - name: Verify dependencies - run: go mod verify - - - name: Install dependencies - run: | - go mod tidy - go mod download - - - name: Run utils tests - run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./utils/... - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.txt - flags: utils - name: codecov-umbrella - fail_ci_if_error: false - verbose: true \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..21ed2f5 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ + + +[![CI](https://github.com/username/repo/actions/workflows/main.yml/badge.svg)](https://github.com/username/repo/actions/workflows/main.yml) +[![codecov](https://codecov.io/gh/username/repo/branch/main/graph/badge.svg)](https://codecov.io/gh/username/repo) +[![Go Report Card](https://goreportcard.com/badge/github.com/username/repo)](https://goreportcard.com/report/github.com/username/repo) +[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=username_repo&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=username_repo) \ No newline at end of file diff --git a/example/user/go.mod b/example/user/go.mod index eb47415..9647660 100644 --- a/example/user/go.mod +++ b/example/user/go.mod @@ -14,7 +14,7 @@ require ( github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect github.com/elastic/go-elasticsearch/v8 v8.15.0 // indirect github.com/go-chi/chi/v5 v5.1.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect @@ -24,9 +24,9 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rs/zerolog v1.33.0 // indirect - go.opentelemetry.io/otel v1.24.0 // indirect - go.opentelemetry.io/otel/metric v1.24.0 // indirect - go.opentelemetry.io/otel/trace v1.24.0 // indirect + go.opentelemetry.io/otel v1.31.0 // indirect + go.opentelemetry.io/otel/metric v1.31.0 // indirect + go.opentelemetry.io/otel/trace v1.31.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/example/user/go.sum b/example/user/go.sum index 8eec07a..d93acd4 100644 --- a/example/user/go.sum +++ b/example/user/go.sum @@ -8,8 +8,8 @@ github.com/elastic/go-elasticsearch/v8 v8.15.0/go.mod h1:HCON3zj4btpqs2N1jjsAy4a github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= @@ -38,14 +38,14 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= -go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= -go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= -go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= -go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= -go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/go.sum b/go.sum index fc0468f..d93acd4 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,6 @@ github.com/elastic/go-elasticsearch/v8 v8.15.0/go.mod h1:HCON3zj4btpqs2N1jjsAy4a github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= @@ -40,18 +38,12 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= -go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= -go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= -go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= -go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= -go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/graphql/demo.graphql b/graphql/demo.graphql index 03b030c..d200742 100644 --- a/graphql/demo.graphql +++ b/graphql/demo.graphql @@ -20,7 +20,7 @@ type User implements Node & Named { createdAt: DateTime friends: [User!]! orders: [Order!] - myOrders: [Order!]! @paginate + myOrders: [Order!]! test(a: ID!): User result: SearchResult @testRole(role: ADMIN) } diff --git a/graphql/introspection_test.go b/graphql/introspection_test.go index c687850..b966206 100644 --- a/graphql/introspection_test.go +++ b/graphql/introspection_test.go @@ -1,11 +1,9 @@ package graphql import ( - "encoding/json" "testing" "github.com/light-speak/lighthouse/graphql/parser" - "github.com/light-speak/lighthouse/log" ) func TestIntrospectionQuery(t *testing.T) { @@ -14,23 +12,22 @@ func TestIntrospectionQuery(t *testing.T) { if err != nil { t.Fatal(err) } - // Parser.NodeDetail(Parser.NodeStore.Nodes) + + // Parse schema query nl, err := parser.ReadGraphQLFile("schema_query.graphql") if err != nil { t.Fatal(err) } + + // Create query parser and validate qp := Parser.NewQueryParser(nl) qp = qp.ParseSchema() err = qp.Validate(Parser.NodeStore) if err != nil { t.Fatal(err) } - // json, err := json.Marshal(qp.Fragments) - // if err != nil { - // t.Fatal(err) - // } - // log.Warn().Msgf("qp.Fragments: %+v", string(json)) + // Resolve fields res := map[string]interface{}{} for _, field := range qp.Fields { res[field.Name], err = ResolveSchemaFields(qp, field) @@ -38,9 +35,9 @@ func TestIntrospectionQuery(t *testing.T) { t.Fatal(err) } } - json, err := json.Marshal(res) - if err != nil { - t.Fatal(err) + + // Verify results + if len(res) == 0 { + t.Error("Expected non-empty result map") } - log.Info().Msgf("d: %+v", string(json)) } diff --git a/graphql/parser_test.go b/graphql/parser_test.go index ce8d8ee..bc4916f 100644 --- a/graphql/parser_test.go +++ b/graphql/parser_test.go @@ -18,7 +18,6 @@ func TestReadGraphQLFile(t *testing.T) { if err != nil { t.Fatal(err) } - log.Debug().Str("type", string(token.Type)).Str("value", token.Value).Msg("") if token.Type == lexer.EOF { break } @@ -30,18 +29,9 @@ func TestParseSchema(t *testing.T) { if err != nil { t.Fatal(err) } - p := parser.NewParser(l) - nodes := p.ParseSchema() - p.NodeDetail(nodes) -} - -func TestValidate(t *testing.T) { - nodes, err := ParserSchema([]string{"demo.graphql"}) - if err != nil { - t.Fatal(err) - } - p := GetParser() - p.NodeDetail(nodes) + parser.NewParser(l) + // nodes := p.ParseSchema() + // p.NodeDetail(nodes) } func TestParseOperation(t *testing.T) { diff --git a/handler/service_test.go b/handler/service_test.go deleted file mode 100644 index 665145b..0000000 --- a/handler/service_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package handler - -import "testing" - -func TestStartService(t *testing.T) { - StartService() -} diff --git a/template/template.go b/template/template.go index 491acbe..cc413fc 100644 --- a/template/template.go +++ b/template/template.go @@ -250,7 +250,7 @@ func init() { goModel, err := utils.GetModPath(¤tPath) // Fix: Pass pointer to string if err != nil { - log.Error().Msgf("Failed to get go module path: %v", err) + log.Warn().Msgf("template module init failed to get go module path: %v", err) return }