From da832d3f524ee5610c913a362907176a7e8efd7e Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Thu, 21 Mar 2024 16:10:08 +0100 Subject: [PATCH] chore: add husky and gh workflows --- .github/dependabot.yml | 15 ++++++++++++++ .github/workflows/release.yml | 37 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 30 ++++++++++++++++++++++++++++ .husky.yaml | 15 ++++++++++++++ .husky/applypatch-msg | 3 +++ .husky/commit-msg | 3 +++ .husky/fsmonitor-watchman | 3 +++ .husky/post-update | 3 +++ .husky/pre-applypatch | 3 +++ .husky/pre-commit | 3 +++ .husky/pre-merge-commit | 3 +++ .husky/pre-push | 3 +++ .husky/pre-rebase | 3 +++ .husky/pre-receive | 3 +++ .husky/prepare-commit-msg | 3 +++ .husky/push-to-checkout | 3 +++ .husky/sendemail-validate | 3 +++ .husky/update | 3 +++ Makefile | 13 ++++++++++++ client/connectionpool.go | 1 - client/sockettransport.go | 2 +- cmd/http.go | 2 -- pkg/handler/socket.go | 5 +---- 23 files changed, 154 insertions(+), 8 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 .husky.yaml create mode 100755 .husky/applypatch-msg create mode 100755 .husky/commit-msg create mode 100755 .husky/fsmonitor-watchman create mode 100755 .husky/post-update create mode 100755 .husky/pre-applypatch create mode 100755 .husky/pre-commit create mode 100755 .husky/pre-merge-commit create mode 100755 .husky/pre-push create mode 100755 .husky/pre-rebase create mode 100755 .husky/pre-receive create mode 100755 .husky/prepare-commit-msg create mode 100755 .husky/push-to-checkout create mode 100755 .husky/sendemail-validate create mode 100755 .husky/update diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..1ba1f3b --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..297e3e0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release Tag + +on: + push: + tags: + - v*.*.* + workflow_dispatch: + +env: + GOFLAGS: -mod=readonly + GOPROXY: https://proxy.golang.org + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v5 + with: + check-latest: true + go-version-file: go.mod + + - id: app_token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.TOKEN_APP_ID }} + private_key: ${{ secrets.TOKEN_APP_PRIVATE_KEY }} + + - uses: goreleaser/goreleaser-action@v5 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ steps.app_token.outputs.token }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..999e8b1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: checks + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + merge_group: + branches: [ main ] + workflow_dispatch: + +env: + GOFLAGS: -mod=readonly + GOPROXY: https://proxy.golang.org + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + check-latest: true + go-version-file: 'go.mod' + + - uses: golangci/golangci-lint-action@v4 + + - name: Run tests + run: go test -v ./... diff --git a/.husky.yaml b/.husky.yaml new file mode 100644 index 0000000..2bbd935 --- /dev/null +++ b/.husky.yaml @@ -0,0 +1,15 @@ +hooks: + pre-commit: + - golangci-lint run --fast + - husky lint-staged + commit-msg: + # only execute if not in a merge + - if [[ -z $(git rev-parse -q --verify MERGE_HEAD) ]]; then husky lint-commit; fi + +lint-staged: + '*.go': + - goimports -l -w + +lint-commit: + types: '^(feat|fix|build|chore|docs|perf|refactor|revert|style|test|wip)$' + header: '^(?P\w+)(\((?P[\w/.-]+)\))?(?P!)?:( +)?(?P
.+)' diff --git a/.husky/applypatch-msg b/.husky/applypatch-msg new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/applypatch-msg @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/fsmonitor-watchman b/.husky/fsmonitor-watchman new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/fsmonitor-watchman @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/post-update b/.husky/post-update new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/post-update @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/pre-applypatch b/.husky/pre-applypatch new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/pre-applypatch @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/pre-merge-commit b/.husky/pre-merge-commit new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/pre-merge-commit @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/pre-rebase b/.husky/pre-rebase new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/pre-rebase @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/pre-receive b/.husky/pre-receive new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/pre-receive @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/prepare-commit-msg @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/push-to-checkout b/.husky/push-to-checkout new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/push-to-checkout @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/sendemail-validate b/.husky/sendemail-validate new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/sendemail-validate @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/.husky/update b/.husky/update new file mode 100755 index 0000000..32d0649 --- /dev/null +++ b/.husky/update @@ -0,0 +1,3 @@ +#!/bin/sh + +husky hook $(basename "$0") $* diff --git a/Makefile b/Makefile index dbfe0ac..386949f 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,19 @@ # --- Targets ----------------------------------------------------------------- +# This allows us to accept extra arguments +%: .husky + @: + +.PHONY: .husky +# Configure git hooks for husky +.husky: + @if ! command -v husky &> /dev/null; then \ + echo "ERROR: missing executeable 'husky', please run:"; \ + echo "\n$ go install github.com/go-courier/husky/cmd/husky@latest\n"; \ + fi + @git config core.hooksPath .husky + ## === Tasks === .PHONY: doc diff --git a/client/connectionpool.go b/client/connectionpool.go index e3c98b3..eb9616b 100644 --- a/client/connectionpool.go +++ b/client/connectionpool.go @@ -126,7 +126,6 @@ RunLoop: for _, i := range waitPoolLoosers { delete(waitPool, i) } - } c.chanDrainPool = nil c.chanConnReturn = nil diff --git a/client/sockettransport.go b/client/sockettransport.go index 667abf5..3533ae3 100644 --- a/client/sockettransport.go +++ b/client/sockettransport.go @@ -83,7 +83,7 @@ func (t *SocketTransport) Call(ctx context.Context, route handler.Route, request n, err := conn.Read(buf) if err != nil && err != io.EOF { returnConn(err) - return fmt.Errorf("an error occured while reading the response: %q", err) + return fmt.Errorf("an error occurred while reading the response: %q", err) } if n == 0 { break diff --git a/cmd/http.go b/cmd/http.go index 93c3a06..ef82e81 100644 --- a/cmd/http.go +++ b/cmd/http.go @@ -93,12 +93,10 @@ func NewHTTPCommand() *cobra.Command { addOtelEnabledFlag(cmd, v) addHealthzEnabledFlag(cmd, v) addPrometheusEnabledFlag(cmd, v) - // cmd.Flags().SetNormalizeFunc(normalizeFlag) return cmd } func init() { rootCmd.AddCommand(NewHTTPCommand()) - } diff --git a/pkg/handler/socket.go b/pkg/handler/socket.go index 6649bff..56c8a6b 100644 --- a/pkg/handler/socket.go +++ b/pkg/handler/socket.go @@ -43,7 +43,6 @@ func NewSocket(l *zap.Logger, repo *repo.Repo) *Socket { // ------------------------------------------------------------------------------------------------ func (h *Socket) Serve(conn net.Conn) { - defer func() { if r := recover(); r != nil { h.l.Error("panic in handle connection", zap.String("error", fmt.Sprint(r))) @@ -87,7 +86,6 @@ func (h *Socket) Serve(conn net.Conn) { } h.l.Debug("found json", zap.Int("length", jsonLength)) if jsonLength > 0 { - var ( // let us try to read some json jsonBytes = make([]byte, jsonLength) @@ -200,7 +198,6 @@ func (h *Socket) handleRequest(r *repo.Repo, route Route, jsonBytes []byte, sour } func (h *Socket) executeRequest(r *repo.Repo, route Route, jsonBytes []byte, source string) (replyBytes []byte, err error) { - var ( reply interface{} apiErr error @@ -249,7 +246,7 @@ func (h *Socket) executeRequest(r *repo.Repo, route Route, jsonBytes []byte, sou h.l.Error("could not read incoming json", zap.Error(jsonErr)) reply = responses.NewError(2, "could not read incoming json "+jsonErr.Error()) } else if apiErr != nil { - h.l.Error("an API error occured", zap.Error(apiErr)) + h.l.Error("an API error occurred", zap.Error(apiErr)) reply = responses.NewError(3, "internal error "+apiErr.Error()) }