Skip to content

Commit

Permalink
Adding linter and github workflows (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucifercr07 authored Sep 27, 2024
1 parent 7fec0f0 commit a4209ae
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/full-test-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: playground-mono-test-suite
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.23.x"
- name: Install dependencies
run: go get .
- name: Build
run: make build
- name: Run Unit tests
run: make unittest
# - name: Run Integration tests
# run: make test
24 changes: 24 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: linter
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

permissions:
contents: read
pull-requests: read

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.60.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.vscode/
.env
./playground-mono
142 changes: 142 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
run:
concurrency: 8

timeout: 5m

issues-exit-code: 1

tests: false

modules-download-mode: readonly

allow-parallel-runners: false

go: "" # keep this empty to use the Go version from the go.mod file.

linters:
fast: false # set to true runs only fast linters.

disable-all: true

enable:
- bodyclose
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- revive
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

linters-settings:
dupl:
threshold: 200

funlen:
lines: 200
statements: 200

goconst:
min-len: 2
min-occurrences: 2

gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10

gocyclo:
min-complexity: 30

lll:
tab-width: 2
line-length: 200

misspell:
locale: US

nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- nestingReduce

revive:
# see https://github.com/mgechev/revive#available-rules for details.
ignore-generated-header: true
severity: error
confidence: 0.8
rules:
- name: indent-error-flow
- name: errorf
- name: unexported-return
- name: error-naming
- name: error-return
- name: empty-lines
- name: empty-block
- name: context-as-argument
- name: if-return
- name: superfluous-else

staticcheck:
checks: ["all"]

output:
print-issued-lines: false

print-linter-name: true

uniq-by-line: false

sort-results: true

issues:
max-issues-per-linter: 0

max-same-issues: 0

new: false

fix: true

exclude-dirs:
- .github
- .hooks
- .vscode

exclude-files:
- README.md
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
- id: golangci-lint
- id: go-mod-tidy
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.PHONY: build test build-docker run test-one

build:
CGO_ENABLED=0 GOOS=linux go build -o ./playground-mono

format:
go fmt ./...

run:
go run main.go

# TODO: Uncomment once integration-tests are added
#test:
# go test -v -count=1 -p=1 ./integration_tests/...
#
#test-one:
# go test -v -race -count=1 --run $(TEST_FUNC) ./integration_tests/...

unittest:
go test -race -count=1 ./internal/...

unittest-one:
go test -v -race -count=1 --run $(TEST_FUNC) ./internal/...

GOLANGCI_LINT_VERSION := 1.60.1

lint: check-golangci-lint
golangci-lint run ./...

check-golangci-lint:
@if ! command -v golangci-lint > /dev/null || ! golangci-lint version | grep -q "$(GOLANGCI_LINT_VERSION)"; then \
echo "Required golangci-lint version $(GOLANGCI_LINT_VERSION) not found."; \
echo "Please install golangci-lint version $(GOLANGCI_LINT_VERSION) with the following command:"; \
echo "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.60.1"; \
exit 1; \
fi
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,28 @@ This repository hosts backend service implementation of the Playground.

## How to contribute

The Code Contribution Guidelines are published at [CONTRIBUTING.md](CONTRIBUTING.md); please read them before you start making any changes. This would allow us to have a consistent standard of coding practices and developer experience.
The code contribution guidelines are published at [CONTRIBUTING.md](CONTRIBUTING.md); please read them before you start making any changes. This would allow us to have a consistent standard of coding practices and developer experience.

Contributors can join the [Discord Server](https://discord.gg/6r8uXWtXh7) for quick collaboration.

### Setting up this repository from source for development and contributions

To run playground-mono for local development or running from source, you will need

1. [Golang](https://go.dev/)
2. Any of the below supported platform environment:
1. [Linux based environment](https://en.wikipedia.org/wiki/Comparison_of_Linux_distributions)
2. [OSX (Darwin) based environment](https://en.wikipedia.org/wiki/MacOS)
3. WSL under Windows
3. Install GoLangCI
```
$ sudo su
$ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /bin v1.60.1
```

Steps to clone and run:
```
$ git clone https://github.com/dicedb/playground-mono
$ cd playground-mono
$ go run main.go
```
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"log"
"net/http"
"sync"
Expand Down Expand Up @@ -32,7 +33,7 @@ func (s *HTTPServer) Run(ctx context.Context) error {
go func() {
defer wg.Done()
log.Printf("Starting server at %s\n", s.httpServer.Addr)
if err := s.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
if err := s.httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("HTTP server error: %v", err)
}
}()
Expand All @@ -56,6 +57,6 @@ func main() {

// run the Http Server
if err := httpServer.Run(ctx); err != nil {
log.Fatalf("Server failed: %v", err)
log.Printf("Server failed: %v\n", err)
}
}
Binary file added playground-mono
Binary file not shown.

0 comments on commit a4209ae

Please sign in to comment.