Skip to content

Commit

Permalink
Migrate to GitHub actions (#177)
Browse files Browse the repository at this point in the history
* Bump to v2

* ci: migrate to github actions from circle-ci

* ci: gotestsum shuffle & race

* ci: replace deprecated linters

* fix: linting issues & disable some linters

* chore: remove circleci/config.yml

* configure revive lint
  • Loading branch information
phiHero authored Jul 22, 2024
1 parent 6136037 commit 8d55404
Show file tree
Hide file tree
Showing 69 changed files with 283 additions and 261 deletions.
73 changes: 0 additions & 73 deletions .circleci/config.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: golangci-lint

on:
push:
paths-ignore:
- '**/*.md'
pull_request:
paths-ignore:
- '**/*.md'

permissions:
# Required: allow read access to the content for analysis.
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
# Optional: Allow write access to checks to allow the action to annotate code in the PR.
checks: write

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
46 changes: 46 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test

on:
push:
paths-ignore:
- '**/*.md'
pull_request:
paths-ignore:
- '**/*.md'

jobs:
test:
runs-on: ubuntu-latest
services:
typesense:
image: typesense/typesense:26.0
ports:
- 8108:8108/tcp
volumes:
- /tmp/typesense-server-data:/data
env:
TYPESENSE_DATA_DIR: '/data'
TYPESENSE_API_KEY: 'test_key'
TYPESENSE_ENABLE_CORS: true
TYPESENSE_URL: 'http://localhost:8108'

steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Install dependencies
run: go mod download

- name: Build
run: go build -v ./...

- name: Run tests
env:
TYPESENSE_URL: 'http://localhost:8108'
TYPESENSE_API_KEY: 'test_key'
CGO_ENABLED: 1
run: go run gotest.tools/gotestsum@latest --format github-actions -- -tags=integration ./... -race -shuffle=on
24 changes: 19 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- gosec
- maligned
- misspell
- nestif
- prealloc
- unconvert
# - unconvert
- unparam
disable:
- structcheck
- revive

linters-settings:
# govet:
# enable:
# - fieldalignment
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming
- name: var-naming
severity: warning
exclude: [""]
arguments:
- ["ID"] # AllowList

run:
timeout: 3m
Expand All @@ -31,3 +41,7 @@ issues:
- linters:
- funlen
path: _test\.go
- linters:
- errcheck
path: _test\.go

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# typesense-go

[![Build Status](https://cloud.drone.io/api/badges/typesense/typesense-go/status.svg)](https://cloud.drone.io/typesense/typesense-go)
[![GoReportCard Status](https://goreportcard.com/badge/github.com/typesense/typesense-go)](https://goreportcard.com/report/github.com/typesense/typesense-go)
[![Go Reference](https://pkg.go.dev/badge/github.com/typesense/typesense-go.svg)](https://pkg.go.dev/github.com/typesense/typesense-go)
[![GoReportCard Status](https://goreportcard.com/badge/github.com/typesense/typesense-go/v2)](https://goreportcard.com/report/github.com/typesense/typesense-go/v2)
[![Go Reference](https://pkg.go.dev/badge/github.com/typesense/typesense-go/v2.svg)](https://pkg.go.dev/github.com/typesense/typesense-go/v2)
[![GitHub release](https://img.shields.io/github/v/release/typesense/typesense-go)](https://github.com/typesense/typesense-go/releases/latest)
[![Gitter](https://badges.gitter.im/typesense-go/community.svg)](https://gitter.im/typesense-go/community)

Expand All @@ -11,15 +11,15 @@ Go client for the Typesense API: https://github.com/typesense/typesense
## Installation

```
go get github.com/typesense/typesense-go
go get github.com/typesense/typesense-go/v2
```

## Usage

Import the the package into your code :

```go
import "github.com/typesense/typesense-go/typesense"
import "github.com/typesense/typesense-go/v2/typesense"
```

Create new client:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/typesense/typesense-go
module github.com/typesense/typesense-go/v2

go 1.18

Expand Down
2 changes: 1 addition & 1 deletion typesense/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package typesense
import (
"context"

"github.com/typesense/typesense-go/typesense/api"
"github.com/typesense/typesense-go/v2/typesense/api"
)

// AliasInterface is a type for Alias API operations
Expand Down
6 changes: 3 additions & 3 deletions typesense/alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"net/http"
"testing"

"go.uber.org/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/typesense/typesense-go/typesense/api"
"github.com/typesense/typesense-go/typesense/mocks"
"github.com/typesense/typesense-go/v2/typesense/api"
"github.com/typesense/typesense-go/v2/typesense/mocks"
"go.uber.org/mock/gomock"
)

func TestCollectionAliasRetrieve(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion typesense/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package typesense
import (
"context"

"github.com/typesense/typesense-go/typesense/api"
"github.com/typesense/typesense-go/v2/typesense/api"
)

// AliasesInterface is a type for Aliases API operations
Expand Down
8 changes: 4 additions & 4 deletions typesense/aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"net/http"
"testing"

"github.com/typesense/typesense-go/typesense/api/pointer"
"github.com/typesense/typesense-go/v2/typesense/api/pointer"

"go.uber.org/mock/gomock"
"github.com/jinzhu/copier"
"github.com/stretchr/testify/assert"
"github.com/typesense/typesense-go/typesense/api"
"github.com/typesense/typesense-go/typesense/mocks"
"github.com/typesense/typesense-go/v2/typesense/api"
"github.com/typesense/typesense-go/v2/typesense/mocks"
"go.uber.org/mock/gomock"
)

func createNewCollectionAlias(collectionName string, name string) *api.CollectionAlias {
Expand Down
2 changes: 1 addition & 1 deletion typesense/api/circuit/gobreaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestGoBreakerSettingsOptions(t *testing.T) {
return counts.Requests > 10 &&
(float64(counts.TotalFailures)/float64(counts.Requests)) > 0.4
}
onStateChange := func(name string, from gobreaker.State, to gobreaker.State) {}
onStateChange := func(_ string, _ gobreaker.State, _ gobreaker.State) {}
tests := []struct {
name string
options []GoBreakerOption
Expand Down
2 changes: 1 addition & 1 deletion typesense/api/circuit/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package circuit
import (
"net/http"

"github.com/typesense/typesense-go/typesense/api"
"github.com/typesense/typesense-go/v2/typesense/api"
)

type HTTPRequestDoer interface {
Expand Down
4 changes: 2 additions & 2 deletions typesense/api/circuit/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"net/http"
"testing"

"go.uber.org/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/typesense/typesense-go/typesense/api/circuit/mocks"
"github.com/typesense/typesense-go/v2/typesense/api/circuit/mocks"
"go.uber.org/mock/gomock"
)

func newHTTPRequest(t *testing.T) *http.Request {
Expand Down
4 changes: 2 additions & 2 deletions typesense/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"net/http"
)

const APIKeyHeader = "X-TYPESENSE-API-KEY"
const APIKeyHeader = "X-TYPESENSE-API-KEY" // #nosec G101

func WithAPIKey(apiKey string) ClientOption {
return func(c *Client) error {
c.RequestEditors = []RequestEditorFn{func(ctx context.Context, req *http.Request) error {
c.RequestEditors = []RequestEditorFn{func(_ context.Context, req *http.Request) error {
req.Header.Add(APIKeyHeader, apiKey)
return nil
}}
Expand Down
2 changes: 1 addition & 1 deletion typesense/api/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type MapKV struct {
}

func sortedSlice(params map[string]interface{}) []MapKV {
var kvs []MapKV
kvs := []MapKV{}

for k, v := range params {
kvs = append(kvs, MapKV{k, v})
Expand Down
Loading

0 comments on commit 8d55404

Please sign in to comment.