<commit_before>NAME ?= gitlab-ci-multi-runner
PACKAGE_NAME ?= $(NAME)
PACKAGE_CONFLICT ?= $(PACKAGE_NAME)-beta
REVISION := $(shell git rev-parse --short HEAD || echo unknown)
LAST_TAG := $(shell git describe --tags --abbrev=0)
COMMITS := $(shell echo `git log --oneline $(LAST_TAG)..HEAD | wc -l`)
VERSION := $(shell (cat VERSION || echo dev) | sed -e 's/^v//g')
BUILT := $(shell date +%Y-%m-%dT%H:%M:%S%:z)
ifneq ($(RELEASE),true)
    VERSION := $(shell echo $(VERSION)~beta.$(COMMITS).g$(REVISION))
endif
BRANCH := $(shell git show-ref | grep "$(REVISION)" | grep -v HEAD | awk '{print $$2}' | sed 's|refs/remotes/origin/||' | sed 's|refs/heads/||' | sort | head -n 1)
ITTERATION := $(shell date +%s)
PACKAGE_CLOUD ?= ayufan/gitlab-ci-multi-runner
PACKAGE_CLOUD_URL ?= https://packagecloud.io/
BUILD_PLATFORMS ?= -os '!netbsd' -os '!openbsd'
S3_UPLOAD_PATH ?= master
DEB_PLATFORMS ?= debian/wheezy debian/jessie debian/stretch debian/buster \
    ubuntu/precise ubuntu/trusty ubuntu/utopic ubuntu/vivid ubuntu/wily ubuntu/xenial \
    raspbian/wheezy raspbian/jessie raspbian/stretch raspbian/buster \
    linuxmint/petra linuxmint/qiana linuxmint/rebecca linuxmint/rafaela linuxmint/rosa
DEB_ARCHS ?= amd64 i386 armel armhf
RPM_PLATFORMS ?= el/6 el/7 \
    ol/6 ol/7 \
    fedora/20 fedora/21 fedora/22 fedora/23
RPM_ARCHS ?= x86_64 i686 arm armhf
COMMON_PACKAGE_NAMESPACE=$(shell go list ./common)
GO_LDFLAGS ?= -X $(COMMON_PACKAGE_NAMESPACE).NAME=$(PACKAGE_NAME) -X $(COMMON_PACKAGE_NAMESPACE).VERSION=$(VERSION) \
              -X $(COMMON_PACKAGE_NAMESPACE).REVISION=$(REVISION) -X $(COMMON_PACKAGE_NAMESPACE).BUILT=$(BUILT) \
              -X $(COMMON_PACKAGE_NAMESPACE).BRANCH=$(BRANCH)
GO_FILES ?= $(shell find . -name '*.go')
export GO15VENDOREXPERIMENT := 1
export CGO_ENABLED := 0

all: deps verify build

help:
	# Commands:
	# make all => deps verify build
	# make version - show information about current version
	#
	# Development commands:
	# make install - install the version suitable for your OS as gitlab-ci-multi-runner
	# make docker - build docker dependencies
	#
	# Testing commands:
	# make verify - run fmt, complexity, test and lint
	# make fmt - check source formatting
	# make test - run project tests
	# make lint - check project code style
	# make vet - examine code and report suspicious constructs
	# make complexity - check code complexity
	#
	# Deployment commands:
	# make deps - install all dependencies
	# make build - build project for all supported OSes
	# make package - package project using FPM
	# make packagecloud - send all packages to packagecloud
	# make packagecloud-yank - remove specific version from packagecloud

version: FORCE
	@echo Current version: $(VERSION)
	@echo Current iteration: $(ITTERATION)
	@echo Current revision: $(REVISION)
	@echo Current branch: $(BRANCH)
	@echo Build platforms: $(BUILD_PLATFORMS)
	@echo DEB platforms: $(DEB_PLATFORMS)
	@echo RPM platforms: $(RPM_PLATFORMS)
	bash -c 'echo TEST: ${GO15VENDOREXPERIMENT}'

verify: fmt vet lint complexity test

deps:
	# Installing dependencies...
	go get -u github.com/golang/lint/golint
	go get github.com/mitchellh/gox
	go get golang.org/x/tools/cmd/cover
	go get github.com/fzipp/gocyclo
	go get -u github.com/jteeuwen/go-bindata/...
	go install cmd/vet

out/docker/prebuilt-x86_64.tar.gz: $(GO_FILES)
	# Create directory
	mkdir -p out/docker

ifneq (, $(shell docker info))
	# Building gitlab-runner-helper
	gox -osarch=linux/amd64 \
		-ldflags "$(GO_LDFLAGS)" \
		-output="dockerfiles/build/gitlab-runner-helper" \
		./apps/gitlab-runner-helper

	# Build docker images
	docker build -t gitlab-runner-prebuilt-x86_64:$(REVISION) -f dockerfiles/build/Dockerfile.x86_64 dockerfiles/build
	-docker rm -f gitlab-runner-prebuilt-x86_64-$(REVISION)
	docker create --name=gitlab-runner-prebuilt-x86_64-$(REVISION) gitlab-runner-prebuilt-x86_64:$(REVISION) /bin/sh
	docker export -o out/docker/prebuilt-x86_64.tar gitlab-runner-prebuilt-x86_64-$(REVISION)
	docker rm -f gitlab-runner-prebuilt-x86_64-$(REVISION)
	gzip -f -9 out/docker/prebuilt-x86_64.tar
else
	$(warning =============================================)
	$(warning WARNING: downloading prebuilt docker images that will be embedded in gitlab-runner)
	$(warning WARNING: to use images compiled from your code install Docker Engine)
	$(warning WARNING: and remove out/docker/prebuilt-x86_64.tar.gz)
	$(warning =============================================)
	curl -o out/docker/prebuilt-x86_64.tar.gz \
		https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/master/docker/prebuilt-x86_64.tar.gz
endif

out/docker/prebuilt-arm.tar.gz: $(GO_FILES)
	# Create directory
	mkdir -p out/docker

ifneq (, $(shell docker info))
	# Building gitlab-runner-helper
	gox -osarch=linux/arm \
		-ldflags "$(GO_LDFLAGS)" \
		-output="dockerfiles/build/gitlab-runner-helper" \
		./apps/gitlab-runner-helper

	# Build docker images
	docker build -t gitlab-runner-prebuilt-arm:$(REVISION) -f dockerfiles/build/Dockerfile.arm dockerfiles/build
	-docker rm -f gitlab-runner-prebuilt-arm-$(REVISION)
	docker create --name=gitlab-runner-prebuilt-arm-$(REVISION) gitlab-runner-prebuilt-arm:$(REVISION) /bin/sh
	docker export -o out/docker/prebuilt-arm.tar gitlab-runner-prebuilt-arm-$(REVISION)
	docker rm -f gitlab-runner-prebuilt-arm-$(REVISION)
	gzip -f -9 out/docker/prebuilt-arm.tar
else
	$(warning =============================================)
	$(warning WARNING: downloading prebuilt docker images that will be embedded in gitlab-runner)
	$(warning WARNING: to use images compiled from your code install Docker Engine)
	$(warning WARNING: and remove out/docker/prebuilt-arm.tar.gz)
	$(warning =============================================)
	curl -o out/docker/prebuilt-arm.tar.gz \
		https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/master/docker/prebuilt-arm.tar.gz
endif

executors/docker/bindata.go: out/docker/prebuilt-x86_64.tar.gz out/docker/prebuilt-arm.tar.gz
	# Generating embedded data
	go-bindata \
		-pkg docker \
		-nocompress \
		-nomemcopy \
		-nometadata \
		-prefix out/docker/ \
		-o executors/docker/bindata.go \
		out/docker/prebuilt-x86_64.tar.gz \
		out/docker/prebuilt-arm.tar.gz

docker: executors/docker/bindata.go

build: executors/docker/bindata.go
	# Building $(NAME) in version $(VERSION) for $(BUILD_PLATFORMS)
	gox $(BUILD_PLATFORMS) \
		-ldflags "$(GO_LDFLAGS)" \
		-output="out/binaries/$(NAME)-{{.OS}}-{{.Arch}}"

build_simple:
	# Building $(NAME) in version $(VERSION) for current platform
	go build \
		-ldflags "$(GO_LDFLAGS)" \
		-o "out/binaries/$(NAME)"

build_current: executors/docker/bindata.go build_simple

fmt:
	# Checking project code formatting...
	@go fmt ./... | awk '{ print "Please run go fmt"; exit 1 }'

vet:
	# Checking for suspicious constructs...
	@go vet ./...

lint:
	# Checking project code style...
	@golint ./... | ( ! grep -v -e "be unexported" -e "don't use an underscore in package name" -e "ALL_CAPS" )

complexity:
	# Checking code complexity
	@gocyclo -over 9 $(shell find . -name '*.go' | grep -v \
	    -e "/Godeps" \
	    -e "/helpers/shell_escape.go" \
	    -e "/executors/parallels/" \
	    -e "/executors/virtualbox/")

test: executors/docker/bindata.go
	# Running tests...
	@go test ./... -cover

install: executors/docker/bindata.go
	go install --ldflags="$(GO_LDFLAGS)"

dockerfiles:
	make -C dockerfiles all

mocks: FORCE
	go get github.com/vektra/mockery/.../
	rm -rf mocks/
	mockery -dir=$(GOPATH)/src/github.com/ayufan/golang-kardianos-service -name=Interface
	mockery -dir=./common -name=Network
	mockery -dir=./helpers/docker -name=Client

test-docker:
	make test-docker-image IMAGE=centos:6 TYPE=rpm
	make test-docker-image IMAGE=centos:7 TYPE=rpm
	make test-docker-image IMAGE=debian:wheezy TYPE=deb
	make test-docker-image IMAGE=debian:jessie TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:precise TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:trusty TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:utopic TYPE=deb

test-docker-image:
	tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE)
	tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE) Y

build-and-deploy:<commit_msg>Update Makefile to exclude vendor/ from make verify<commit_after>NAME ?= gitlab-ci-multi-runner
PACKAGE_NAME ?= $(NAME)
PACKAGE_CONFLICT ?= $(PACKAGE_NAME)-beta
REVISION := $(shell git rev-parse --short HEAD || echo unknown)
LAST_TAG := $(shell git describe --tags --abbrev=0)
COMMITS := $(shell echo `git log --oneline $(LAST_TAG)..HEAD | wc -l`)
VERSION := $(shell (cat VERSION || echo dev) | sed -e 's/^v//g')
BUILT := $(shell date +%Y-%m-%dT%H:%M:%S%:z)
ifneq ($(RELEASE),true)
    VERSION := $(shell echo $(VERSION)~beta.$(COMMITS).g$(REVISION))
endif
BRANCH := $(shell git show-ref | grep "$(REVISION)" | grep -v HEAD | awk '{print $$2}' | sed 's|refs/remotes/origin/||' | sed 's|refs/heads/||' | sort | head -n 1)
ITTERATION := $(shell date +%s)
PACKAGE_CLOUD ?= ayufan/gitlab-ci-multi-runner
PACKAGE_CLOUD_URL ?= https://packagecloud.io/
BUILD_PLATFORMS ?= -os '!netbsd' -os '!openbsd'
S3_UPLOAD_PATH ?= master
DEB_PLATFORMS ?= debian/wheezy debian/jessie debian/stretch debian/buster \
    ubuntu/precise ubuntu/trusty ubuntu/utopic ubuntu/vivid ubuntu/wily ubuntu/xenial \
    raspbian/wheezy raspbian/jessie raspbian/stretch raspbian/buster \
    linuxmint/petra linuxmint/qiana linuxmint/rebecca linuxmint/rafaela linuxmint/rosa
DEB_ARCHS ?= amd64 i386 armel armhf
RPM_PLATFORMS ?= el/6 el/7 \
    ol/6 ol/7 \
    fedora/20 fedora/21 fedora/22 fedora/23
RPM_ARCHS ?= x86_64 i686 arm armhf
COMMON_PACKAGE_NAMESPACE=$(shell go list ./common)

# Packages in vendor/ are included in ./...
# https://github.com/golang/go/issues/11659
OUR_PACKAGES=$(shell go list ./... | grep -v '/vendor/')

GO_LDFLAGS ?= -X $(COMMON_PACKAGE_NAMESPACE).NAME=$(PACKAGE_NAME) -X $(COMMON_PACKAGE_NAMESPACE).VERSION=$(VERSION) \
              -X $(COMMON_PACKAGE_NAMESPACE).REVISION=$(REVISION) -X $(COMMON_PACKAGE_NAMESPACE).BUILT=$(BUILT) \
              -X $(COMMON_PACKAGE_NAMESPACE).BRANCH=$(BRANCH)
GO_FILES ?= $(shell find . -name '*.go')
export GO15VENDOREXPERIMENT := 1
export CGO_ENABLED := 0

all: deps verify build

help:
	# Commands:
	# make all => deps verify build
	# make version - show information about current version
	#
	# Development commands:
	# make install - install the version suitable for your OS as gitlab-ci-multi-runner
	# make docker - build docker dependencies
	#
	# Testing commands:
	# make verify - run fmt, complexity, test and lint
	# make fmt - check source formatting
	# make test - run project tests
	# make lint - check project code style
	# make vet - examine code and report suspicious constructs
	# make complexity - check code complexity
	#
	# Deployment commands:
	# make deps - install all dependencies
	# make build - build project for all supported OSes
	# make package - package project using FPM
	# make packagecloud - send all packages to packagecloud
	# make packagecloud-yank - remove specific version from packagecloud

version: FORCE
	@echo Current version: $(VERSION)
	@echo Current iteration: $(ITTERATION)
	@echo Current revision: $(REVISION)
	@echo Current branch: $(BRANCH)
	@echo Build platforms: $(BUILD_PLATFORMS)
	@echo DEB platforms: $(DEB_PLATFORMS)
	@echo RPM platforms: $(RPM_PLATFORMS)
	bash -c 'echo TEST: ${GO15VENDOREXPERIMENT}'

verify: fmt vet lint complexity test

deps:
	# Installing dependencies...
	go get -u github.com/golang/lint/golint
	go get github.com/mitchellh/gox
	go get golang.org/x/tools/cmd/cover
	go get github.com/fzipp/gocyclo
	go get -u github.com/jteeuwen/go-bindata/...
	go install cmd/vet

out/docker/prebuilt-x86_64.tar.gz: $(GO_FILES)
	# Create directory
	mkdir -p out/docker

ifneq (, $(shell docker info))
	# Building gitlab-runner-helper
	gox -osarch=linux/amd64 \
		-ldflags "$(GO_LDFLAGS)" \
		-output="dockerfiles/build/gitlab-runner-helper" \
		./apps/gitlab-runner-helper

	# Build docker images
	docker build -t gitlab-runner-prebuilt-x86_64:$(REVISION) -f dockerfiles/build/Dockerfile.x86_64 dockerfiles/build
	-docker rm -f gitlab-runner-prebuilt-x86_64-$(REVISION)
	docker create --name=gitlab-runner-prebuilt-x86_64-$(REVISION) gitlab-runner-prebuilt-x86_64:$(REVISION) /bin/sh
	docker export -o out/docker/prebuilt-x86_64.tar gitlab-runner-prebuilt-x86_64-$(REVISION)
	docker rm -f gitlab-runner-prebuilt-x86_64-$(REVISION)
	gzip -f -9 out/docker/prebuilt-x86_64.tar
else
	$(warning =============================================)
	$(warning WARNING: downloading prebuilt docker images that will be embedded in gitlab-runner)
	$(warning WARNING: to use images compiled from your code install Docker Engine)
	$(warning WARNING: and remove out/docker/prebuilt-x86_64.tar.gz)
	$(warning =============================================)
	curl -o out/docker/prebuilt-x86_64.tar.gz \
		https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/master/docker/prebuilt-x86_64.tar.gz
endif

out/docker/prebuilt-arm.tar.gz: $(GO_FILES)
	# Create directory
	mkdir -p out/docker

ifneq (, $(shell docker info))
	# Building gitlab-runner-helper
	gox -osarch=linux/arm \
		-ldflags "$(GO_LDFLAGS)" \
		-output="dockerfiles/build/gitlab-runner-helper" \
		./apps/gitlab-runner-helper

	# Build docker images
	docker build -t gitlab-runner-prebuilt-arm:$(REVISION) -f dockerfiles/build/Dockerfile.arm dockerfiles/build
	-docker rm -f gitlab-runner-prebuilt-arm-$(REVISION)
	docker create --name=gitlab-runner-prebuilt-arm-$(REVISION) gitlab-runner-prebuilt-arm:$(REVISION) /bin/sh
	docker export -o out/docker/prebuilt-arm.tar gitlab-runner-prebuilt-arm-$(REVISION)
	docker rm -f gitlab-runner-prebuilt-arm-$(REVISION)
	gzip -f -9 out/docker/prebuilt-arm.tar
else
	$(warning =============================================)
	$(warning WARNING: downloading prebuilt docker images that will be embedded in gitlab-runner)
	$(warning WARNING: to use images compiled from your code install Docker Engine)
	$(warning WARNING: and remove out/docker/prebuilt-arm.tar.gz)
	$(warning =============================================)
	curl -o out/docker/prebuilt-arm.tar.gz \
		https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/master/docker/prebuilt-arm.tar.gz
endif

executors/docker/bindata.go: out/docker/prebuilt-x86_64.tar.gz out/docker/prebuilt-arm.tar.gz
	# Generating embedded data
	go-bindata \
		-pkg docker \
		-nocompress \
		-nomemcopy \
		-nometadata \
		-prefix out/docker/ \
		-o executors/docker/bindata.go \
		out/docker/prebuilt-x86_64.tar.gz \
		out/docker/prebuilt-arm.tar.gz

docker: executors/docker/bindata.go

build: executors/docker/bindata.go
	# Building $(NAME) in version $(VERSION) for $(BUILD_PLATFORMS)
	gox $(BUILD_PLATFORMS) \
		-ldflags "$(GO_LDFLAGS)" \
		-output="out/binaries/$(NAME)-{{.OS}}-{{.Arch}}"

build_simple:
	# Building $(NAME) in version $(VERSION) for current platform
	go build \
		-ldflags "$(GO_LDFLAGS)" \
		-o "out/binaries/$(NAME)"

build_current: executors/docker/bindata.go build_simple

fmt:
	# Checking project code formatting...
	@go fmt $(OUR_PACKAGES) | awk '{ print "Please run go fmt"; exit 1 }'

vet:
	# Checking for suspicious constructs...
	@go vet $(OUR_PACKAGES)

lint:
	# Checking project code style...
	@golint ./... | ( ! grep -v -e "^vendor/" -e "be unexported" -e "don't use an underscore in package name" -e "ALL_CAPS" )

complexity:
	# Checking code complexity
	@gocyclo -over 9 $(shell find . -name '*.go' -not -path './vendor/*' | grep -v \
	    -e "/helpers/shell_escape.go" \
	    -e "/executors/parallels/" \
	    -e "/executors/virtualbox/")

test: executors/docker/bindata.go
	# Running tests...
	@go test $(OUR_PACKAGES) -cover

install: executors/docker/bindata.go
	go install --ldflags="$(GO_LDFLAGS)"

dockerfiles:
	make -C dockerfiles all

mocks: FORCE
	go get github.com/vektra/mockery/.../
	rm -rf mocks/
	mockery -dir=$(GOPATH)/src/github.com/ayufan/golang-kardianos-service -name=Interface
	mockery -dir=./common -name=Network
	mockery -dir=./helpers/docker -name=Client

test-docker:
	make test-docker-image IMAGE=centos:6 TYPE=rpm
	make test-docker-image IMAGE=centos:7 TYPE=rpm
	make test-docker-image IMAGE=debian:wheezy TYPE=deb
	make test-docker-image IMAGE=debian:jessie TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:precise TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:trusty TYPE=deb
	make test-docker-image IMAGE=ubuntu-upstart:utopic TYPE=deb

test-docker-image:
	tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE)
	tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE) Y

build-and-deploy:
{'fraction_non_alphanumeric': 0.15704415740462602, 'fraction_numerical': 0.013277260438570141, 'mean_word_length': 4.147186147186147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3531506', 'n_tokens_mistral': 6368, 'n_tokens_neox': 5902, 'n_words': 1399}