diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2017-10-02 14:12:04 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2017-10-02 14:12:04 +0300 |
commit | b322a578e5cfa144f5d0c5be3f43b2a0c9d8d42e (patch) | |
tree | e4a38cd7c6ee3fb64208fb53fb815dfc678d9a98 | |
parent | 550eecbcdc65ade834311629f5cac9d0d2387e62 (diff) | |
parent | d4aa227433be1b4c415ad8e70f5123b81a496360 (diff) |
Merge branch '2-fix-makefile-and-ci' into 'master'
Resolve "'cannot find package' when running make"
Closes #2
See merge request gitlab-org/gitlab-pages!45
-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 | ||||
-rw-r--r-- | domain_config_test.go | 2 | ||||
-rw-r--r-- | domains_test.go | 5 | ||||
-rw-r--r-- | logging_test.go | 3 | ||||
-rw-r--r-- | metrics/metrics.go | 5 | ||||
-rw-r--r-- | multi_string_flag_test.go | 3 | ||||
-rw-r--r-- | server.go | 3 |
12 files changed, 174 insertions, 61 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) diff --git a/domain_config_test.go b/domain_config_test.go index 51b9468b..307060ef 100644 --- a/domain_config_test.go +++ b/domain_config_test.go @@ -3,10 +3,10 @@ package main import ( "io/ioutil" "os" + "path/filepath" "testing" "github.com/stretchr/testify/assert" - "path/filepath" ) const configFile = "test-group/test-project/config.json" diff --git a/domains_test.go b/domains_test.go index 6ce11f5f..51bafc9f 100644 --- a/domains_test.go +++ b/domains_test.go @@ -2,12 +2,13 @@ package main import ( "crypto/rand" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "io/ioutil" "os" "testing" "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) const updateFile = ".update" diff --git a/logging_test.go b/logging_test.go index e6551047..bc557a71 100644 --- a/logging_test.go +++ b/logging_test.go @@ -2,9 +2,10 @@ package main import ( "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) func testLogWithStatus(ww http.ResponseWriter, r *http.Request) { diff --git a/metrics/metrics.go b/metrics/metrics.go index 00e39460..b15c6711 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -5,21 +5,25 @@ import ( ) var ( + // DomainsServed counts the total number of sites served DomainsServed = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "gitlab_pages_domains_served_total", Help: "The total number of sites served by this Pages app", }) + // DomainUpdates counts the number of site updates processed DomainUpdates = prometheus.NewCounter(prometheus.CounterOpts{ Name: "gitlab_pages_domains_updated_total", Help: "The total number of site updates processed since daemon start", }) + // DomainLastUpdateTime is the UNIX timestamp of the last update DomainLastUpdateTime = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "gitlab_pages_last_domain_update_seconds", Help: "UNIX timestamp of the last update", }) + // ProcessedRequests is the number of HTTP requests served ProcessedRequests = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "gitlab_pages_http_requests_total", Help: "Total number of HTTP requests done serving", @@ -27,6 +31,7 @@ var ( []string{"code", "method"}, ) + // SessionsActive is the number of HTTP requests currently being processed SessionsActive = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "gitlab_pages_http_sessions_active", Help: "The number of HTTP requests currently being processed", diff --git a/multi_string_flag_test.go b/multi_string_flag_test.go index bbbdea3d..ca561bc4 100644 --- a/multi_string_flag_test.go +++ b/multi_string_flag_test.go @@ -2,8 +2,9 @@ package main import ( "flag" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestMultiStringFlagAppendsOnSet(t *testing.T) { @@ -3,11 +3,12 @@ package main import ( "crypto/tls" "fmt" - "golang.org/x/net/http2" "net" "net/http" "os" "time" + + "golang.org/x/net/http2" ) type tlsHandlerFunc func(*tls.ClientHelloInfo) (*tls.Certificate, error) |