diff --git a/.gitignore b/.gitignore index 0aba6d4889e5a58ff645859e3f64cf04bacd6e46..c5d418a9c66b8da2ef6856c651103c6fe467027e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /internal/service/smarthttp/testdata /internal/testhelper/testdata /config.toml +_tools diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1b8f75df221fc3d6c7ae6bb85a08b09192904977..c8c11137cf97f774c151c28782f3298f629a4fc2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,31 +1,40 @@ -image: registry.gitlab.com/gitlab-org/gitlab-build-images:golang-1.7-git-2.8.4 +image: registry.gitlab.com/gitlab-org/gitlab-build-images:golang-1.8-git-2.8.4 stages: - test + - build - package - publish +verify: + stage: test + script: + - make verify + .test_template: &test_definition stage: test script: - go version - git version - - make - make test +coverage: + stage: test + script: + - make cover + test:go1.8: <<: *test_definition image: registry.gitlab.com/gitlab-org/gitlab-build-images:golang-1.8-git-2.8.4 -verify: - stage: test +compile: + stage: build script: - - make notice-up-to-date - - make verify + - make build package: stage: package - only: + only: - tags script: - apt-get update -qq diff --git a/Makefile b/Makefile index 3acb0c2e8a695e173a5f0f3f92c9b9b74bf62324..63bd2ff443be7bd23f10c8c9fca8318eae008674 100644 --- a/Makefile +++ b/Makefile @@ -1,74 +1,129 @@ -PREFIX=/usr/local -PKG=gitlab.com/gitlab-org/gitaly -BUILD_DIR=$(shell pwd) -BIN_BUILD_DIR=${BUILD_DIR}/_build/bin -PKG_BUILD_DIR:=${BUILD_DIR}/_build/src/${PKG} -CMDS:=$(shell cd cmd && ls) -TEST_REPO=internal/testhelper/testdata/data/gitlab-test.git +PREFIX := /usr/local +PKG := gitlab.com/gitlab-org/gitaly +BUILD_DIR := ${CURDIR} +TARGET_DIR := ${BUILD_DIR}/_build +BIN_BUILD_DIR := ${TARGET_DIR}/bin +PKG_BUILD_DIR := ${TARGET_DIR}/src/${PKG} +export TEST_REPO_LOCATION := ${TARGET_DIR}/testdata/data +TEST_REPO := ${TEST_REPO_LOCATION}/gitlab-test.git +COVERAGE_DIR := ${TARGET_DIR}/cover +TOOLS_DIR := ${BUILD_DIR}/_tools + VERSION=$(shell git describe)-$(shell date -u +%Y%m%d.%H%M%S) -export GOPATH=${BUILD_DIR}/_build -export GO15VENDOREXPERIMENT=1 -export PATH:=${GOPATH}/bin:$(PATH) +export GOPATH := ${TARGET_DIR} +export GO15VENDOREXPERIMENT = 1 +export PATH := ${GOPATH}/bin:${PATH} + +# Returns a list of all non-vendored (local packages) +LOCAL_PACKAGES = $(shell cd "${PKG_BUILD_DIR}" && GOPATH=${GOPATH} ${TOOLS_DIR}/govendor list -no-status +local) +COMMAND_PACKAGES = $(shell cd "${PKG_BUILD_DIR}" && GOPATH=${GOPATH} ${TOOLS_DIR}/govendor list -no-status +local +p ./cmd/...) +COMMANDS = $(subst $(PKG)/cmd/,,$(COMMAND_PACKAGES)) .PHONY: all -all: build +all: verify build test -.PHONY: ${BUILD_DIR}/_build -${BUILD_DIR}/_build: - mkdir -p $@/src/${PKG} - tar -cf - --exclude _build --exclude .git . | (cd $@/src/${PKG} && tar -xf -) - touch $@ +${TARGET_DIR}/.ok: Makefile ${TOOLS_DIR}/govendor + rm -rf -- "${TARGET_DIR}" + mkdir -p "$(dir ${PKG_BUILD_DIR})" + ln -sf ../../../.. "${PKG_BUILD_DIR}" + mkdir -p "${BIN_BUILD_DIR}" + touch -- "${TARGET_DIR}/.ok" -build: clean-build ${BUILD_DIR}/_build $(shell find . -name '*.go' -not -path './vendor/*' -not -path './_build/*') - rm -f -- "${BIN_BUILD_DIR}/*" - go install -ldflags "-X main.version=${VERSION}" ${PKG}/cmd/... - cp ${BIN_BUILD_DIR}/* ${BUILD_DIR}/ +.PHONY: build +build: ${TARGET_DIR}/.ok + go install -ldflags "-X main.version=${VERSION}" ${COMMAND_PACKAGES} + cp $(foreach cmd,${COMMANDS},${BIN_BUILD_DIR}/${cmd}) ${BUILD_DIR}/ +.PHONY: install install: build mkdir -p $(DESTDIR)${PREFIX}/bin/ - cd ${BIN_BUILD_DIR} && install ${CMDS} ${DESTDIR}${PREFIX}/bin/ + cd ${BIN_BUILD_DIR} && install ${COMMANDS} ${DESTDIR}${PREFIX}/bin/ -verify: lint check-formatting govendor-status +.PHONY: verify +verify: lint check-formatting govendor-status notice-up-to-date -check-formatting: install-developer-tools +.PHONY: check-formatting +check-formatting: go run _support/gofmt-all.go -n -govendor-status: ${BUILD_DIR}/_build install-developer-tools - cd ${PKG_BUILD_DIR} && govendor status +.PHONY: govendor-status +govendor-status: ${TARGET_DIR}/.ok ${TOOLS_DIR}/govendor + cd ${PKG_BUILD_DIR} && ${TOOLS_DIR}/govendor status ${TEST_REPO}: git clone --bare https://gitlab.com/gitlab-org/gitlab-test.git $@ -test: clean-build ${TEST_REPO} ${BUILD_DIR}/_build - go test ${PKG}/... +.PHONY: test +test: ${TARGET_DIR}/.ok ${TEST_REPO} + go test ${LOCAL_PACKAGES} -lint: install-developer-tools - go run _support/lint.go +.PHONY: test-race +test-race: ${TARGET_DIR}/.ok ${TEST_REPO} + GODEBUG=cgocheck=2 go test -v -race ${LOCAL_PACKAGES} -package: build - ./_support/package/package ${CMDS} +.PHONY: lint +lint: ${TARGET_DIR}/.ok ${TOOLS_DIR}/golint + ${TOOLS_DIR}/golint ${LOCAL_PACKAGES} -notice: ${BUILD_DIR}/_build install-developer-tools - rm -f ${PKG_BUILD_DIR}/NOTICE # Avoid NOTICE-in-NOTICE - cd ${PKG_BUILD_DIR} && govendor license -template _support/notice.template -o ${BUILD_DIR}/NOTICE +.PHONY: package +package: build + ./_support/package/package ${COMMANDS} -notice-up-to-date: notice - git ls-files --error-unmatch NOTICE # NOTICE is a tracked file - git diff --exit-code # there are no changed files +.PHONY: notice +notice: ${TARGET_DIR}/.ok ${TOOLS_DIR}/govendor + cd ${PKG_BUILD_DIR} && ${TOOLS_DIR}/govendor license -template _support/notice.template -o ${BUILD_DIR}/NOTICE -clean: clean-build - rm -rf internal/testhelper/testdata - rm -f $(foreach cmd,${CMDS},./${cmd}) +.PHONY: notice-up-to-date +notice-up-to-date: ${TARGET_DIR}/.ok ${TOOLS_DIR}/govendor + cd ${PKG_BUILD_DIR} && ${TOOLS_DIR}/govendor license -template _support/notice.template -o ${TARGET_DIR}/nutd.temp + diff ${TARGET_DIR}/nutd.temp NOTICE + rm -f ${TARGET_DIR}/nutd.temp -clean-build: - rm -rf ${BUILD_DIR}/_build +.PHONY: clean +clean: + rm -rf -- ${TARGET_DIR} + rm -f -- $(foreach cmd,${COMMANDS},./${cmd}) .PHONY: format format: - @go run _support/gofmt-all.go -f + go run _support/gofmt-all.go -f + +.PHONY: cover +cover: ${TARGET_DIR}/.ok ${TEST_REPO} ${TOOLS_DIR}/gocovmerge + @echo "NOTE: make cover does not exit 1 on failure, don't use it to check for tests success!" + mkdir -p "${COVERAGE_DIR}" + rm -f ${COVERAGE_DIR}/*.out "${COVERAGE_DIR}/all.merged" "${COVERAGE_DIR}/all.html" + @for MOD in ${LOCAL_PACKAGES}; do \ + go test -coverpkg=`echo ${LOCAL_PACKAGES}|tr " " ","` \ + -coverprofile=${COVERAGE_DIR}/unit-`echo $$MOD|tr "/" "_"`.out \ + $$MOD 2>&1 | grep -v "no packages being tested depend on"; \ + done + ${TOOLS_DIR}/gocovmerge ${COVERAGE_DIR}/*.out > "${COVERAGE_DIR}/all.merged" + go tool cover -html "${COVERAGE_DIR}/all.merged" -o "${COVERAGE_DIR}/all.html" + @echo "" + @echo "=====> Total test coverage: <=====" + @echo "" + @go tool cover -func "${COVERAGE_DIR}/all.merged" + +.PHONY: list +list: ${TARGET_DIR}/.ok + @echo "${LOCAL_PACKAGES}" .PHONY: install-developer-tools -install-developer-tools: - @go run _support/go-get-if-missing.go govendor github.com/kardianos/govendor - @go run _support/go-get-if-missing.go golint github.com/golang/lint/golint +install-developer-tools: ${TOOLS_DIR}/govendor ${TOOLS_DIR}/golint ${TOOLS_DIR}/gocovmerge + +${TOOLS_DIR}/govendor: + go get github.com/kardianos/govendor + mkdir -p ${TOOLS_DIR} + mv ${BIN_BUILD_DIR}/govendor ${TOOLS_DIR}/ + +${TOOLS_DIR}/golint: + go get github.com/golang/lint/golint + mkdir -p ${TOOLS_DIR} + mv ${BIN_BUILD_DIR}/golint ${TOOLS_DIR}/ + +${TOOLS_DIR}/gocovmerge: + go get github.com/wadey/gocovmerge + mkdir -p ${TOOLS_DIR} + mv ${BIN_BUILD_DIR}/gocovmerge ${TOOLS_DIR}/ diff --git a/NOTICE b/NOTICE index f24a42935500b369dd9c8b98bfa5be2529246a68..5fd076fe74aeb5914a69fa9c606165cae2066455 100644 --- a/NOTICE +++ b/NOTICE @@ -1,5 +1,6 @@ The following components are included in Gitaly: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LICENSE - go Copyright (c) 2009 The Go Authors. All rights reserved. @@ -52,7 +53,6 @@ implementation of Go constitutes direct or contributory patent infringement, or inducement of patent infringement, then any patent rights granted to you under this License for this implementation of Go shall terminate as of the date such litigation is filed. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LICENSE - gitlab.com/gitlab-org/gitaly The MIT License (MIT) diff --git a/_support/notice.template b/_support/notice.template index 9543d1d69b24bb16b0c6c2da28bb9a4742b914f1..197675a4d8272e843eda43a0bfb719c484082c35 100644 --- a/_support/notice.template +++ b/_support/notice.template @@ -1,58 +1,16 @@ The following components are included in Gitaly: -LICENSE - go -Copyright (c) 2009 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +{{ range $index, $t := . -}} + {{- if eq .Path " go" -}} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -PATENTS - go -Additional IP Rights Grant (Patents) - -"This implementation" means the copyrightable works distributed by -Google as part of the Go project. - -Google hereby grants to You a perpetual, worldwide, non-exclusive, -no-charge, royalty-free, irrevocable (except as stated in this section) -patent license to make, have made, use, offer to sell, sell, import, -transfer and otherwise run, modify and propagate the contents of this -implementation of Go, where such license applies only to those patent -claims, both currently owned or controlled by Google and acquired in -the future, licensable by Google that are necessarily infringed by this -implementation of Go. This grant does not include claims that would be -infringed only as a consequence of further modification of this -implementation. If you or your agent or exclusive licensee institute or -order or agree to the institution of patent litigation against any -entity (including a cross-claim or counterclaim in a lawsuit) alleging -that this implementation of Go or any code incorporated within this -implementation of Go constitutes direct or contributory patent -infringement, or inducement of patent infringement, then any patent -rights granted to you under this License for this implementation of Go -shall terminate as of the date such litigation is filed. - -{{range $index, $t := .}}{{if ne .Path " go" }}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -{{.Filename}} - {{.Path}} -{{.Text}}{{end}}{{end}} +{{ .Filename }} - {{ .Path }} +{{ .Text }} + {{- end -}} +{{- end -}} +{{ range $index, $t := . -}} + {{- if and (ne .Path " go") (or (ne .Path "gitlab.com/gitlab-org/gitaly") (ne .Filename "NOTICE") ) -}} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +{{ .Filename }} - {{ .Path }} +{{ .Text }} + {{- end -}} +{{- end }} diff --git a/_support/release b/_support/release index 091004639b7986f1690ab9cf4f54fc2dd6835195..92e776b7c343d57bbe98c7c48078cf537dfc9564 100755 --- a/_support/release +++ b/_support/release @@ -4,7 +4,7 @@ require 'erb' require_relative 'run.rb' def main(version) - run!(%w[make notice-up-to-date]) + run!(%w[make verify]) run!(%w[make test]) puts 'Testing for changed files' diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index 0a19ee205160848fefdfcb024b89c4e3afbad6e9..d5ee2fab7d877ae7242dbd3bae1a289a6ff8dc86 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -12,6 +12,8 @@ import ( log "github.com/Sirupsen/logrus" + "path/filepath" + "google.golang.org/grpc" "google.golang.org/grpc/codes" ) @@ -31,6 +33,17 @@ func MustReadFile(t *testing.T, filename string) []byte { // GitlabTestStoragePath returns the storage path to the gitlab-test repo. func GitlabTestStoragePath() string { + // If TEST_REPO_LOCATION has been set (by the Makefile) then use that + testRepoPath := os.Getenv("TEST_REPO_LOCATION") + if testRepoPath != "" { + testRepoPathAbs, err := filepath.Abs(testRepoPath) + if err != nil { + log.Fatal(err) + } + + return testRepoPathAbs + } + _, currentFile, _, ok := runtime.Caller(0) if !ok { log.Fatal("Could not get caller info")