Skip to content

Commit

Permalink
Initial project setup
Browse files Browse the repository at this point in the history
  • Loading branch information
kmesiab committed Jan 17, 2024
1 parent fc94f4b commit e28d0d6
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@kmesiab
33 changes: 33 additions & 0 deletions .github/workflows/go-build.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
go-version: '1.21.4'
cache: true
check-latest: true

- name: 🧹 Tidy
run: go mod tidy

- name: 🤖 Build
run: go build ./...
52 changes: 52 additions & 0 deletions .github/workflows/go-lint.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
46 changes: 46 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
.idea
.DS_Store
77 changes: 77 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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')
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e28d0d6

Please sign in to comment.