chore: add husky and gh workflows

This commit is contained in:
Kevin Franklin Kim 2024-03-21 16:10:08 +01:00
parent 39cd0c422a
commit da832d3f52
No known key found for this signature in database
23 changed files with 154 additions and 8 deletions

15
.github/dependabot.yml vendored Normal file
View File

@ -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"

37
.github/workflows/release.yml vendored Normal file
View File

@ -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 }}

30
.github/workflows/test.yml vendored Normal file
View File

@ -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 ./...

15
.husky.yaml Normal file
View File

@ -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<type>\w+)(\((?P<scope>[\w/.-]+)\))?(?P<breaking>!)?:( +)?(?P<header>.+)'

3
.husky/applypatch-msg Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/commit-msg Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/fsmonitor-watchman Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/post-update Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-applypatch Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-commit Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-merge-commit Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-push Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-rebase Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-receive Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/prepare-commit-msg Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/push-to-checkout Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/sendemail-validate Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/update Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

View File

@ -3,6 +3,19 @@
# --- Targets ----------------------------------------------------------------- # --- 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 === ## === Tasks ===
.PHONY: doc .PHONY: doc

View File

@ -126,7 +126,6 @@ RunLoop:
for _, i := range waitPoolLoosers { for _, i := range waitPoolLoosers {
delete(waitPool, i) delete(waitPool, i)
} }
} }
c.chanDrainPool = nil c.chanDrainPool = nil
c.chanConnReturn = nil c.chanConnReturn = nil

View File

@ -83,7 +83,7 @@ func (t *SocketTransport) Call(ctx context.Context, route handler.Route, request
n, err := conn.Read(buf) n, err := conn.Read(buf)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
returnConn(err) 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 { if n == 0 {
break break

View File

@ -93,12 +93,10 @@ func NewHTTPCommand() *cobra.Command {
addOtelEnabledFlag(cmd, v) addOtelEnabledFlag(cmd, v)
addHealthzEnabledFlag(cmd, v) addHealthzEnabledFlag(cmd, v)
addPrometheusEnabledFlag(cmd, v) addPrometheusEnabledFlag(cmd, v)
// cmd.Flags().SetNormalizeFunc(normalizeFlag)
return cmd return cmd
} }
func init() { func init() {
rootCmd.AddCommand(NewHTTPCommand()) rootCmd.AddCommand(NewHTTPCommand())
} }

View File

@ -43,7 +43,6 @@ func NewSocket(l *zap.Logger, repo *repo.Repo) *Socket {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
func (h *Socket) Serve(conn net.Conn) { func (h *Socket) Serve(conn net.Conn) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
h.l.Error("panic in handle connection", zap.String("error", fmt.Sprint(r))) 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)) h.l.Debug("found json", zap.Int("length", jsonLength))
if jsonLength > 0 { if jsonLength > 0 {
var ( var (
// let us try to read some json // let us try to read some json
jsonBytes = make([]byte, jsonLength) 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) { func (h *Socket) executeRequest(r *repo.Repo, route Route, jsonBytes []byte, source string) (replyBytes []byte, err error) {
var ( var (
reply interface{} reply interface{}
apiErr error 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)) h.l.Error("could not read incoming json", zap.Error(jsonErr))
reply = responses.NewError(2, "could not read incoming json "+jsonErr.Error()) reply = responses.NewError(2, "could not read incoming json "+jsonErr.Error())
} else if apiErr != nil { } 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()) reply = responses.NewError(3, "internal error "+apiErr.Error())
} }