...

Text file src/github.com/chrismellard/docker-credential-acr-env/Makefile

Documentation: github.com/chrismellard/docker-credential-acr-env

     1# Make does not offer a recursive wildcard function, so here's one:
     2rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
     3
     4SHELL := /bin/bash
     5NAME := docker-credential-acr-env
     6BUILD_TARGET = build
     7MAIN_SRC_FILE=./main.go
     8GO := GO111MODULE=on go
     9GO_NOMOD :=GO111MODULE=off go
    10REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
    11ORG := chrismellard
    12ORG_REPO := $(ORG)/$(NAME)
    13RELEASE_ORG_REPO := $(ORG_REPO)
    14ROOT_PACKAGE := github.com/$(ORG_REPO)
    15GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
    16GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/,*.go)
    17
    18BRANCH     := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null  || echo 'unknown')
    19BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
    20CGO_ENABLED = 0
    21
    22REPORTS_DIR=$(BUILD_TARGET)/reports
    23
    24GOTEST := $(GO) test
    25
    26# set dev version unless VERSION is explicitly set via environment
    27VERSION ?= $(shell echo "$$(git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)' 2>/dev/null)-dev+$(REV)" | sed 's/^v//')
    28
    29# Build flags for setting build-specific configuration at build time - defaults to empty
    30#BUILD_TIME_CONFIG_FLAGS ?= ""
    31
    32# Full build flags used when building binaries. Not used for test compilation/execution.
    33BUILDFLAGS :=  -ldflags \
    34  " -X $(ROOT_PACKAGE)/pkg/cmd/version.Version=$(VERSION)\
    35		-X github.com/chrismellard/docker-credential-acr-env/pkg/cmd/version.Version=$(VERSION)\
    36		-X $(ROOT_PACKAGE)/pkg/cmd/version.Revision='$(REV)'\
    37		-X $(ROOT_PACKAGE)/pkg/cmd/version.Branch='$(BRANCH)'\
    38		-X $(ROOT_PACKAGE)/pkg/cmd/version.BuildDate='$(BUILD_DATE)'\
    39		-X $(ROOT_PACKAGE)/pkg/cmd/version.GoVersion='$(GO_VERSION)'\
    40		$(BUILD_TIME_CONFIG_FLAGS)"
    41
    42# Some tests expect default values for version.*, so just use the config package values there.
    43TEST_BUILDFLAGS :=  -ldflags "$(BUILD_TIME_CONFIG_FLAGS)"
    44
    45ifdef DEBUG
    46BUILDFLAGS := -gcflags "all=-N -l" $(BUILDFLAGS)
    47endif
    48
    49ifdef PARALLEL_BUILDS
    50BUILDFLAGS += -p $(PARALLEL_BUILDS)
    51GOTEST += -p $(PARALLEL_BUILDS)
    52else
    53# -p 4 seems to work well for people
    54GOTEST += -p 4
    55endif
    56
    57ifdef DISABLE_TEST_CACHING
    58GOTEST += -count=1
    59endif
    60
    61TEST_PACKAGE ?= ./...
    62COVER_OUT:=$(REPORTS_DIR)/cover.out
    63COVERFLAGS=-coverprofile=$(COVER_OUT) --covermode=count --coverpkg=./...
    64
    65.PHONY: list
    66list: ## List all make targets
    67	@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
    68
    69.PHONY: help
    70.DEFAULT_GOAL := help
    71help:
    72	@grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
    73
    74full: check ## Build and run the tests
    75check: build test ## Build and run the tests
    76get-test-deps: ## Install test dependencies
    77	$(GO_NOMOD) get github.com/axw/gocov/gocov
    78	$(GO_NOMOD) get -u gopkg.in/matm/v1/gocov-html
    79
    80print-version: ## Print version
    81	@echo $(VERSION)
    82
    83build: $(GO_DEPENDENCIES) clean ## Build binary for current OS
    84	go mod download
    85	CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/$(NAME) $(MAIN_SRC_FILE)
    86
    87build-all: $(GO_DEPENDENCIES) build make-reports-dir ## Build all files - runtime, all tests etc.
    88	CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) $(GOTEST) -run=nope -tags=integration -failfast -short ./... $(BUILDFLAGS)
    89
    90tidy-deps: ## Cleans up dependencies
    91	$(GO) mod tidy
    92	# mod tidy only takes compile dependencies into account, let's make sure we capture tooling dependencies as well
    93	@$(MAKE) install-generate-deps
    94
    95.PHONY: make-reports-dir
    96make-reports-dir:
    97	mkdir -p $(REPORTS_DIR)
    98
    99test: ## Run tests with the "unit" build tag
   100	CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) --tags=unit -failfast -short ./... $(TEST_BUILDFLAGS)
   101
   102test-coverage : make-reports-dir ## Run tests and coverage for all tests with the "unit" build tag
   103	CGO_ENABLED=$(CGO_ENABLED) $(GOTEST) --tags=unit $(COVERFLAGS) -failfast -short ./... $(TEST_BUILDFLAGS)
   104
   105test-report: make-reports-dir get-test-deps test-coverage ## Create the test report
   106	@gocov convert $(COVER_OUT) | gocov report
   107
   108test-report-html: make-reports-dir get-test-deps test-coverage ## Create the test report in HTML format
   109	@gocov convert $(COVER_OUT) | gocov-html > $(REPORTS_DIR)/cover.html && open $(REPORTS_DIR)/cover.html
   110
   111install: $(GO_DEPENDENCIES) ## Install the binary
   112	GOBIN=${GOPATH}/bin $(GO) install $(BUILDFLAGS) $(MAIN_SRC_FILE)
   113
   114linux: ## Build for Linux
   115	CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/linux/$(NAME) $(MAIN_SRC_FILE)
   116	chmod +x build/linux/$(NAME)
   117
   118arm: ## Build for ARM
   119	CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=arm $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/arm/$(NAME) $(MAIN_SRC_FILE)
   120	chmod +x build/arm/$(NAME)
   121
   122win: ## Build for Windows
   123	CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/win/$(NAME)-windows-amd64.exe $(MAIN_SRC_FILE)
   124
   125darwin: ## Build for OSX
   126	CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o build/darwin/$(NAME) $(MAIN_SRC_FILE)
   127	chmod +x build/darwin/$(NAME)
   128
   129.PHONY: release
   130release: clean linux test
   131
   132release-all: release linux win darwin
   133
   134promoter:
   135	cd promote && go build main.go
   136
   137.PHONY: goreleaser
   138goreleaser:
   139	step-go-releaser --organisation=$(ORG) --revision=$(REV) --branch=$(BRANCH) --build-date=$(BUILD_DATE) --go-version=$(GO_VERSION) --root-package=$(ROOT_PACKAGE) --version=$(VERSION) --timeout 200m
   140
   141.PHONY: clean
   142clean: ## Clean the generated artifacts
   143	rm -rf build release dist
   144
   145get-fmt-deps: ## Install test dependencies
   146	$(GO_NOMOD) get golang.org/x/tools/cmd/goimports
   147
   148.PHONY: fmt
   149fmt: importfmt ## Format the code
   150	$(eval FORMATTED = $(shell $(GO) fmt ./...))
   151	@if [ "$(FORMATTED)" == "" ]; \
   152      	then \
   153      	    echo "All Go files properly formatted"; \
   154      	else \
   155      		echo "Fixed formatting for: $(FORMATTED)"; \
   156      	fi
   157
   158.PHONY: importfmt
   159importfmt: get-fmt-deps
   160	@echo "Formatting the imports..."
   161	goimports -w $(GO_DEPENDENCIES)
   162
   163.PHONY: lint
   164lint: ## Lint the code
   165	./hack/gofmt.sh
   166	./hack/linter.sh
   167	./hack/generate.sh
   168
   169.PHONY: all
   170all: fmt build test lint generate-refdocs
   171
   172install-refdocs:
   173	$(GO) get github.com/jenkins-x/gen-crd-api-reference-docs
   174
   175generate-refdocs: install-refdocs
   176	gen-crd-api-reference-docs -config "hack/configdocs/config.json" \
   177	-template-dir hack/configdocs/templates \
   178    -api-dir "./pkg/apis/gitops/v1alpha1" \
   179    -out-file docs/config.md
   180
   181bin/docs:
   182	go build $(LDFLAGS) -v -o bin/docs cmd/docs/*.go
   183
   184.PHONY: docs
   185docs: bin/docs generate-refdocs ## update docs
   186	@echo "Generating docs"
   187	@./bin/docs --target=./docs/cmd
   188	@./bin/docs --target=./docs/man/man1 --kind=man
   189	@rm -f ./bin/docs

View as plain text