gitlab.com/jfprevost/gitlab-runner-notlscheck@v11.11.4+incompatible/Makefile (about)

     1  NAME ?= gitlab-runner
     2  PACKAGE_NAME ?= $(NAME)
     3  export VERSION := $(shell ./ci/version)
     4  REVISION := $(shell git rev-parse --short=8 HEAD || echo unknown)
     5  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)
     6  BUILT := $(shell date -u +%Y-%m-%dT%H:%M:%S%z)
     7  export TESTFLAGS ?= -cover
     8  
     9  LATEST_STABLE_TAG := $(shell git -c versionsort.prereleaseSuffix="-rc" -c versionsort.prereleaseSuffix="-RC" tag -l "v*.*.*" --sort=-v:refname | awk '!/rc/' | head -n 1)
    10  export IS_LATEST :=
    11  ifeq ($(shell git describe --exact-match --match $(LATEST_STABLE_TAG) >/dev/null 2>&1; echo $$?), 0)
    12  export IS_LATEST := true
    13  endif
    14  
    15  PACKAGE_CLOUD ?= ayufan/gitlab-ci-multi-runner
    16  PACKAGE_CLOUD_URL ?= https://packagecloud.io/
    17  BUILD_PLATFORMS ?= -os '!netbsd' -os '!openbsd'
    18  S3_UPLOAD_PATH ?= master
    19  
    20  # Keep in sync with docs/install/linux-repository.md
    21  DEB_PLATFORMS ?= debian/wheezy debian/jessie debian/stretch debian/buster \
    22      ubuntu/trusty ubuntu/xenial ubuntu/artful ubuntu/bionic \
    23      raspbian/wheezy raspbian/jessie raspbian/stretch raspbian/buster \
    24      linuxmint/qiana linuxmint/rebecca linuxmint/rafaela linuxmint/rosa linuxmint/sarah linuxmint/serena linuxmint/sonya
    25  DEB_ARCHS ?= amd64 i386 armel armhf
    26  RPM_PLATFORMS ?= el/6 el/7 \
    27      ol/6 ol/7 \
    28      fedora/26 fedora/27 fedora/28 fedora/29
    29  RPM_ARCHS ?= x86_64 i686 arm armhf
    30  
    31  PKG = gitlab.com/gitlab-org/$(PACKAGE_NAME)
    32  COMMON_PACKAGE_NAMESPACE=$(PKG)/common
    33  
    34  BUILD_DIR := $(CURDIR)
    35  TARGET_DIR := $(BUILD_DIR)/out
    36  
    37  ORIGINAL_GOPATH = $(shell echo $$GOPATH)
    38  LOCAL_GOPATH := $(CURDIR)/.gopath
    39  GOPATH_SETUP := $(LOCAL_GOPATH)/.ok
    40  GOPATH_BIN := $(LOCAL_GOPATH)/bin
    41  PKG_BUILD_DIR := $(LOCAL_GOPATH)/src/$(PKG)
    42  
    43  export GOPATH = $(LOCAL_GOPATH)
    44  export PATH := $(GOPATH_BIN):$(PATH)
    45  
    46  # Packages in vendor/ are included in ./...
    47  # https://github.com/golang/go/issues/11659
    48  export OUR_PACKAGES ?= $(subst _$(BUILD_DIR),$(PKG),$(shell go list ./... | grep -v '/vendor/'))
    49  
    50  GO_LDFLAGS ?= -X $(COMMON_PACKAGE_NAMESPACE).NAME=$(PACKAGE_NAME) -X $(COMMON_PACKAGE_NAMESPACE).VERSION=$(VERSION) \
    51                -X $(COMMON_PACKAGE_NAMESPACE).REVISION=$(REVISION) -X $(COMMON_PACKAGE_NAMESPACE).BUILT=$(BUILT) \
    52                -X $(COMMON_PACKAGE_NAMESPACE).BRANCH=$(BRANCH) \
    53                -s -w
    54  GO_FILES ?= $(shell find . -name '*.go' | grep -v './.gopath/')
    55  export CGO_ENABLED ?= 0
    56  
    57  
    58  # Development Tools
    59  DEP = $(GOPATH_BIN)/dep
    60  GOX = $(GOPATH_BIN)/gox
    61  MOCKERY = $(GOPATH_BIN)/mockery
    62  DEVELOPMENT_TOOLS = $(DEP) $(GOX) $(MOCKERY)
    63  
    64  MOCKERY_FLAGS = -note="This comment works around https://github.com/vektra/mockery/issues/155"
    65  
    66  .PHONY: clean version mocks
    67  
    68  all: deps helper-docker build
    69  
    70  include Makefile.runner_helper.mk
    71  
    72  help:
    73  	# Commands:
    74  	# make all => deps build
    75  	# make version - show information about current version
    76  	#
    77  	# Development commands:
    78  	# make build_simple - build executable for your arch and OS
    79  	# make install - install the version suitable for your OS as gitlab-runner
    80  	# make helper-docker - build docker dependencies
    81  	#
    82  	# Testing commands:
    83  	# make test - run project tests
    84  	# make codequality - run code quality analysis
    85  	#
    86  	# Deployment commands:
    87  	# make deps - install all dependencies
    88  	# make build - build project for all supported OSes
    89  	# make package - package project using FPM
    90  	# make packagecloud - send all packages to packagecloud
    91  	# make packagecloud-yank - remove specific version from packagecloud
    92  
    93  version:
    94  	@echo Current version: $(VERSION)
    95  	@echo Current revision: $(REVISION)
    96  	@echo Current branch: $(BRANCH)
    97  	@echo Build platforms: $(BUILD_PLATFORMS)
    98  	@echo DEB platforms: $(DEB_PLATFORMS)
    99  	@echo RPM platforms: $(RPM_PLATFORMS)
   100  	@echo IS_LATEST: $(IS_LATEST)
   101  
   102  deps: $(DEVELOPMENT_TOOLS)
   103  
   104  codequality:
   105  	./scripts/codequality analyze --dev
   106  
   107  build: $(GOX)
   108  	# Building $(NAME) in version $(VERSION) for $(BUILD_PLATFORMS)
   109  	gox $(BUILD_PLATFORMS) \
   110  		-ldflags "$(GO_LDFLAGS)" \
   111  		-output="out/binaries/$(NAME)-{{.OS}}-{{.Arch}}" \
   112  		$(PKG)
   113  
   114  build_simple: $(GOPATH_SETUP)
   115  	# Building $(NAME) in version $(VERSION) for current platform
   116  	go build \
   117  		-ldflags "$(GO_LDFLAGS)" \
   118  		-o "out/binaries/$(NAME)" \
   119  		$(PKG)
   120  
   121  build_current: helper-docker build_simple
   122  
   123  check_race_conditions:
   124  	@./scripts/check_race_conditions $(OUR_PACKAGES)
   125  
   126  test: $(PKG_BUILD_DIR) helper-docker
   127  	go test $(OUR_PACKAGES) $(TESTFLAGS)
   128  
   129  parallel_test_prepare: $(GOPATH_SETUP)
   130  	# Preparing test commands
   131  	@./scripts/go_test_with_coverage_report prepare
   132  
   133  parallel_test_execute: $(GOPATH_SETUP) pull_images_for_tests
   134  	# executing tests
   135  	@./scripts/go_test_with_coverage_report execute
   136  
   137  parallel_test_coverage_report: $(GOPATH_SETUP)
   138  	# Preparing coverage report
   139  	@./scripts/go_test_with_coverage_report coverage
   140  
   141  parallel_test_junit_report: $(GOPATH_SETUP)
   142  	# Preparing jUnit test report
   143  	@./scripts/go_test_with_coverage_report junit
   144  
   145  pull_images_for_tests: $(GOPATH_SETUP)
   146  	# Pulling images required for some tests
   147  	@go run ./scripts/pull-images-for-tests/main.go
   148  
   149  install:
   150  	go install --ldflags="$(GO_LDFLAGS)" $(PKG)
   151  
   152  dockerfiles:
   153  	make -C dockerfiles all
   154  
   155  # We rely on user GOPATH 'cause mockery seems not to be able to find dependencies in vendor directory
   156  mocks: $(MOCKERY)
   157  	rm -rf ./helpers/service/mocks
   158  	find . -type f ! -path '*vendor/*' -name 'mock_*' -delete
   159  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./vendor/github.com/ayufan/golang-kardianos-service -output=./helpers/service/mocks -name='(Interface)'
   160  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./helpers/docker -all -inpkg
   161  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./helpers/certificate -all -inpkg
   162  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./executors/docker -all -inpkg
   163  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./cache -all -inpkg
   164  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./common -all -inpkg
   165  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./log -all -inpkg
   166  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./session -all -inpkg
   167  	GOPATH=$(ORIGINAL_GOPATH) mockery $(MOCKERY_FLAGS) -dir=./shells -all -inpkg
   168  
   169  test-docker:
   170  	make test-docker-image IMAGE=centos:6 TYPE=rpm
   171  	make test-docker-image IMAGE=centos:7 TYPE=rpm
   172  	make test-docker-image IMAGE=debian:wheezy TYPE=deb
   173  	make test-docker-image IMAGE=debian:jessie TYPE=deb
   174  	make test-docker-image IMAGE=ubuntu-upstart:precise TYPE=deb
   175  	make test-docker-image IMAGE=ubuntu-upstart:trusty TYPE=deb
   176  	make test-docker-image IMAGE=ubuntu-upstart:utopic TYPE=deb
   177  
   178  test-docker-image:
   179  	tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE)
   180  	tests/test_installation.sh $(IMAGE) out/$(TYPE)/$(PACKAGE_NAME)_amd64.$(TYPE) Y
   181  
   182  build-and-deploy:
   183  	make build BUILD_PLATFORMS="-os=linux -arch=amd64"
   184  	make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64
   185  	scp out/deb/$(PACKAGE_NAME)_amd64.deb $(SERVER):
   186  	ssh $(SERVER) dpkg -i $(PACKAGE_NAME)_amd64.deb
   187  
   188  build-and-deploy-binary:
   189  	make build BUILD_PLATFORMS="-os=linux -arch=amd64"
   190  	scp out/binaries/$(PACKAGE_NAME)-linux-amd64 $(SERVER):/usr/bin/gitlab-runner
   191  
   192  package: package-deps package-prepare package-deb package-rpm
   193  
   194  package-deps:
   195  	# Installing packaging dependencies...
   196  	which fpm 1>/dev/null || gem install rake fpm --no-ri --no-rdoc
   197  
   198  package-prepare:
   199  	chmod 755 packaging/root/usr/share/gitlab-runner/
   200  	chmod 755 packaging/root/usr/share/gitlab-runner/*
   201  
   202  package-deb: package-deps package-prepare
   203  	# Building Debian compatible packages...
   204  	make package-deb-fpm ARCH=amd64 PACKAGE_ARCH=amd64
   205  	make package-deb-fpm ARCH=386 PACKAGE_ARCH=i386
   206  	make package-deb-fpm ARCH=arm PACKAGE_ARCH=armel
   207  	make package-deb-fpm ARCH=arm PACKAGE_ARCH=armhf
   208  
   209  package-rpm: package-deps package-prepare
   210  	# Building RedHat compatible packages...
   211  	make package-rpm-fpm ARCH=amd64 PACKAGE_ARCH=amd64
   212  	make package-rpm-fpm ARCH=386 PACKAGE_ARCH=i686
   213  	make package-rpm-fpm ARCH=arm PACKAGE_ARCH=arm
   214  	make package-rpm-fpm ARCH=arm PACKAGE_ARCH=armhf
   215  
   216  package-deb-fpm:
   217  	@mkdir -p out/deb/
   218  	fpm -s dir -t deb -n $(PACKAGE_NAME) -v $(VERSION) \
   219  		-p out/deb/$(PACKAGE_NAME)_$(PACKAGE_ARCH).deb \
   220  		--deb-priority optional --category admin \
   221  		--force \
   222  		--deb-compression bzip2 \
   223  		--after-install packaging/scripts/postinst.deb \
   224  		--before-remove packaging/scripts/prerm.deb \
   225  		--url https://gitlab.com/gitlab-org/gitlab-runner \
   226  		--description "GitLab Runner" \
   227  		-m "GitLab Inc. <support@gitlab.com>" \
   228  		--license "MIT" \
   229  		--vendor "GitLab Inc." \
   230  		--conflicts $(PACKAGE_NAME)-beta \
   231  		--conflicts gitlab-ci-multi-runner \
   232  		--conflicts gitlab-ci-multi-runner-beta \
   233  		--provides gitlab-ci-multi-runner \
   234  		--replaces gitlab-ci-multi-runner \
   235  		--depends ca-certificates \
   236  		--depends git \
   237  		--depends curl \
   238  		--depends tar \
   239  		--deb-suggests docker-engine \
   240  		-a $(PACKAGE_ARCH) \
   241  		packaging/root/=/ \
   242  		out/binaries/$(NAME)-linux-$(ARCH)=/usr/lib/gitlab-runner/gitlab-runner \
   243  		out/helper-images/=/usr/lib/gitlab-runner/helper-images/
   244  	@if [ -n "$(GPG_KEYID)" ]; then \
   245  		dpkg-sig -g "--no-tty --digest-algo 'sha512' --passphrase '$(GPG_PASSPHRASE)'" \
   246  			-k $(GPG_KEYID) --sign builder "out/deb/$(PACKAGE_NAME)_$(PACKAGE_ARCH).deb" ;\
   247  	fi
   248  
   249  package-rpm-fpm:
   250  	@mkdir -p out/rpm/
   251  	fpm -s dir -t rpm -n $(PACKAGE_NAME) -v $(VERSION) \
   252  		-p out/rpm/$(PACKAGE_NAME)_$(PACKAGE_ARCH).rpm \
   253  		--rpm-compression bzip2 --rpm-os linux \
   254  		--force \
   255  		--after-install packaging/scripts/postinst.rpm \
   256  		--before-remove packaging/scripts/prerm.rpm \
   257  		--url https://gitlab.com/gitlab-org/gitlab-runner \
   258  		--description "GitLab Runner" \
   259  		-m "GitLab Inc. <support@gitlab.com>" \
   260  		--license "MIT" \
   261  		--vendor "GitLab Inc." \
   262  		--conflicts $(PACKAGE_NAME)-beta \
   263  		--conflicts gitlab-ci-multi-runner \
   264  		--conflicts gitlab-ci-multi-runner-beta \
   265  		--provides gitlab-ci-multi-runner \
   266  		--replaces gitlab-ci-multi-runner \
   267  		--depends git \
   268  		--depends curl \
   269  		--depends tar \
   270  		-a $(PACKAGE_ARCH) \
   271  		packaging/root/=/ \
   272  		out/binaries/$(NAME)-linux-$(ARCH)=/usr/lib/gitlab-runner/gitlab-runner \
   273  		out/helper-images/=/usr/lib/gitlab-runner/helper-images/
   274  	@if [ -n "$(GPG_KEYID)" ] ; then \
   275  		echo "yes" | setsid rpm \
   276  			--define "_gpg_name $(GPG_KEYID)" \
   277  			--define "_signature gpg" \
   278  			--define "__gpg_check_password_cmd /bin/true" \
   279  			--define "__gpg_sign_cmd %{__gpg} gpg --batch --no-armor --digest-algo 'sha512' --passphrase '$(GPG_PASSPHRASE)' --no-secmem-warning -u '%{_gpg_name}' --sign --detach-sign --output %{__signature_filename} %{__plaintext_filename}" \
   280  			--addsign out/rpm/$(PACKAGE_NAME)_$(PACKAGE_ARCH).rpm ;\
   281  	fi
   282  
   283  packagecloud: packagecloud-deps packagecloud-deb packagecloud-rpm
   284  
   285  packagecloud-deps:
   286  	# Installing packagecloud dependencies...
   287  	gem install package_cloud --version "~> 0.3.0" --no-ri --no-rdoc
   288  
   289  packagecloud-deb:
   290  	# Sending Debian compatible packages...
   291  	-for DIST in $(DEB_PLATFORMS); do \
   292  		package_cloud push --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST out/deb/*.deb; \
   293  	done
   294  
   295  packagecloud-rpm:
   296  	# Sending RedHat compatible packages...
   297  	-for DIST in $(RPM_PLATFORMS); do \
   298  		package_cloud push --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST out/rpm/*.rpm; \
   299  	done
   300  
   301  packagecloud-yank:
   302  ifneq ($(YANK),)
   303  	# Removing $(YANK) from packagecloud...
   304  	-for DIST in $(DEB_PLATFORMS); do \
   305  		for ARCH in $(DEB_ARCHS); do \
   306  			package_cloud yank --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST $(PACKAGE_NAME)_$(YANK)_$$ARCH.deb & \
   307  		done; \
   308  	done; \
   309  	for DIST in $(RPM_PLATFORMS); do \
   310  		for ARCH in $(RPM_ARCHS); do \
   311  			package_cloud yank --url $(PACKAGE_CLOUD_URL) $(PACKAGE_CLOUD)/$$DIST $(PACKAGE_NAME)-$(YANK)-1.$$ARCH.rpm & \
   312  		done; \
   313  	done; \
   314  	wait
   315  else
   316  	# No version specified in YANK
   317  	@exit 1
   318  endif
   319  
   320  s3-upload:
   321  	export ARTIFACTS_DEST=artifacts; curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash
   322  	./artifacts upload \
   323  		--permissions public-read \
   324  		--working-dir out \
   325  		--target-paths "$(S3_UPLOAD_PATH)/" \
   326  		--max-size $(shell du -bs out/ | cut -f1) \
   327  		$(shell cd out/; find . -type f)
   328  	@echo "\n\033[1m==> Download index file: \033[36mhttps://$$ARTIFACTS_S3_BUCKET.s3.amazonaws.com/$$S3_UPLOAD_PATH/index.html\033[0m\n"
   329  
   330  release_packagecloud:
   331  	# Releasing to https://packages.gitlab.com/runner/
   332  	@./ci/release_packagecloud "$$CI_JOB_NAME"
   333  
   334  release_s3: prepare_windows_zip prepare_zoneinfo prepare_index
   335  	# Releasing to S3
   336  	@./ci/release_s3
   337  
   338  out/binaries/gitlab-runner-windows-%.zip: out/binaries/gitlab-runner-windows-%.exe
   339  	zip --junk-paths $@ $<
   340  	cd out/ && zip -r ../$@ helper-images
   341  
   342  prepare_windows_zip: out/binaries/gitlab-runner-windows-386.zip out/binaries/gitlab-runner-windows-amd64.zip
   343  
   344  prepare_zoneinfo:
   345  	# preparing the zoneinfo file
   346  	@cp $$GOROOT/lib/time/zoneinfo.zip out/
   347  
   348  prepare_index:
   349  	# Preparing index file
   350  	@./ci/prepare_index
   351  
   352  release_docker_images:
   353  	# Releasing Docker images
   354  	@./ci/release_docker_images
   355  
   356  check-tags-in-changelog:
   357  	# Looking for tags in CHANGELOG
   358  	@git status | grep "On branch master" 2>&1 >/dev/null || echo "Check should be done on master branch only. Skipping."
   359  	@for tag in $$(git tag | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$$" | sed 's|v||' | sort -g); do \
   360  		state="MISSING"; \
   361  		grep "^v $$tag" CHANGELOG.md 2>&1 >/dev/null; \
   362  		[ "$$?" -eq 1 ] || state="OK"; \
   363  		echo "$$tag:   \t $$state"; \
   364  	done
   365  
   366  prepare_release_checklist_issue_dry_run:
   367  	make prepare_release_checklist_issue opts="-dry-run"
   368  
   369  prepare_release_checklist_issue: opts ?= ""
   370  prepare_release_checklist_issue: $(GOPATH_SETUP)
   371  	@go run $(PKG)/scripts/prepare-release-checklist-issue \
   372  		-issue-template-file ".gitlab/issue_templates/Release Checklist.md" \
   373  		$(opts)
   374  
   375  update_feature_flags_docs: $(GOPATH_SETUP)
   376  	go run ./scripts/update-feature-flags-docs/main.go
   377  
   378  development_setup:
   379  	test -d tmp/gitlab-test || git clone https://gitlab.com/gitlab-org/ci-cd/tests/gitlab-test.git tmp/gitlab-test
   380  	if prlctl --version ; then $(MAKE) -C tests/ubuntu parallels ; fi
   381  	if vboxmanage --version ; then $(MAKE) -C tests/ubuntu virtualbox ; fi
   382  
   383  dep_check: $(DEP)
   384  	@cd $(PKG_BUILD_DIR) && $(DEP) check
   385  
   386  dep_status: $(DEP)
   387  	@./scripts/dep_status_check $(PKG_BUILD_DIR)
   388  
   389  # local GOPATH
   390  $(GOPATH_SETUP): $(PKG_BUILD_DIR)
   391  	mkdir -p $(GOPATH_BIN)
   392  	touch $@
   393  
   394  $(PKG_BUILD_DIR):
   395  	mkdir -p $(@D)
   396  	ln -s ../../../.. $@
   397  
   398  # development tools
   399  $(DEP): $(GOPATH_SETUP)
   400  	go get github.com/golang/dep/cmd/dep
   401  
   402  $(GOX): $(GOPATH_SETUP)
   403  	go get github.com/mitchellh/gox
   404  
   405  $(MOCKERY): $(GOPATH_SETUP)
   406  	go get github.com/vektra/mockery/.../
   407  
   408  clean:
   409  	-$(RM) -rf $(LOCAL_GOPATH)
   410  	-$(RM) -rf $(TARGET_DIR)