From 7066632a5c5fb5b3954925af6b7e8438ee7b017e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Tue, 16 Apr 2024 14:12:57 +0200 Subject: [PATCH] Add Makefile --- .github/workflows/ci.yml | 10 +++++++++ Makefile | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b57c1d..cec3e0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,16 @@ jobs: with: fail: true + make: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4.1.2 + - uses: actions/setup-go@v5.0.0 + with: + go-version: '1.22' + check-latest: true + - run: make ci + compatibility-test: strategy: matrix: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3151259 --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +GO = go + +SHELL := /bin/bash +.DEFAULT_GOAL := precommit + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +define print-target + @printf "Executing target: \033[36m$@\033[0m\n" +endef + +.PHONY: precommit +precommit: ## build pipeline +precommit: mod gen test + +.PHONY: ci +ci: ## CI build pipeline +ci: precommit diff + +.PHONY: mod +mod: ## go mod tidy + $(call print-target) + $(GO) mod tidy + +.PHONY: gen +gen: ## go generate + $(call print-target) + $(GO) generate ./... + +.PHONY: test +test: ## go test + $(call print-target) + $(GO) test -race -covermode=atomic -coverprofile=coverage.out -coverpkg=./... ./... + +.PHONY: diff +diff: ## git diff + $(call print-target) + if ! git diff --quiet; then \ + echo; \ + echo 'Working tree is not clean, did you forget to run "make precommit"?'; \ + echo; \ + git status; \ + exit 1; \ + fi