diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..f0db899 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@kmesiab diff --git a/.github/workflows/go-build.yml b/.github/workflows/go-build.yml new file mode 100644 index 0000000..967a286 --- /dev/null +++ b/.github/workflows/go-build.yml @@ -0,0 +1,33 @@ +name: Build + +defaults: + run: + shell: bash + +on: + push: + branches: + - '**' + +jobs: + + build_go: + name: "๐Ÿ— Compile" + + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›’ Checkout Code + uses: actions/checkout@v3 + + - name: ๐Ÿš€ Set up Go + uses: actions/setup-go@v4.1.0 + with: + go-version: '1.21.4' + cache: true + check-latest: true + + - name: ๐Ÿงน Tidy + run: go mod tidy + + - name: ๐Ÿค– Build + run: go build ./... diff --git a/.github/workflows/go-lint.yml b/.github/workflows/go-lint.yml new file mode 100644 index 0000000..d8b31b7 --- /dev/null +++ b/.github/workflows/go-lint.yml @@ -0,0 +1,52 @@ +name: Lint + +defaults: + run: + shell: bash + +on: + push: + branches: + - '**' + +jobs: + + lint-markdown: + + name: "๐Ÿงน Markdown" + continue-on-error: true + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›’ Checkout Code + uses: actions/checkout@v3 + + - name: ๐Ÿ“ฆ Install Node.js and npm + uses: actions/setup-node@v3 + with: + node-version: '20.0.0' + + - name: ๐Ÿ“š Install markdownlint-cli + run: npm install -g markdownlint-cli + + - name: ๐Ÿ–Š๏ธ Run markdownlint + run: find . -name '*.md' -exec markdownlint {} + + + lint_go: + name: "๏ธโ€๏ธ๐Ÿ•ต๏ธ Golang" + + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ›’ Checkout Code + uses: actions/checkout@v3 + + - name: ๐Ÿš€ Set up Go + uses: actions/setup-go@v4.1.0 + with: + go-version: '1.21.4' + cache: true + check-latest: true + + - name: ๐Ÿ•ต๏ธโ€โ™‚๏ธ Run GolangCI-Lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml new file mode 100644 index 0000000..dd2a554 --- /dev/null +++ b/.github/workflows/go-test.yml @@ -0,0 +1,46 @@ +name: Test + +defaults: + run: + shell: bash + +on: + push: + branches: + - '**' + +jobs: + build: + name: ๐Ÿงช Unit Tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.21.4 + + - name: ๐Ÿ— Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y xorg-dev libgl1-mesa-dev + + - name: Set up gotestfmt + run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest + + # Run tests with nice formatting. Save the original log in /tmp/gotest.log + - name: ๐Ÿงช Execute Tests + run: | + set -euo pipefail + go test -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt + + # Upload the original go test log as an artifact for later review. + - name: Upload test log + uses: actions/upload-artifact@v2 + if: always() + with: + name: test-log + path: /tmp/gotest.log + if-no-files-found: error diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cfe994 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +.idea +.DS_Store diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f4579ed --- /dev/null +++ b/Makefile @@ -0,0 +1,77 @@ +# Phony Targets +.PHONY: all build test install-tools lint run run-debug invoke + +# Meta Targets +all: install-tools build test lint + +# Build Targets +build: go-mod-tidy go-build + +# Build and run the application +build-and-run: + @echo ">>>>> Starting app" + @go mod tidy -go=1.21 && go build -o cadre && ./cadre + +go-mod-tidy: + @echo "๐Ÿงน Running go mod tidy" + @go mod tidy -go=1.21 + +go-build: + @echo "๐Ÿ”จ Building Go binaries" + @go build -ldflags="-s -w" ./... + +# Test Targets +test: test-basic + +test-basic: + @echo "๐Ÿงช Running tests" + @go test -cover ./... + +test-verbose: + @echo "๐Ÿ“ Running tests with verbose output" + @go test -v -cover ./... + +test-race: + CGO_ENABLED=1 go test -race -cover ./... + +# Tooling +install-tools: + @echo "๐Ÿ› ๏ธ Installing tools" + @go install mvdan.cc/gofumpt@latest + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + +# Linting +lint: lint-golangci lint-fumpt lint-markdown + +lint-fumpt: + @echo "๐Ÿงน Running gofumpt linter" + @gofumpt -l -w . + +lint-golangci: + @echo "๐Ÿณ Running golangci linters" + @golangci-lint run + +lint-go: + @echo "๐Ÿณ Running Go linters in Docker" + @docker run -t --rm -v $$(pwd):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run -v \ + -E bodyclose \ + -E exportloopref \ + -E forcetypeassert \ + -E goconst \ + -E gocritic \ + -E misspell \ + -E noctx \ + -E nolintlint \ + -E prealloc \ + -E predeclared \ + -E reassign \ + -E sqlclosecheck \ + -E stylecheck \ + -E varnamelen \ + -E wastedassign \ + -E staticcheck + +lint-markdown: + @echo "๐Ÿ“š Running Markdown linters with npm" + @if [ -z $$(which markdownlint) ]; then npm install -g markdownlint-cli; fi + @markdownlint $$(find ./. -name '*.md') diff --git a/README.md b/README.md index 30e9a8a..462d9fe 100644 --- a/README.md +++ b/README.md @@ -1 +1,8 @@ -# cadre +# Cadre ๐Ÿ’ป + +![Golang](https://img.shields.io/badge/Go-00add8.svg?labelColor=171e21&style=for-the-badge&logo=go) + +![Build](https://github.com/kmesiab/cadre/actions/workflows/go-build.yml/badge.svg) +![Build](https://github.com/kmesiab/cadre/actions/workflows/go-lint.yml/badge.svg) +![Build](https://github.com/kmesiab/cadre/actions/workflows/go-test.yml/badge.svg) +[![Go Report Card](https://goreportcard.com/badge/github.com/kmesiab/cadre)](https://goreportcard.com/report/github.com/kmesiab/cadre)