2021-02-22 17:27:13 +05:30
|
|
|
PREFIX=/usr/local
|
2021-10-27 15:23:28 +05:30
|
|
|
PKG := gitlab.com/gitlab-org/gitlab/workhorse
|
2021-02-22 17:27:13 +05:30
|
|
|
BUILD_DIR ?= $(CURDIR)
|
|
|
|
TARGET_DIR ?= $(BUILD_DIR)/_build
|
|
|
|
VERSION_STRING := $(shell git describe)
|
|
|
|
ifeq ($(strip $(VERSION_STRING)),)
|
|
|
|
VERSION_STRING := v$(shell cat VERSION)
|
|
|
|
endif
|
|
|
|
BUILD_TIME := $(shell date -u +%Y%m%d.%H%M%S)
|
|
|
|
GOBUILD := go build -ldflags "-X main.Version=$(VERSION_STRING) -X main.BuildTime=$(BUILD_TIME)"
|
|
|
|
EXE_ALL := gitlab-resize-image gitlab-zip-cat gitlab-zip-metadata gitlab-workhorse
|
|
|
|
INSTALL := install
|
|
|
|
BUILD_TAGS := tracer_static tracer_static_jaeger continuous_profiler_stackdriver
|
|
|
|
|
|
|
|
MINIMUM_SUPPORTED_GO_VERSION := 1.11
|
|
|
|
|
|
|
|
export GOBIN := $(TARGET_DIR)/bin
|
|
|
|
export PATH := $(GOBIN):$(PATH)
|
|
|
|
export GOPROXY ?= https://proxy.golang.org
|
|
|
|
export GO111MODULE=on
|
|
|
|
|
|
|
|
define message
|
|
|
|
@echo "### $(1)"
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
|
|
|
.NOTPARALLEL:
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: clean-build $(EXE_ALL)
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
.PHONY: gitlab-resize-image
|
2021-10-27 15:23:28 +05:30
|
|
|
gitlab-resize-image:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Building $@)
|
|
|
|
$(GOBUILD) -tags "$(BUILD_TAGS)" -o $(BUILD_DIR)/$@ $(PKG)/cmd/$@
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
.PHONY: gitlab-zip-cat
|
2021-10-27 15:23:28 +05:30
|
|
|
gitlab-zip-cat:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Building $@)
|
|
|
|
$(GOBUILD) -tags "$(BUILD_TAGS)" -o $(BUILD_DIR)/$@ $(PKG)/cmd/$@
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
.PHONY: gitlab-zip-metadata
|
2021-10-27 15:23:28 +05:30
|
|
|
gitlab-zip-metadata:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Building $@)
|
|
|
|
$(GOBUILD) -tags "$(BUILD_TAGS)" -o $(BUILD_DIR)/$@ $(PKG)/cmd/$@
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
.PHONY: gitlab-workhorse
|
2021-10-27 15:23:28 +05:30
|
|
|
gitlab-workhorse:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Building $@)
|
|
|
|
$(GOBUILD) -tags "$(BUILD_TAGS)" -o $(BUILD_DIR)/$@ $(PKG)
|
|
|
|
|
|
|
|
.PHONY: install
|
2021-10-27 15:23:28 +05:30
|
|
|
install: $(EXE_ALL)
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,$@)
|
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)/bin/
|
|
|
|
cd $(BUILD_DIR) && $(INSTALL) $(EXE_ALL) $(DESTDIR)$(PREFIX)/bin/
|
|
|
|
|
|
|
|
.PHONY: test
|
2021-10-27 15:23:28 +05:30
|
|
|
test: prepare-tests
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,$@)
|
|
|
|
@go test -tags "$(BUILD_TAGS)" ./...
|
|
|
|
@echo SUCCESS
|
|
|
|
|
|
|
|
.PHONY: clean
|
2021-10-27 15:23:28 +05:30
|
|
|
clean: clean-workhorse clean-build
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,$@)
|
|
|
|
rm -rf testdata/data testdata/scratch
|
|
|
|
|
|
|
|
.PHONY: clean-workhorse
|
|
|
|
clean-workhorse:
|
|
|
|
$(call message,$@)
|
|
|
|
rm -f $(EXE_ALL)
|
|
|
|
|
|
|
|
.PHONY: clean-build
|
|
|
|
clean-build:
|
|
|
|
$(call message,$@)
|
|
|
|
rm -rf $(TARGET_DIR)
|
|
|
|
|
|
|
|
.PHONY: prepare-tests
|
|
|
|
prepare-tests: testdata/data/group/test.git $(EXE_ALL)
|
|
|
|
prepare-tests: testdata/scratch
|
|
|
|
|
|
|
|
testdata/data/group/test.git:
|
|
|
|
$(call message,$@)
|
|
|
|
git clone --quiet --bare https://gitlab.com/gitlab-org/gitlab-test.git $@
|
|
|
|
|
|
|
|
testdata/scratch:
|
|
|
|
mkdir -p testdata/scratch
|
|
|
|
|
|
|
|
.PHONY: verify
|
|
|
|
verify: lint vet detect-context detect-assert check-formatting staticcheck deps-check
|
|
|
|
|
|
|
|
.PHONY: lint
|
2021-10-27 15:23:28 +05:30
|
|
|
lint:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Verify: $@)
|
|
|
|
go install golang.org/x/lint/golint
|
|
|
|
@_support/lint.sh ./...
|
|
|
|
|
|
|
|
.PHONY: vet
|
2021-10-27 15:23:28 +05:30
|
|
|
vet:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Verify: $@)
|
|
|
|
@go vet ./...
|
|
|
|
|
|
|
|
.PHONY: detect-context
|
2021-10-27 15:23:28 +05:30
|
|
|
detect-context:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Verify: $@)
|
|
|
|
_support/detect-context.sh
|
|
|
|
|
|
|
|
.PHONY: detect-assert
|
|
|
|
detect-assert:
|
|
|
|
$(call message,Verify: $@)
|
|
|
|
_support/detect-assert.sh
|
|
|
|
|
|
|
|
.PHONY: check-formatting
|
2021-10-27 15:23:28 +05:30
|
|
|
check-formatting: install-goimports
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Verify: $@)
|
2021-03-08 18:12:59 +05:30
|
|
|
@_support/fmt.sh check
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
# Megacheck will tailor some responses given a minimum Go version, so pass that through the CLI
|
|
|
|
# Additionally, megacheck will not return failure exit codes unless explicitly told to via the
|
|
|
|
# `-simple.exit-non-zero` `-unused.exit-non-zero` and `-staticcheck.exit-non-zero` flags
|
|
|
|
.PHONY: staticcheck
|
2021-10-27 15:23:28 +05:30
|
|
|
staticcheck:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,Verify: $@)
|
|
|
|
go install honnef.co/go/tools/cmd/staticcheck
|
|
|
|
@ $(GOBIN)/staticcheck -go $(MINIMUM_SUPPORTED_GO_VERSION) ./...
|
|
|
|
|
|
|
|
# In addition to fixing imports, goimports also formats your code in the same style as gofmt
|
|
|
|
# so it can be used as a replacement.
|
|
|
|
.PHONY: fmt
|
2021-10-27 15:23:28 +05:30
|
|
|
fmt: install-goimports
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,$@)
|
2021-03-08 18:12:59 +05:30
|
|
|
@_support/fmt.sh
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
.PHONY: goimports
|
2021-10-27 15:23:28 +05:30
|
|
|
install-goimports:
|
2021-02-22 17:27:13 +05:30
|
|
|
$(call message,$@)
|
|
|
|
go install golang.org/x/tools/cmd/goimports
|
|
|
|
|
|
|
|
.PHONY: deps-check
|
|
|
|
deps-check:
|
|
|
|
go mod tidy
|
|
|
|
@if git diff --quiet --exit-code -- go.mod go.sum; then \
|
|
|
|
echo "go.mod and go.sum are ok"; \
|
|
|
|
else \
|
|
|
|
echo ""; \
|
|
|
|
echo "go.mod and go.sum are modified, please commit them";\
|
|
|
|
exit 1; \
|
|
|
|
fi;
|