diff options
-rw-r--r-- | .gitignore | 11 | ||||
-rw-r--r-- | .gitlab-ci.yml | 18 | ||||
-rw-r--r-- | Makefile | 74 | ||||
-rw-r--r-- | Makefile.build.mk | 20 | ||||
-rw-r--r-- | Makefile.internal.mk | 53 | ||||
-rw-r--r-- | Makefile.util.mk | 38 |
6 files changed, 159 insertions, 55 deletions
@@ -1,3 +1,14 @@ # Created by .ignore support plugin (hsz.mobi) shared/pages/.update /gitlab-pages + +# Used by the makefile +/.GOPATH +/bin + +# Added by `make setup` +/vendor/manifest +/vendor/github.com/fzipp/gocyclo/ +/vendor/golang.org/x/tools/ +/vendor/github.com/wadey/gocovmerge/ +/vendor/github.com/golang/lint/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 38084c3e..9b75c6ee 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,18 +1,15 @@ image: golang:1.8 -# Put the go sources in GOPATH -# This is required to make the vendor working -before_script: -- GODIR=$GOPATH/src/gitlab.com/gitlab-org/gitlab-pages -- mkdir -p "$(dirname "$GODIR")" -- ln -sfv "$(pwd -P)" "$GODIR" -- cd "$GODIR" - .test: &test script: + - make setup - make verify - - make acceptance - + - make cover + - make test + artifacts: + paths: + - bin/gitlab-pages + - coverage.html test:1.8: <<: *test @@ -20,4 +17,3 @@ test:1.8: test:1.9: image: golang:1.9 <<: *test -
\ No newline at end of file @@ -1,48 +1,34 @@ -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) +IMPORT_PATH := gitlab.com/gitlab-org/gitlab-pages +V := 1 -ifneq (v$(VERSION),$(LAST_TAG)) - VERSION := $(shell echo $(VERSION)~beta.$(COMMITS).g$(REVISION)) -endif - -GO_LDFLAGS ?= -X main.VERSION=$(VERSION) -X main.REVISION=$(REVISION) -GO_FILES ?= $(shell find . -name '*.go') +# Space separated patterns of packages to skip in list, test, fmt. +IGNORED_PACKAGES := /vendor/ /internal/httputil/ +# GitLab Pages is statically compiled without CGO to help it in chroot mode export CGO_ENABLED := 0 -all: gitlab-pages - -gitlab-pages: $(GO_FILES) - go build -o gitlab-pages --ldflags="$(GO_LDFLAGS)" - -update: - godep save ./... - -verify: fmt vet complexity lint test - -fmt: - go fmt ./... | awk '{ print "Please run go fmt"; exit 1 }' - -vet: - go tool vet *.go - -lint: - go get github.com/golang/lint/golint - golint . | ( ! grep -v "^$$" ) - -complexity: - go get github.com/fzipp/gocyclo - gocyclo -over 9 $(wildcard *.go) - -test: - go get golang.org/x/tools/cmd/cover - go test . -short -cover -v -timeout 1m - -acceptance: gitlab-pages - go get golang.org/x/tools/cmd/cover - go test . -cover -v -timeout 1m - -docker: - docker run --rm -it -v ${PWD}:/go/src/pages -w /go/src/pages golang:1.5 /bin/bash +include Makefile.build.mk +include Makefile.util.mk +include Makefile.internal.mk + +# Based on https://github.com/cloudflare/hellogopher - v1.1 - MIT License +# +# Copyright (c) 2017 Cloudflare +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. diff --git a/Makefile.build.mk b/Makefile.build.mk new file mode 100644 index 00000000..70f446d4 --- /dev/null +++ b/Makefile.build.mk @@ -0,0 +1,20 @@ +.PHONY: all setup build clean + +all: gitlab-pages + +setup: clean .GOPATH/.ok + go get -u github.com/FiloSottile/gvt + - ./bin/gvt fetch golang.org/x/tools/cmd/goimports + - ./bin/gvt fetch github.com/wadey/gocovmerge + - ./bin/gvt fetch github.com/golang/lint/golint + - ./bin/gvt fetch github.com/fzipp/gocyclo + +build: .GOPATH/.ok + $Q go install $(if $V,-v) $(VERSION_FLAGS) $(IMPORT_PATH) + +clean: + $Q rm -rf bin .GOPATH gitlab-pages + +gitlab-pages: build + $Q cp -f ./bin/gitlab-pages . + diff --git a/Makefile.internal.mk b/Makefile.internal.mk new file mode 100644 index 00000000..309083ff --- /dev/null +++ b/Makefile.internal.mk @@ -0,0 +1,53 @@ +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) + +ifneq (v$(VERSION),$(LAST_TAG)) + VERSION := $(shell echo $(VERSION)~beta.$(COMMITS).g$(REVISION)) +endif + +VERSION_FLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.REVISION=$(REVISION)"' + +# cd into the GOPATH to workaround ./... not following symlinks +_allpackages = $(shell ( cd $(CURDIR)/.GOPATH/src/$(IMPORT_PATH) && \ + GOPATH=$(CURDIR)/.GOPATH go list ./... 2>&1 1>&3 | \ + grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)) 1>&2 ) 3>&1 | \ + grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES))) + +_allfiles = $(shell cd $(CURDIR)/.GOPATH/src/$(IMPORT_PATH) && find . -iname '*.go' | grep -v "^\./\." | grep -v -e "^$$" $(addprefix -e ,$(IGNORED_PACKAGES)) ) + +# memoize allpackages, so that it's executed only once and only if used +allpackages = $(if $(__allpackages),,$(eval __allpackages := $$(_allpackages)))$(__allpackages) +allfiles = $(if $(__allfiles),,$(eval __allfiles := $$(_allfiles)))$(__allfiles) + +export GOPATH := $(CURDIR)/.GOPATH +unexport GOBIN + +Q := $(if $V,,@) + +.GOPATH/.ok: + $Q mkdir -p "$(dir .GOPATH/src/$(IMPORT_PATH))" + $Q ln -s ../../../.. ".GOPATH/src/$(IMPORT_PATH)" + $Q mkdir -p .GOPATH/test .GOPATH/cover + $Q mkdir -p bin + $Q ln -s ../bin .GOPATH/bin + $Q touch $@ + +.PHONY: bin/gocovmerge bin/goimports +bin/gocovmerge: .GOPATH/.ok + @test -d ./vendor/github.com/wadey/gocovmerge || \ + { echo "Vendored gocovmerge not found, try running 'make setup'..."; exit 1; } + $Q go install $(IMPORT_PATH)/vendor/github.com/wadey/gocovmerge +bin/gocyclo: .GOPATH/.ok + @test -d ./vendor/github.com/fzipp/gocyclo || \ + { echo "Vendored gocyclo not found, try running 'make setup'..."; exit 1; } + $Q go get github.com/fzipp/gocyclo +bin/goimports: .GOPATH/.ok + @test -d ./vendor/golang.org/x/tools/cmd/goimports || \ + { echo "Vendored goimports not found, try running 'make setup'..."; exit 1; } + $Q go install $(IMPORT_PATH)/vendor/golang.org/x/tools/cmd/goimports +bin/golint: .GOPATH/.ok + @test -d ./vendor/github.com/golang/lint/golint || \ + { echo "Vendored golint not found, try running 'make setup'..."; exit 1; } + $Q go install $(IMPORT_PATH)/vendor/github.com/golang/lint/golint diff --git a/Makefile.util.mk b/Makefile.util.mk new file mode 100644 index 00000000..18f6b0ff --- /dev/null +++ b/Makefile.util.mk @@ -0,0 +1,38 @@ +.PHONY: verify fmt vet lint complexity test cover list + +verify: list fmt vet lint complexity + +fmt: bin/goimports .GOPATH/.ok + $Q ./bin/goimports -l $(allfiles) | awk '{ print "Please run go fmt"; exit 1 }' + +vet: .GOPATH/.ok + $Q go vet $(allpackages) + +lint: bin/golint + $Q ./bin/golint $(allpackages) | tee | ( ! grep -v "^$$" ) + +complexity: .GOPATH/.ok bin/gocyclo + $Q ./bin/gocyclo -over 9 $(allfiles) + +test: .GOPATH/.ok gitlab-pages + go test $(if $V,-v) -timeout=1m $(allpackages) + +# The acceptance tests cannot count for coverage +cover: bin/gocovmerge .GOPATH/.ok + @echo "NOTE: make cover does not exit 1 on failure, don't use it to check for tests success!" + $Q rm -f .GOPATH/cover/*.out .GOPATH/cover/all.merged + $(if $V,@echo "-- go test -coverpkg=./... -coverprofile=.GOPATH/cover/... ./...") + @for MOD in $(allpackages); do \ + go test -coverpkg=`echo $(allpackages)|tr " " ","` \ + -coverprofile=.GOPATH/cover/unit-`echo $$MOD|tr "/" "_"`.out \ + $$MOD 2>&1 | grep -v "no packages being tested depend on"; \ + done + $Q ./bin/gocovmerge .GOPATH/cover/*.out > .GOPATH/cover/all.merged + $Q go tool cover -html .GOPATH/cover/all.merged -o coverage.html + @echo "" + @echo "=====> Total test coverage: <=====" + @echo "" + $Q go tool cover -func .GOPATH/cover/all.merged + +list: .GOPATH/.ok + @echo $(allpackages) |