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..c31e3d5 --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +# Copyright Splunk Inc. +# SPDX-License-Identifier: Apache-2.0 + +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 check-clean-work-tree + +.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: check-clean-work-tree +check-clean-work-tree: ## 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 + +