Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
grongor committed Aug 18, 2021
1 parent 546fd87 commit 9a64cf2
Show file tree
Hide file tree
Showing 20 changed files with 1,951 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
pull_request:

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.17'
- name: Run tests
run: make test

coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.17'
- name: Generate Code Coverage
run: make coverage
- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.cov

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
23 changes: 23 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release

on:
push:
tags:
- v*

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v2
- name: GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/bin

/coverage.cov
138 changes: 138 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
run:
modules-download-mode: readonly

linters:
enable:
- asciicheck
- bodyclose
- cyclop
- dupl
- durationcheck
- errorlint
- exhaustive
- exportloopref
- gci
- gochecknoglobals
- gochecknoinits
- gocognit # probably tune
- goconst
- gocritic # probably tune
- godot
- goerr113
- gofumpt
- gosec
- ifshort
- lll
- makezero
- misspell
- nakedret
- nilerr
- nlreturn
- nolintlint
# - paralleltest # @todo check later, maybe enable
- prealloc
- predeclared
- revive
- sqlclosecheck
- testpackage
- thelper
- unconvert
- wastedassign
- whitespace
- wsl

linters-settings:
goimports:
local-prefixes: gitlab.cdn77.eu

govet:
check-shadowing: false
enable-all: true
disable:
- fieldalignment # @todo fix later

revive:
ignore-generated-header: true
confidence: 0.8
error-code: 0
severity: error
rules:
- name: atomic
- name: bare-return
- name: blank-imports
- name: bool-literal-in-expr
- name: confusing-naming
- name: confusing-results
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: defer
- name: dot-imports
- name: duplicated-imports
- name: early-return
- name: empty-block
- name: empty-lines
- name: error-naming
- name: error-return
- name: error-strings
- name: flag-parameter
- name: get-return
- name: identical-branches
- name: if-return
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: modifies-parameter
- name: modifies-value-receiver
- name: nested-structs
- name: range
- name: range-val-address
- name: range-val-in-closure
- name: receiver-naming
- name: redefines-builtin-id
- name: string-of-int
- name: struct-tag
- name: superfluous-else
- name: time-naming
- name: unconditional-recursion
- name: unexported-naming
- name: unexported-naming
- name: unexported-return
- name: unnecessary-stmt
- name: unused-parameter
- name: unused-receiver
- name: useless-break
- name: var-declaration
- name: waitgroup-by-value

lll:
tab-width: 4

wsl:
allow-cuddle-declarations: true

issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
# ignore unchecked errors, missing Close(), code complexity, global variables, line lengths and code duplicity in tests
- path: _test\.go
linters: [ errcheck, bodyclose, cyclop, gocognit, gochecknoglobals, lll, dupl ]
# ignore control flags in tests
- path: _test\.go
text: "seems to be a control flag, avoid control coupling"
linters: [ revive ]
# ignore unchecked errors in defer statements
- source: "^\t+defer "
linters: [ errcheck ]
# ignore defer cuddle in tests
- path: _test\.go
text: only one cuddle assignment allowed before defer statement
linters: [ wsl ]
# ignore expressions after assignment in tests
- path: _test\.go
text: only cuddled expressions if assigning variable or using from line above
linters: [ wsl ]
# ignore goerr113 dynamic errors definition error...not sure how to approach this correctly now
- text: do not define dynamic errors, use wrapped static errors instead
linters: [ goerr113 ]
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
changelog:
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export BIN = ${PWD}/bin
export GOBIN = $(BIN)

.PHONY: check
check: lint test

.PHONY: lint
lint: $(BIN)/golangci-lint mocks
$(BIN)/golangci-lint run

.PHONY: fix
fix: $(BIN)/golangci-lint mocks
$(BIN)/golangci-lint run --fix

.PHONY: test
test: mocks
go test --timeout 5m $(GO_TEST_FLAGS) ./...
go test --timeout 5m $(GO_TEST_FLAGS) --race ./...
go test --timeout 5m $(GO_TEST_FLAGS) --count 100 ./...

mocks: $(BIN)/mockery $(shell find . -type f -name '*.go' -not -name '*_test.go')
$(BIN)/mockery --all --outpkg cmd_mocks
@touch mocks

.PHONY: coverage
coverage: $(BIN)/go-acc mocks
$(BIN)/go-acc --covermode set --output coverage.cov ./...

.PHONY: clean
clean:
rm -rf bin mocks coverage.cov

$(BIN)/golangci-lint:
curl --retry 5 -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh

$(BIN)/mockery:
mkdir -p $(BIN)
curl -sSfL https://api.github.com/repos/vektra/mockery/releases | jq -r 'first(.[] | select(.tag_name | test("^v2\\.8[.0-9]+$$"))) | .assets[] | select(.name | test("Linux_x86_64.tar.gz")) | .browser_download_url' \
| xargs curl -sSfL \
| tar -xz -C $(BIN) mockery
#curl -sSfL https://api.github.com/repos/vektra/mockery/releases | jq -r 'first(.[] | select(.tag_name | test("^v2[.0-9]+$$"))) | .assets[] | select(.name | test("Linux_x86_64.tar.gz")) | .browser_download_url' \
# | xargs curl -sSfL \
# | tar -xz -C $(BIN) mockery

$(BIN)/go-acc:
go install github.com/ory/go-acc@latest
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# cmd

![CI](https://github.com/grongor/cmd/workflows/CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/grongor/cmd/badge.svg)](https://coveralls.io/github/grongor/cmd)

todo
Loading

0 comments on commit 9a64cf2

Please sign in to comment.