2019-04-25 17:06:53 +00:00
DIST := dist
2020-03-05 09:22:41 +00:00
export GO111MODULE = on
2021-09-23 16:01:07 +00:00
export CGO_ENABLED = 0
2019-04-25 17:06:53 +00:00
GO ?= go
SHASUM ?= shasum -a 256
export PATH := $( $( GO) env GOPATH) /bin:$( PATH)
GOFILES := $( shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go" )
GOFMT ?= gofmt -s
i f n e q ( $( DRONE_TAG ) , )
VERSION ?= $( subst v,,$( DRONE_TAG) )
2019-04-26 03:41:21 +00:00
TEA_VERSION ?= $( VERSION)
2019-04-25 17:06:53 +00:00
e l s e
ifneq ( $( DRONE_BRANCH) ,)
VERSION ?= $( subst release/v,,$( DRONE_BRANCH) )
else
VERSION ?= master
endif
2019-04-26 03:41:21 +00:00
TEA_VERSION ?= $( shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//' )
2019-04-25 17:06:53 +00:00
e n d i f
2021-03-30 11:13:23 +00:00
TEA_VERSION_TAG ?= $( shell sed 's/+/_/' <<< $( TEA_VERSION) )
2021-09-23 16:01:07 +00:00
TAGS ?=
LDFLAGS := -X " main.Version= $( TEA_VERSION) " -X " main.Tags= $( TAGS) " -s -w
i f e q ( $( STATIC ) , t r u e )
# NOTE: clean up this mess, when https://github.com/golang/go/issues/26492 is resolved
# static_build is a defacto standard tag used in go packages
TAGS := osusergo,netgo,static_build,$( TAGS)
LDFLAGS := $( LDFLAGS) -linkmode= external -extldflags "-static-pie" -X " main.Tags= $( TAGS) "
export CGO_ENABLED = 1 # needed for linkmode=external
e n d i f
# override to allow passing additional goflags via make CLI
override GOFLAGS : = $( GOFLAGS ) -mod =vendor -tags '$( TAGS ) ' -ldflags '$( LDFLAGS ) '
2019-04-25 17:06:53 +00:00
2019-04-26 03:41:21 +00:00
PACKAGES ?= $( shell $( GO) list ./... | grep -v /vendor/)
2019-04-25 17:06:53 +00:00
SOURCES ?= $( shell find . -name "*.go" -type f)
i f e q ( $( OS ) , W i n d o w s _ N T )
EXECUTABLE := tea.exe
e l s e
EXECUTABLE := tea
e n d i f
.PHONY : all
all : build
.PHONY : clean
clean :
2020-03-05 09:22:41 +00:00
$( GO) clean -mod= vendor -i ./...
2019-04-26 03:41:21 +00:00
rm -rf $( EXECUTABLE) $( DIST)
2019-04-25 17:06:53 +00:00
.PHONY : fmt
fmt :
$( GOFMT) -w $( GOFILES)
.PHONY : vet
vet :
2020-04-28 13:02:21 +00:00
# Default vet
2020-03-05 09:22:41 +00:00
$( GO) vet -mod= vendor $( PACKAGES)
2020-04-28 13:02:21 +00:00
# Custom vet
2020-07-21 16:17:52 +00:00
$( GO) build -mod= vendor code.gitea.io/gitea-vet
2020-04-28 13:02:21 +00:00
$( GO) vet -vettool= gitea-vet $( PACKAGES)
2019-04-25 17:06:53 +00:00
.PHONY : lint
lint :
@hash revive > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 09:22:41 +00:00
cd /tmp && $( GO) get -u github.com/mgechev/revive; \
2019-04-25 17:06:53 +00:00
fi
revive -config .revive.toml -exclude= ./vendor/... ./... || exit 1
.PHONY : misspell -check
misspell-check :
@hash misspell > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 09:22:41 +00:00
cd /tmp && $( GO) get -u github.com/client9/misspell/cmd/misspell; \
2019-04-25 17:06:53 +00:00
fi
misspell -error -i unknwon,destory $( GOFILES)
.PHONY : misspell
misspell :
@hash misspell > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-03-05 09:22:41 +00:00
cd /tmp && $( GO) get -u github.com/client9/misspell/cmd/misspell; \
2019-04-25 17:06:53 +00:00
fi
misspell -w -i unknwon $( GOFILES)
.PHONY : fmt -check
fmt-check :
# get all go files and run go fmt on them
@diff= $$ ( $( GOFMT) -d $( GOFILES) ) ; \
if [ -n " $$ diff " ] ; then \
echo "Please run 'make fmt' and commit the result:" ; \
echo " $$ {diff} " ; \
exit 1; \
fi ;
.PHONY : test
test :
2020-03-05 09:22:41 +00:00
$( GO) test -mod= vendor -tags= 'sqlite sqlite_unlock_notify' $( PACKAGES)
2019-04-25 17:06:53 +00:00
.PHONY : unit -test -coverage
unit-test-coverage :
2020-03-05 09:22:41 +00:00
$( GO) test -mod= vendor -tags= 'sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $( PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
2019-04-25 17:06:53 +00:00
.PHONY : vendor
vendor :
2020-03-05 09:22:41 +00:00
$( GO) mod tidy && $( GO) mod vendor
2019-04-25 17:06:53 +00:00
.PHONY : test -vendor
test-vendor : vendor
@diff= $$ ( git diff vendor/) ; \
if [ -n " $$ diff " ] ; then \
echo "Please run 'make vendor' and commit the result:" ; \
echo " $$ {diff} " ; \
exit 1; \
fi ;
.PHONY : check
check : test
.PHONY : install
2021-09-23 16:01:07 +00:00
install : $( SOURCES )
@echo " installing to $( GOPATH) /bin/ $( EXECUTABLE) "
$( GO) install -v -buildmode= pie $( GOFLAGS)
2019-04-25 17:06:53 +00:00
.PHONY : build
build : $( EXECUTABLE )
$(EXECUTABLE) : $( SOURCES )
2021-09-23 16:01:07 +00:00
i f e q ( $( STATIC ) , t r u e )
@echo "enabling static build, make sure you have glibc-static (or equivalent) installed"
e n d i f
$( GO) build -buildmode= pie $( GOFLAGS) -o $@
2019-04-25 17:06:53 +00:00
2021-03-30 11:13:23 +00:00
.PHONY : build -image
build-image :
docker build --build-arg VERSION = $( TEA_VERSION) -t gitea/tea:$( TEA_VERSION_TAG) .
2019-04-25 17:06:53 +00:00
.PHONY : release
2020-12-08 17:45:48 +00:00
release : release -dirs release -os release -compress release -check
2019-04-25 17:06:53 +00:00
.PHONY : release -dirs
release-dirs :
mkdir -p $( DIST) /binaries $( DIST) /release
2020-12-08 17:45:48 +00:00
.PHONY : release -os
release-os :
@hash gox > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
cd /tmp && $( GO) get -u github.com/mitchellh/gox; \
2019-04-25 17:06:53 +00:00
fi
2021-09-23 16:01:07 +00:00
CGO_ENABLED = 0 gox -verbose -cgo= false $( GOFLAGS) -osarch= '!darwin/386 !darwin/arm' -os= "windows linux darwin" -arch= "386 amd64 arm arm64" -output= " $( DIST) /release/tea- $( VERSION) -{{.OS}}-{{.Arch}} "
2019-04-25 17:06:53 +00:00
2019-04-27 13:01:07 +00:00
.PHONY : release -compress
release-compress :
@hash gxz > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2020-04-06 14:21:36 +00:00
GO111MODULE = off $( GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
2019-04-27 13:01:07 +00:00
fi
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " compressing $$ {file} " && gxz -k -9 $$ { file} ; done ;
2019-04-25 17:06:53 +00:00
.PHONY : release -check
release-check :
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " checksumming $$ {file} " && $( SHASUM) ` echo $$ { file} | sed 's/^..//' ` > $$ { file} .sha256; done ;