SHELL = /bin/bash -euo pipefail PWD = $(shell pwd) export PATH := $(PWD)/bin:$(PATH) # constants GOLANGCI_VERSION = 2.8.0 all: download build ## Initializes all tools and files all/ci: ado-git-setup all out: @mkdir -pv "$(@)" build: out ## do nothing .PHONY: build/% build/%: out ## do nothing download: @go mod download fmt: @go fmt ./... GOLANGCI_LINT = bin/golangci-lint-$(GOLANGCI_VERSION) $(GOLANGCI_LINT): curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b bin v$(GOLANGCI_VERSION) @mv bin/golangci-lint "$(@)" lint: fmt $(GOLANGCI_LINT) download ## Lints all code with golangci-lint @$(GOLANGCI_LINT) run lint/fix: fmt $(GOLANGCI_LINT) download ## Fixes automatically fixable things like imports for the defined lint rules @$(GOLANGCI_LINT) run --fix lint/reports: fmt $(GOLANGCI_LINT) download ## Fixes automatically fixable things like imports for the defined lint rules @$(GOLANGCI_LINT) run ./... --output.checkstyle.path stdout | awk '!/0 issues./' > out/lint.xml test-clean: @go clean -testcache tidy: @go mod tidy test: @go test ./... coverage: out/report.json ## Displays coverage per func on cli go tool cover -func=out/cover.out html-coverage: out/report.json ## Displays the coverage results in the browser go tool cover -html=out/cover.out test-reports: out/report.json .PHONY: out/report.json out/report.json: out go test -v $$(go list ./... | grep -v '/tests') -tags=unit -coverprofile=out/cover.out -json | tee "$(@)" clean: @rm -rf bin out .PHONY: ado-git-setup ado-git-setup: # Add "dev.azure.com/schwarzit" to GOPRIVATE if not present @priv="$$(go env GOPRIVATE)"; \ [[ "$$priv" =~ '(^|,)dev\.azure\.com(/|,|$)' ]] || go env -w "GOPRIVATE=$${priv:+$$priv,}dev.azure.com/schwarzit" # Configure HTTPS (with PAT) or SSH access to Go import paths @if [[ -n "$${ADO_PAT:+x}" ]]; then \ git config --global "url.https://schwarzit:$${ADO_PAT}@dev.azure.com/schwarzit/.insteadof" 'https://dev.azure.com/schwarzit/'; \ else \ git config --global 'url.git@ssh.dev.azure.com:v3/schwarzit.insteadOf' 'https://dev.azure.com/schwarzit'; \ fi help: @echo 'Usage: make ... ' @echo '' @echo 'Available targets are:' @echo '' @grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @echo ''