Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Makefile 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. DIST := dist
  2. IMPORT := code.gitea.io/gitea
  3. GO ?= go
  4. SED_INPLACE := sed -i
  5. ifeq ($(OS), Windows_NT)
  6. EXECUTABLE := gitea.exe
  7. else
  8. EXECUTABLE := gitea
  9. UNAME_S := $(shell uname -s)
  10. ifeq ($(UNAME_S),Darwin)
  11. SED_INPLACE := sed -i ''
  12. endif
  13. endif
  14. BINDATA := modules/{options,public,templates}/bindata.go
  15. STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
  16. DOCKER_TAG := gitea/gitea:latest
  17. GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
  18. GOFMT ?= gofmt -s
  19. GOFLAGS := -i -v
  20. EXTRA_GOFLAGS ?=
  21. LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.Tags=$(TAGS)"
  22. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list ./... | grep -v /vendor/))
  23. SOURCES ?= $(shell find . -name "*.go" -type f)
  24. TAGS ?=
  25. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
  26. TEST_MYSQL_HOST ?= mysql:3306
  27. TEST_MYSQL_DBNAME ?= testgitea
  28. TEST_MYSQL_USERNAME ?= root
  29. TEST_MYSQL_PASSWORD ?=
  30. TEST_PGSQL_HOST ?= pgsql:5432
  31. TEST_PGSQL_DBNAME ?= testgitea
  32. TEST_PGSQL_USERNAME ?= postgres
  33. TEST_PGSQL_PASSWORD ?= postgres
  34. ifeq ($(OS), Windows_NT)
  35. EXECUTABLE := gitea.exe
  36. else
  37. EXECUTABLE := gitea
  38. endif
  39. ifneq ($(DRONE_TAG),)
  40. VERSION ?= $(subst v,,$(DRONE_TAG))
  41. else
  42. ifneq ($(DRONE_BRANCH),)
  43. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  44. else
  45. VERSION ?= master
  46. endif
  47. endif
  48. .PHONY: all
  49. all: build
  50. .PHONY: clean
  51. clean:
  52. $(GO) clean -i ./...
  53. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) integrations*.test integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-sqlite/ integrations/mysql.ini integrations/pgsql.ini
  54. required-gofmt-version:
  55. @$(GO) version | grep -q '\(1.7\|1.8\)' || { echo "We require go version 1.7 or 1.8 to format code" >&2 && exit 1; }
  56. .PHONY: fmt
  57. fmt: required-gofmt-version
  58. $(GOFMT) -w $(GOFILES)
  59. .PHONY: vet
  60. vet:
  61. $(GO) vet $(PACKAGES)
  62. .PHONY: generate
  63. generate:
  64. @hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  65. $(GO) get -u github.com/jteeuwen/go-bindata/...; \
  66. fi
  67. $(GO) generate $(PACKAGES)
  68. .PHONY: generate-swagger
  69. generate-swagger:
  70. @hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  71. $(GO) get -u github.com/go-swagger/go-swagger/cmd/swagger; \
  72. fi
  73. swagger generate spec -o ./public/swagger.v1.json
  74. $(SED_INPLACE) "s;\".ref\": \"#/definitions/GPGKey\";\"type\": \"object\";g" ./public/swagger.v1.json
  75. $(SED_INPLACE) "s;^ \".ref\": \"#/definitions/Repository\"; \"type\": \"object\";g" ./public/swagger.v1.json
  76. .PHONY: errcheck
  77. errcheck:
  78. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  79. $(GO) get -u github.com/kisielk/errcheck; \
  80. fi
  81. errcheck $(PACKAGES)
  82. .PHONY: lint
  83. lint:
  84. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  85. $(GO) get -u github.com/golang/lint/golint; \
  86. fi
  87. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  88. .PHONY: misspell-check
  89. misspell-check:
  90. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  91. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  92. fi
  93. misspell -error -i unknwon $(GOFILES)
  94. .PHONY: misspell
  95. misspell:
  96. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  97. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  98. fi
  99. misspell -w -i unknwon $(GOFILES)
  100. .PHONY: fmt-check
  101. fmt-check: required-gofmt-version
  102. # get all go files and run go fmt on them
  103. @diff=$$($(GOFMT) -d $(GOFILES)); \
  104. if [ -n "$$diff" ]; then \
  105. echo "Please run 'make fmt' and commit the result:"; \
  106. echo "$${diff}"; \
  107. exit 1; \
  108. fi;
  109. .PHONY: test
  110. test: fmt-check
  111. $(GO) test $(PACKAGES)
  112. .PHONY: coverage
  113. coverage:
  114. @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  115. $(GO) get -u github.com/wadey/gocovmerge; \
  116. fi
  117. echo "mode: set" > coverage.all
  118. for PKG in $(PACKAGES); do\
  119. egrep "$$PKG[^/]*\.go" integration.coverage.out > int.coverage.out;\
  120. gocovmerge $$GOPATH/src/$$PKG/coverage.out int.coverage.out > pkg.coverage.out;\
  121. grep -h -v "^mode:" pkg.coverage.out >> coverage.all;\
  122. mv pkg.coverage.out $$GOPATH/src/$$PKG/coverage.out;\
  123. rm int.coverage.out;\
  124. done;
  125. .PHONY: unit-test-coverage
  126. unit-test-coverage:
  127. for PKG in $(PACKAGES); do $(GO) test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
  128. .PHONY: test-vendor
  129. test-vendor:
  130. @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  131. $(GO) get -u github.com/kardianos/govendor; \
  132. fi
  133. govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused"
  134. [ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\"
  135. govendor list +outside | tee "$(TMPDIR)/wc-gitea-outside"
  136. [ $$(cat "$(TMPDIR)/wc-gitea-outside" | wc -l) -eq 0 ] || exit 1
  137. govendor status || exit 1
  138. .PHONY: test-sqlite
  139. test-sqlite: integrations.sqlite.test
  140. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  141. generate-ini:
  142. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  143. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  144. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  145. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  146. integrations/mysql.ini.tmpl > integrations/mysql.ini
  147. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  148. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  149. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  150. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  151. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  152. .PHONY: test-mysql
  153. test-mysql: integrations.mysql.test generate-ini
  154. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  155. .PHONY: test-pgsql
  156. test-pgsql: integrations.pgsql.test generate-ini
  157. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
  158. .PHONY: bench-sqlite
  159. bench-sqlite: integrations.sqlite.test
  160. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.bench .
  161. .PHONY: bench-mysql
  162. bench-mysql: integrations.mysql.test generate-ini
  163. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.bench .
  164. .PHONY: bench-pgsql
  165. bench-pgsql: integrations.pgsql.test generate-ini
  166. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.bench .
  167. .PHONY: integration-test-coverage
  168. integration-test-coverage: integrations.cover.test generate-ini
  169. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  170. integrations.mysql.test: $(SOURCES)
  171. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  172. integrations.pgsql.test: $(SOURCES)
  173. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  174. integrations.sqlite.test: $(SOURCES)
  175. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite'
  176. integrations.cover.test: $(SOURCES)
  177. $(GO) test -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  178. .PHONY: check
  179. check: test
  180. .PHONY: install
  181. install: $(wildcard *.go)
  182. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  183. .PHONY: build
  184. build: $(EXECUTABLE)
  185. $(EXECUTABLE): $(SOURCES)
  186. $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  187. .PHONY: docker
  188. docker:
  189. docker run -ti --rm -v $(CURDIR):/srv/app/src/code.gitea.io/gitea -w /srv/app/src/code.gitea.io/gitea -e TAGS="bindata $(TAGS)" webhippie/golang:edge make clean generate build
  190. docker build -t $(DOCKER_TAG) .
  191. .PHONY: release
  192. release: release-dirs release-windows release-linux release-darwin release-copy release-check
  193. .PHONY: release-dirs
  194. release-dirs:
  195. mkdir -p $(DIST)/binaries $(DIST)/release
  196. .PHONY: release-windows
  197. release-windows:
  198. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  199. $(GO) get -u github.com/karalabe/xgo; \
  200. fi
  201. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  202. ifeq ($(CI),drone)
  203. mv /build/* $(DIST)/binaries
  204. endif
  205. .PHONY: release-linux
  206. release-linux:
  207. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  208. $(GO) get -u github.com/karalabe/xgo; \
  209. fi
  210. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  211. ifeq ($(CI),drone)
  212. mv /build/* $(DIST)/binaries
  213. endif
  214. .PHONY: release-darwin
  215. release-darwin:
  216. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  217. $(GO) get -u github.com/karalabe/xgo; \
  218. fi
  219. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  220. ifeq ($(CI),drone)
  221. mv /build/* $(DIST)/binaries
  222. endif
  223. .PHONY: release-copy
  224. release-copy:
  225. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  226. .PHONY: release-check
  227. release-check:
  228. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  229. .PHONY: javascripts
  230. javascripts: public/js/index.js
  231. .IGNORE: public/js/index.js
  232. public/js/index.js: $(JAVASCRIPTS)
  233. cat $< >| $@
  234. .PHONY: stylesheets-check
  235. stylesheets-check: stylesheets
  236. @diff=$$(git diff public/css/index.css); \
  237. if [ -n "$$diff" ]; then \
  238. echo "Please run 'make stylesheets' and commit the result:"; \
  239. echo "$${diff}"; \
  240. exit 1; \
  241. fi;
  242. .PHONY: stylesheets
  243. stylesheets: public/css/index.css
  244. .IGNORE: public/css/index.css
  245. public/css/index.css: $(STYLESHEETS)
  246. @which lessc > /dev/null; if [ $$? -ne 0 ]; then \
  247. $(GO) get -u github.com/kib357/less-go/lessc; \
  248. fi
  249. lessc -i $< -o $@
  250. .PHONY: swagger-ui
  251. swagger-ui:
  252. rm -Rf public/vendor/assets/swagger-ui
  253. git clone --depth=10 -b v3.0.7 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
  254. mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
  255. rm -Rf $(TMPDIR)/swagger-ui
  256. $(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
  257. .PHONY: update-translations
  258. update-translations:
  259. mkdir -p ./translations
  260. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  261. rm ./translations/gitea.zip
  262. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  263. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  264. mv ./translations/*.ini ./options/locale/
  265. rmdir ./translations
  266. .PHONY: generate-images
  267. generate-images:
  268. mkdir -p $(TMPDIR)/images
  269. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  270. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  271. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  272. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  273. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  274. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  275. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  276. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  277. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  278. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  279. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  280. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  281. zopflipng $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  282. zopflipng $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  283. zopflipng $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  284. zopflipng $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  285. rm -f $(TMPDIR)/images/*-*.png
  286. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  287. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  288. $(PWD)/public/img/favicon.ico
  289. rm -rf $(TMPDIR)/images