Skip to content

Commit

Permalink
housekeeping (#38)
Browse files Browse the repository at this point in the history
- rename CI action build to test
- move lint timeout to .golangci.yml
- add CI action to validate generated files
- add paramgen as tool dependency
- update dependency versions (why didn't dependabot update them?!)
- enable more linters
  • Loading branch information
lovromazgon authored May 17, 2024
1 parent e6ee1d7 commit 6273b4a
Show file tree
Hide file tree
Showing 14 changed files with 459 additions and 448 deletions.
1 change: 0 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
version: ${{ steps.golangci-lint-version.outputs.v }}
args: --timeout=2m
4 changes: 2 additions & 2 deletions .github/workflows/build.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: build
name: test

on:
push:
branches: [ main ]
pull_request:

jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/validate-generated-files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: validate-generated-files

on:
push:
branches: [ main ]
pull_request:

jobs:
validate-generated-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Check generated files
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make install-tools generate
git diff --exit-code --numstat
118 changes: 79 additions & 39 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,120 @@
run:
timeout: 5m

linters-settings:
gofmt:
simplify: false
govet:
check-shadowing: false
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to mention the specific linter being suppressed
gocyclo:
min-complexity: 20
goconst:
ignore-tests: true
wrapcheck:
ignoreSigs:
- .Errorf(
- errors.New(
- errors.Unwrap(
- errors.Join(
- .Wrap(
- .Wrapf(
- .WithMessage(
- .WithMessagef(
- .WithStack(
- (context.Context).Err()

issues:
exclude-rules:
- path: _test\.go
linters:
- dogsled
- gosec
- gocognit
- errcheck
- forcetypeassert
- funlen
- err113
- dupl
- maintidx

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
# - depguard
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
# - errorlint
# - exhaustive
# - exhaustivestruct
- errorlint
- exhaustive
- exportloopref
# - forbidigo
# - forcetypeassert
# - funlen
# - gochecknoinits
- forcetypeassert
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
# - cyclop # not interested in package complexities at the moment
# - godot
- godot
- err113
- gofmt
# - gofumpt
- gofumpt
- goheader
- goimports
# - revive # lots of unused parameters in the template, would be helpful for the user to keep them
# - gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
# - ifshort
- grouper
- importas
- ineffassign
# - importas
# - lll
# - misspell
- interfacebloat
# - ireturn # Doesn't have correct support for generic types https://github.com/butuzov/ireturn/issues/37
- loggercheck
- maintidx
- makezero
# - nakedret
# - nilerr
# - nilnil
# - nlreturn
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
# - paralleltest
- nosprintfhostport
- prealloc
- predeclared
# - rowserrcheck
- promlinter
- reassign
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
# - sqlclosecheck
# - tagliatelle
# - tenv
# - thelper
# - tparallel
- typecheck
- tenv
- testableexamples
- thelper
- unconvert
# - unparam
- unparam
- unused
# - wastedassign
- usestdlibvars
- wastedassign
- whitespace
# - wrapcheck
# - wsl
- wrapcheck
- zerologlint
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
.PHONY: build test test-integration generate install-paramgen install-tools golangci-lint-install

VERSION=$(shell git describe --tags --dirty --always)

.PHONY: build
build:
go build -ldflags "-X 'github.com/conduitio/conduit-connector-connectorname.version=${VERSION}'" -o conduit-connector-connectorname cmd/connector/main.go

.PHONY: test
test:
go test $(GOTEST_FLAGS) -race ./...

.PHONY: test-integration
test-integration:
# run required docker containers, execute integration tests, stop containers after tests
docker compose -f test/docker-compose.yml up -d
go test $(GOTEST_FLAGS) -v -race ./...; ret=$$?; \
docker compose -f test/docker-compose.yml down; \
exit $$ret

.PHONY: generate
generate:
go generate ./...

install-paramgen:
go install github.com/conduitio/conduit-connector-sdk/cmd/paramgen@latest

.PHONY: install-tools
install-tools:
@echo Installing tools from tools.go
@go list -e -f '{{ join .Imports "\n" }}' tools.go | xargs -tI % go install %
@go list -e -f '{{ join .Imports "\n" }}' tools.go | xargs -I % go list -f "%@{{.Module.Version}}" % | xargs -tI % go install %
@go mod tidy

.PHONY: lint
lint:
golangci-lint run -v
golangci-lint run
13 changes: 10 additions & 3 deletions README_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Conduit Connector for <resource>
[Conduit](https://conduit.io) for <resource>.

[Conduit](https://conduit.io) connector for <resource>.

## How to build?

Run `make build` to build the connector.

## Testing

Run `make test` to run all the unit tests. Run `make test-integration` to run the integration tests.

The Docker compose file at `test/docker-compose.yml` can be used to run the required resource locally.

## Source

A source connector pulls data from an external resource and pushes it to downstream resources via Conduit.

### Configuration
Expand All @@ -19,6 +23,7 @@ A source connector pulls data from an external resource and pushes it to downstr
| `source_config_param` | Description of `source_config_param`. | true | 1000 |

## Destination

A destination connector pushes data from upstream resources to an external resource via Conduit.

### Configuration
Expand All @@ -28,9 +33,11 @@ A destination connector pushes data from upstream resources to an external resou
| `destination_config_param` | Description of `destination_config_param`. | true | 1000 |

## Known Issues & Limitations
* Known issue A
* Limitation A

- Known issue A
- Limitation A

## Planned work

- [ ] Item A
- [ ] Item B
3 changes: 1 addition & 2 deletions cmd/connector/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package main

import (
sdk "github.com/conduitio/conduit-connector-sdk"

connectorname "github.com/conduitio/conduit-connector-connectorname"
sdk "github.com/conduitio/conduit-connector-sdk"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ func (d *Destination) Configure(ctx context.Context, cfg map[string]string) erro
return nil
}

func (d *Destination) Open(ctx context.Context) error {
func (d *Destination) Open(_ context.Context) error {
// Open is called after Configure to signal the plugin it can prepare to
// start writing records. If needed, the plugin should open connections in
// this function.
return nil
}

func (d *Destination) Write(ctx context.Context, records []sdk.Record) (int, error) {
func (d *Destination) Write(_ context.Context, _ []sdk.Record) (int, error) {
// Write writes len(r) records from r to the destination right away without
// caching. It should return the number of records written from r
// (0 <= n <= len(r)) and any error encountered that caused the write to
// stop early. Write must return a non-nil error if it returns n < len(r).
return 0, nil
}

func (d *Destination) Teardown(ctx context.Context) error {
func (d *Destination) Teardown(_ context.Context) error {
// Teardown signals to the plugin that all records were written and there
// will be no more calls to any other function. After Teardown returns, the
// plugin should be ready for a graceful shutdown.
Expand Down
Loading

0 comments on commit 6273b4a

Please sign in to comment.