-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: Makefile and other general improvements (#74)
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
- Loading branch information
1 parent
c960930
commit 8fbb1e3
Showing
5 changed files
with
108 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,46 @@ | ||
# Binaries for programs and plugins | ||
/bin | ||
/tools/bin | ||
|
||
# Other IDE files | ||
.idea | ||
|
||
# Created by https://www.toptal.com/developers/gitignore/api/go,vim | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=go,vim | ||
|
||
### Go ### | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
bin | ||
testbin | ||
|
||
# Test binary, build with `go test -c` | ||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Kubernetes Generated files - skip generated files, except for vendored files | ||
### Vim ### | ||
# Swap | ||
[._]*.s[a-v][a-z] | ||
!*.svg # comment out if you don't need vector files | ||
[._]*.sw[a-p] | ||
[._]s[a-rt-v][a-z] | ||
[._]ss[a-gi-z] | ||
[._]sw[a-p] | ||
|
||
!vendor/**/zz_generated.* | ||
# Session | ||
Session.vim | ||
Sessionx.vim | ||
|
||
# editor and IDE paraphernalia | ||
.idea | ||
*.swp | ||
*.swo | ||
# Temporary | ||
.netrwhist | ||
*~ | ||
# Auto-generated tag files | ||
tags | ||
# Persistent undo | ||
[._]*.un~ | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/go,vim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,57 @@ | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= quay.io/joelanford/helm-operator | ||
|
||
SHELL=/bin/bash | ||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
# GO_BUILD_ARGS should be set when running 'go build' or 'go install'. | ||
VERSION_PKG = "$(shell go list -m)/internal/version" | ||
SCAFFOLD_VERSION = $(shell git describe --abbrev=0) | ||
GIT_VERSION = $(shell git describe --dirty --tags --always) | ||
GIT_COMMIT = $(shell git rev-parse HEAD) | ||
BUILD_DIR = $(PWD)/bin | ||
GO_BUILD_ARGS = \ | ||
-gcflags "all=-trimpath=$(shell dirname $(shell pwd))" \ | ||
-asmflags "all=-trimpath=$(shell dirname $(shell pwd))" \ | ||
-ldflags " \ | ||
-s \ | ||
-w \ | ||
-X '$(VERSION_PKG).ScaffoldVersion=$(SCAFFOLD_VERSION)' \ | ||
-X '$(VERSION_PKG).GitVersion=$(GIT_VERSION)' \ | ||
-X '$(VERSION_PKG).GitCommit=$(GIT_COMMIT)' \ | ||
" \ | ||
|
||
# Always use Go modules | ||
export GO111MODULE = on | ||
|
||
# Setup project-local paths and build settings | ||
SHELL=/bin/bash | ||
TOOLS_DIR=$(PWD)/tools | ||
TOOLS_BIN_DIR=$(TOOLS_DIR)/bin | ||
SCRIPTS_DIR=$(TOOLS_DIR)/scripts | ||
export PATH := $(BUILD_DIR):$(TOOLS_BIN_DIR):$(SCRIPTS_DIR):$(PATH) | ||
|
||
.PHONY: all | ||
all: test lint build | ||
|
||
# Run tests | ||
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin | ||
test: fmt vet | ||
mkdir -p ${ENVTEST_ASSETS_DIR} | ||
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh | ||
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test -race -covermode atomic -coverprofile cover.out ./... | ||
.PHONY: test | ||
export KUBEBUILDER_ASSETS := $(TOOLS_BIN_DIR) | ||
CR_VERSION=$(shell go list -m sigs.k8s.io/controller-runtime | cut -d" " -f2 | sed 's/^v//') | ||
test: | ||
fetch envtest $(CR_VERSION) && go test -race -covermode atomic -coverprofile cover.out ./... | ||
|
||
# Build manager binary | ||
build: fmt vet | ||
CGO_ENABLED=0 go build $(GO_BUILD_ARGS) -o bin/helm-operator main.go | ||
|
||
# Run go fmt against code | ||
fmt: | ||
.PHONY: build | ||
build: | ||
CGO_ENABLED=0 mkdir -p $(BUILD_DIR) && go build $(GO_BUILD_ARGS) -o $(BUILD_DIR) ./ | ||
|
||
# Run go fmt and go mod tidy, and check for clean git tree | ||
.PHONY: fix | ||
fix: | ||
go mod tidy | ||
go fmt ./... | ||
git diff --exit-code | ||
|
||
# Run go vet against code | ||
vet: | ||
go vet ./... | ||
|
||
lint: golangci-lint | ||
$(GOLANGCI_LINT) run | ||
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes | ||
$(GOLANGCI_LINT) run --fix | ||
# Run various checks against code | ||
.PHONY: lint | ||
lint: | ||
fetch golangci-lint 1.35.2 && golangci-lint run | ||
|
||
# find or download controller-gen | ||
# download controller-gen if necessary | ||
golangci-lint: | ||
ifeq (, $(shell which golangci-lint)) | ||
@{ \ | ||
set -e ;\ | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.27.0 ;\ | ||
} | ||
GOLANGCI_LINT=$(shell go env GOPATH)/bin/golangci-lint | ||
else | ||
GOLANGCI_LINT=$(shell which golangci-lint) | ||
endif | ||
.PHONY: clean | ||
clean: | ||
rm -rf $(TOOLS_BIN_DIR) $(BUILD_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
ROOT="$(git rev-parse --show-toplevel)" | ||
DEST="${ROOT}/tools/bin" | ||
|
||
fetch() { | ||
local tool=$1; shift | ||
local ver=$1; shift | ||
|
||
local ver_cmd="" | ||
local fetch_cmd="" | ||
case "$tool" in | ||
"golangci-lint") | ||
ver_cmd="${DEST}/golangci-lint --version 2>/dev/null | cut -d\" \" -f4" | ||
fetch_cmd="curl -sSfL \"https://raw.githubusercontent.com/golangci/golangci-lint/v${ver}/install.sh\" | sh -s -- -b \"${DEST}\" \"v${ver}\"" | ||
;; | ||
"goreleaser") | ||
ver_cmd="${DEST}/goreleaser --version 2>/dev/null | grep version | cut -d' ' -f3" | ||
fetch_cmd="curl -sSfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- -b \"${DEST}\" -d \"v${ver}\"" | ||
;; | ||
"envtest") | ||
ver_cmd="cat ${DEST}/.envtest_version 2>/dev/null" | ||
fetch_cmd="(test -f ${DEST}/setup-envtest.sh || curl -sSLo ${DEST}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v${ver}/hack/setup-envtest.sh) && (source ${DEST}/setup-envtest.sh; fetch_envtest_tools ${DEST}/../) && echo ${ver} > ${DEST}/.envtest_version" | ||
;; | ||
*) | ||
echo "unknown tool $tool" | ||
return 1 | ||
;; | ||
esac | ||
|
||
if [[ "${ver}" != "$(eval ${ver_cmd})" ]]; then | ||
echo "${tool} missing or not version '${ver}', downloading..." | ||
mkdir -p ${DEST} | ||
eval ${fetch_cmd} | ||
fi | ||
} | ||
|
||
fetch $@ |