You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. ifeq ($(USE_REPO_TEST_DIR),1)
  2. # This rule replaces the whole Makefile when we're trying to use /tmp repository temporary files
  3. location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
  4. self := $(location)
  5. %:
  6. @tmpdir=`mktemp --tmpdir -d` ; \
  7. echo Using temporary directory $$tmpdir for test repositories ; \
  8. USE_REPO_TEST_DIR= $(MAKE) -f $(self) --no-print-directory REPO_TEST_DIR=$$tmpdir/ $@ ; \
  9. STATUS=$$? ; rm -r "$$tmpdir" ; exit $$STATUS
  10. else
  11. # This is the "normal" part of the Makefile
  12. DIST := dist
  13. DIST_DIRS := $(DIST)/binaries $(DIST)/release
  14. IMPORT := code.gitea.io/gitea
  15. export GO111MODULE=on
  16. GO ?= go
  17. SED_INPLACE := sed -i
  18. SHASUM ?= shasum -a 256
  19. HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
  20. COMMA := ,
  21. XGO_VERSION := go-1.14.x
  22. MIN_GO_VERSION := 001012000
  23. MIN_NODE_VERSION := 010013000
  24. DOCKER_IMAGE ?= gitea/gitea
  25. DOCKER_TAG ?= latest
  26. DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)
  27. ifeq ($(HAS_GO), GO)
  28. GOPATH ?= $(shell $(GO) env GOPATH)
  29. export PATH := $(GOPATH)/bin:$(PATH)
  30. CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
  31. CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
  32. endif
  33. ifeq ($(OS), Windows_NT)
  34. EXECUTABLE ?= gitea.exe
  35. else
  36. EXECUTABLE ?= gitea
  37. UNAME_S := $(shell uname -s)
  38. ifeq ($(UNAME_S),Darwin)
  39. SED_INPLACE := sed -i ''
  40. endif
  41. ifeq ($(UNAME_S),FreeBSD)
  42. SED_INPLACE := sed -i ''
  43. endif
  44. endif
  45. GOFMT ?= gofmt -s
  46. GOFLAGS := -v
  47. EXTRA_GOFLAGS ?=
  48. MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
  49. MAKE_EVIDENCE_DIR := .make_evidence
  50. ifneq ($(RACE_ENABLED),)
  51. GOTESTFLAGS ?= -race
  52. endif
  53. STORED_VERSION_FILE := VERSION
  54. ifneq ($(DRONE_TAG),)
  55. VERSION ?= $(subst v,,$(DRONE_TAG))
  56. GITEA_VERSION ?= $(VERSION)
  57. else
  58. ifneq ($(DRONE_BRANCH),)
  59. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  60. else
  61. VERSION ?= master
  62. endif
  63. STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
  64. ifneq ($(STORED_VERSION),)
  65. GITEA_VERSION ?= $(STORED_VERSION)
  66. else
  67. GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  68. endif
  69. endif
  70. LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  71. GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list -mod=vendor ./... | grep -v /vendor/)))
  72. FOMANTIC_CONFIGS := semantic.json web_src/fomantic/theme.config.less web_src/fomantic/_site/globals/site.variables
  73. FOMANTIC_DEST := web_src/fomantic/build/semantic.js web_src/fomantic/build/semantic.css
  74. FOMANTIC_DEST_DIR := web_src/fomantic/build
  75. WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f) $(FOMANTIC_DEST)
  76. WEBPACK_CONFIGS := webpack.config.js
  77. WEBPACK_DEST := public/js/index.js public/css/index.css
  78. WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/serviceworker.js
  79. BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
  80. BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
  81. SVG_DEST_DIR := public/img/svg
  82. AIR_TMP_DIR := .air
  83. TAGS ?=
  84. TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
  85. TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
  86. GO_DIRS := cmd integrations models modules routers build services vendor
  87. GO_SOURCES := $(wildcard *.go)
  88. GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go)
  89. ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
  90. GO_SOURCES += $(BINDATA_DEST)
  91. endif
  92. GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
  93. #To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
  94. SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
  95. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  96. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
  97. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
  98. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  99. TEST_MYSQL_HOST ?= mysql:3306
  100. TEST_MYSQL_DBNAME ?= testgitea
  101. TEST_MYSQL_USERNAME ?= root
  102. TEST_MYSQL_PASSWORD ?=
  103. TEST_MYSQL8_HOST ?= mysql8:3306
  104. TEST_MYSQL8_DBNAME ?= testgitea
  105. TEST_MYSQL8_USERNAME ?= root
  106. TEST_MYSQL8_PASSWORD ?=
  107. TEST_PGSQL_HOST ?= pgsql:5432
  108. TEST_PGSQL_DBNAME ?= testgitea
  109. TEST_PGSQL_USERNAME ?= postgres
  110. TEST_PGSQL_PASSWORD ?= postgres
  111. TEST_PGSQL_SCHEMA ?= gtestschema
  112. TEST_MSSQL_HOST ?= mssql:1433
  113. TEST_MSSQL_DBNAME ?= gitea
  114. TEST_MSSQL_USERNAME ?= sa
  115. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  116. .PHONY: all
  117. all: build
  118. .PHONY: help
  119. help:
  120. @echo "Make Routines:"
  121. @echo " - \"\" equivalent to \"build\""
  122. @echo " - build build everything"
  123. @echo " - frontend build frontend files"
  124. @echo " - backend build backend files"
  125. @echo " - clean delete backend and integration files"
  126. @echo " - clean-all delete backend, frontend and integration files"
  127. @echo " - lint lint everything"
  128. @echo " - lint-frontend lint frontend files"
  129. @echo " - lint-backend lint backend files"
  130. @echo " - watch-frontend watch frontend files and continuously rebuild"
  131. @echo " - watch-backend watch backend files and continuously rebuild"
  132. @echo " - webpack build webpack files"
  133. @echo " - svg build svg files"
  134. @echo " - fomantic build fomantic files"
  135. @echo " - generate run \"go generate\""
  136. @echo " - fmt format the Go code"
  137. @echo " - generate-swagger generate the swagger spec from code comments"
  138. @echo " - swagger-validate check if the swagger spec is valid"
  139. @echo " - golangci-lint run golangci-lint linter"
  140. @echo " - revive run revive linter"
  141. @echo " - misspell check for misspellings"
  142. @echo " - vet examines Go source code and reports suspicious constructs"
  143. @echo " - test[\#TestSpecificName] run unit test"
  144. @echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
  145. @echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
  146. .PHONY: go-check
  147. go-check:
  148. $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
  149. @if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
  150. echo "Gitea requires Go 1.12 or greater to build. You can get it at https://golang.org/dl/"; \
  151. exit 1; \
  152. fi
  153. .PHONY: git-check
  154. git-check:
  155. @if git lfs >/dev/null 2>&1 ; then : ; else \
  156. echo "Gitea requires git with lfs support to run tests." ; \
  157. exit 1; \
  158. fi
  159. .PHONY: node-check
  160. node-check:
  161. $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | cut -c2- | tr '.' ' ');))
  162. $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
  163. @if [ "$(NODE_VERSION)" -lt "$(MIN_NODE_VERSION)" -o "$(NPM_MISSING)" = "1" ]; then \
  164. echo "Gitea requires Node.js 10 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
  165. exit 1; \
  166. fi
  167. .PHONY: clean-all
  168. clean-all: clean
  169. rm -rf $(WEBPACK_DEST_ENTRIES) $(FOMANTIC_DEST_DIR)
  170. .PHONY: clean
  171. clean:
  172. $(GO) clean -i ./...
  173. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
  174. integrations*.test \
  175. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
  176. integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
  177. integrations/indexers-mssql integrations/mysql.ini integrations/mysql8.ini integrations/pgsql.ini integrations/mssql.ini
  178. .PHONY: fmt
  179. fmt:
  180. $(GOFMT) -w $(GO_SOURCES_OWN)
  181. .PHONY: vet
  182. vet:
  183. # Default vet
  184. $(GO) vet $(GO_PACKAGES)
  185. # Custom vet
  186. $(GO) build -mod=vendor gitea.com/jolheiser/gitea-vet
  187. $(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
  188. .PHONY: $(TAGS_EVIDENCE)
  189. $(TAGS_EVIDENCE):
  190. @mkdir -p $(MAKE_EVIDENCE_DIR)
  191. @echo "$(TAGS)" > $(TAGS_EVIDENCE)
  192. ifneq "$(TAGS)" "$(shell cat $(TAGS_EVIDENCE) 2>/dev/null)"
  193. TAGS_PREREQ := $(TAGS_EVIDENCE)
  194. endif
  195. .PHONY: generate-swagger
  196. generate-swagger:
  197. $(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
  198. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  199. $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
  200. .PHONY: swagger-check
  201. swagger-check: generate-swagger
  202. @diff=$$(git diff '$(SWAGGER_SPEC)'); \
  203. if [ -n "$$diff" ]; then \
  204. echo "Please run 'make generate-swagger' and commit the result:"; \
  205. echo "$${diff}"; \
  206. exit 1; \
  207. fi;
  208. .PHONY: swagger-validate
  209. swagger-validate:
  210. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  211. $(SWAGGER) validate './$(SWAGGER_SPEC)'
  212. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  213. .PHONY: errcheck
  214. errcheck:
  215. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  216. GO111MODULE=off $(GO) get -u github.com/kisielk/errcheck; \
  217. fi
  218. errcheck $(GO_PACKAGES)
  219. .PHONY: revive
  220. revive:
  221. GO111MODULE=on $(GO) run -mod=vendor build/lint.go -config .revive.toml -exclude=./vendor/... ./... || exit 1
  222. .PHONY: misspell-check
  223. misspell-check:
  224. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  225. GO111MODULE=off $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  226. fi
  227. misspell -error -i unknwon,destory $(GO_SOURCES_OWN)
  228. .PHONY: misspell
  229. misspell:
  230. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  231. GO111MODULE=off $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  232. fi
  233. misspell -w -i unknwon $(GO_SOURCES_OWN)
  234. .PHONY: fmt-check
  235. fmt-check:
  236. # get all go files and run go fmt on them
  237. @diff=$$($(GOFMT) -d $(GO_SOURCES_OWN)); \
  238. if [ -n "$$diff" ]; then \
  239. echo "Please run 'make fmt' and commit the result:"; \
  240. echo "$${diff}"; \
  241. exit 1; \
  242. fi;
  243. .PHONY: lint
  244. lint: lint-backend lint-frontend
  245. .PHONY: lint-backend
  246. lint-backend: golangci-lint revive vet swagger-check swagger-validate test-vendor
  247. .PHONY: lint-frontend
  248. lint-frontend: node_modules svg-check
  249. npx eslint web_src/js build webpack.config.js
  250. npx stylelint web_src/less
  251. .PHONY: watch-frontend
  252. watch-frontend: node-check $(FOMANTIC_DEST) node_modules
  253. rm -rf $(WEBPACK_DEST_ENTRIES)
  254. NODE_ENV=development npx webpack --hide-modules --display-entrypoints=false --watch --progress
  255. .PHONY: watch-backend
  256. watch-backend: go-check
  257. @hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  258. GO111MODULE=off $(GO) get -u github.com/cosmtrek/air; \
  259. fi
  260. air -c .air.conf
  261. .PHONY: test
  262. test:
  263. $(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' $(GO_PACKAGES)
  264. .PHONY: test-check
  265. test-check:
  266. @echo "Checking if tests have changed the source tree...";
  267. @diff=$$(git status -s); \
  268. if [ -n "$$diff" ]; then \
  269. echo "make test has changed files in the source tree:"; \
  270. echo "$${diff}"; \
  271. echo "You should change the tests to create these files in a temporary directory."; \
  272. echo "Do not simply add these files to .gitignore"; \
  273. exit 1; \
  274. fi;
  275. .PHONY: test\#%
  276. test\#%:
  277. $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -run $(subst .,/,$*) $(GO_PACKAGES)
  278. .PHONY: coverage
  279. coverage:
  280. GO111MODULE=on $(GO) run -mod=vendor build/gocovmerge.go integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all
  281. .PHONY: unit-test-coverage
  282. unit-test-coverage:
  283. $(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  284. .PHONY: vendor
  285. vendor:
  286. $(GO) mod tidy && $(GO) mod vendor
  287. .PHONY: test-vendor
  288. test-vendor: vendor
  289. @diff=$$(git diff vendor/); \
  290. if [ -n "$$diff" ]; then \
  291. echo "Please run 'make vendor' and commit the result:"; \
  292. echo "$${diff}"; \
  293. exit 1; \
  294. fi;
  295. generate-ini-sqlite:
  296. sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  297. integrations/sqlite.ini.tmpl > integrations/sqlite.ini
  298. .PHONY: test-sqlite
  299. test-sqlite: integrations.sqlite.test generate-ini-sqlite
  300. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  301. .PHONY: test-sqlite\#%
  302. test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
  303. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*)
  304. .PHONY: test-sqlite-migration
  305. test-sqlite-migration: migrations.sqlite.test generate-ini-sqlite
  306. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  307. generate-ini-mysql:
  308. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  309. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  310. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  311. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  312. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  313. integrations/mysql.ini.tmpl > integrations/mysql.ini
  314. .PHONY: test-mysql
  315. test-mysql: integrations.mysql.test generate-ini-mysql
  316. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  317. .PHONY: test-mysql\#%
  318. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  319. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.run $(subst .,/,$*)
  320. .PHONY: test-mysql-migration
  321. test-mysql-migration: migrations.mysql.test generate-ini-mysql
  322. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.mysql.test
  323. generate-ini-mysql8:
  324. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  325. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  326. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  327. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  328. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  329. integrations/mysql8.ini.tmpl > integrations/mysql8.ini
  330. .PHONY: test-mysql8
  331. test-mysql8: integrations.mysql8.test generate-ini-mysql8
  332. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test
  333. .PHONY: test-mysql8\#%
  334. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  335. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test -test.run $(subst .,/,$*)
  336. .PHONY: test-mysql8-migration
  337. test-mysql8-migration: migrations.mysql8.test generate-ini-mysql8
  338. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./migrations.mysql8.test
  339. generate-ini-pgsql:
  340. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  341. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  342. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  343. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  344. -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
  345. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  346. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  347. .PHONY: test-pgsql
  348. test-pgsql: integrations.pgsql.test generate-ini-pgsql
  349. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
  350. .PHONY: test-pgsql\#%
  351. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  352. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.run $(subst .,/,$*)
  353. .PHONY: test-pgsql-migration
  354. test-pgsql-migration: migrations.pgsql.test generate-ini-pgsql
  355. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.pgsql.test
  356. generate-ini-mssql:
  357. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  358. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  359. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  360. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  361. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  362. integrations/mssql.ini.tmpl > integrations/mssql.ini
  363. .PHONY: test-mssql
  364. test-mssql: integrations.mssql.test generate-ini-mssql
  365. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test
  366. .PHONY: test-mssql\#%
  367. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  368. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.run $(subst .,/,$*)
  369. .PHONY: test-mssql-migration
  370. test-mssql-migration: migrations.mssql.test generate-ini-mssql
  371. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test
  372. .PHONY: bench-sqlite
  373. bench-sqlite: integrations.sqlite.test generate-ini-sqlite
  374. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  375. .PHONY: bench-mysql
  376. bench-mysql: integrations.mysql.test generate-ini-mysql
  377. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  378. .PHONY: bench-mssql
  379. bench-mssql: integrations.mssql.test generate-ini-mssql
  380. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  381. .PHONY: bench-pgsql
  382. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  383. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  384. .PHONY: integration-test-coverage
  385. integration-test-coverage: integrations.cover.test generate-ini-mysql
  386. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  387. integrations.mysql.test: git-check $(GO_SOURCES)
  388. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  389. integrations.mysql8.test: git-check $(GO_SOURCES)
  390. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
  391. integrations.pgsql.test: git-check $(GO_SOURCES)
  392. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  393. integrations.mssql.test: git-check $(GO_SOURCES)
  394. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
  395. integrations.sqlite.test: git-check $(GO_SOURCES)
  396. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  397. integrations.cover.test: git-check $(GO_SOURCES)
  398. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(GO_PACKAGES) | tr ' ' ',') -o integrations.cover.test
  399. .PHONY: migrations.mysql.test
  400. migrations.mysql.test: $(GO_SOURCES)
  401. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
  402. .PHONY: migrations.mysql8.test
  403. migrations.mysql8.test: $(GO_SOURCES)
  404. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
  405. .PHONY: migrations.pgsql.test
  406. migrations.pgsql.test: $(GO_SOURCES)
  407. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
  408. .PHONY: migrations.mssql.test
  409. migrations.mssql.test: $(GO_SOURCES)
  410. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
  411. .PHONY: migrations.sqlite.test
  412. migrations.sqlite.test: $(GO_SOURCES)
  413. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  414. .PHONY: check
  415. check: test
  416. .PHONY: install $(TAGS_PREREQ)
  417. install: $(wildcard *.go)
  418. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  419. .PHONY: build
  420. build: frontend backend
  421. .PHONY: frontend
  422. frontend: node-check $(FOMANTIC_DEST) $(WEBPACK_DEST)
  423. .PHONY: backend
  424. backend: go-check generate $(EXECUTABLE)
  425. .PHONY: generate
  426. generate: $(TAGS_PREREQ)
  427. CC= GOOS= GOARCH= $(GO) generate -mod=vendor -tags '$(TAGS)' $(GO_PACKAGES)
  428. $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
  429. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  430. .PHONY: release
  431. release: frontend generate release-windows release-linux release-darwin release-copy release-compress release-sources release-docs release-check
  432. $(DIST_DIRS):
  433. mkdir -p $(DIST_DIRS)
  434. .PHONY: release-windows
  435. release-windows: | $(DIST_DIRS)
  436. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  437. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  438. fi
  439. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  440. ifeq ($(CI),drone)
  441. cp /build/* $(DIST)/binaries
  442. endif
  443. .PHONY: release-linux
  444. release-linux: | $(DIST_DIRS)
  445. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  446. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  447. fi
  448. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/mips64le,linux/mips,linux/mipsle' -out gitea-$(VERSION) .
  449. ifeq ($(CI),drone)
  450. cp /build/* $(DIST)/binaries
  451. endif
  452. .PHONY: release-darwin
  453. release-darwin: | $(DIST_DIRS)
  454. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  455. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  456. fi
  457. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  458. ifeq ($(CI),drone)
  459. cp /build/* $(DIST)/binaries
  460. endif
  461. .PHONY: release-copy
  462. release-copy: | $(DIST_DIRS)
  463. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  464. .PHONY: release-check
  465. release-check: | $(DIST_DIRS)
  466. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  467. .PHONY: release-compress
  468. release-compress: | $(DIST_DIRS)
  469. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  470. GO111MODULE=off $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  471. fi
  472. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  473. .PHONY: release-sources
  474. release-sources: | $(DIST_DIRS) node_modules
  475. echo $(VERSION) > $(STORED_VERSION_FILE)
  476. tar --exclude=./$(DIST) --exclude=./.git --exclude=./$(MAKE_EVIDENCE_DIR) --exclude=./node_modules/.cache --exclude=./$(AIR_TMP_DIR) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
  477. rm -f $(STORED_VERSION_FILE)
  478. .PHONY: release-docs
  479. release-docs: | $(DIST_DIRS) docs
  480. tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs/public .
  481. .PHONY: docs
  482. docs:
  483. @hash hugo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  484. $(GO) get -u github.com/gohugoio/hugo; \
  485. fi
  486. cd docs; make trans-copy clean build-offline;
  487. node_modules: package-lock.json
  488. npm install --no-save
  489. @touch node_modules
  490. .PHONY: npm-update
  491. npm-update: node-check | node_modules
  492. npx updates -cu
  493. rm -rf node_modules package-lock.json
  494. npm install --package-lock
  495. .PHONY: fomantic
  496. fomantic: $(FOMANTIC_DEST)
  497. $(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) | node_modules
  498. rm -rf $(FOMANTIC_DEST_DIR)
  499. cp web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
  500. cp -r web_src/fomantic/_site/* node_modules/fomantic-ui/src/_site/
  501. npx gulp -f node_modules/fomantic-ui/gulpfile.js build
  502. @touch $(FOMANTIC_DEST)
  503. .PHONY: webpack
  504. webpack: $(WEBPACK_DEST)
  505. $(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json | node_modules
  506. rm -rf $(WEBPACK_DEST_ENTRIES)
  507. npx webpack --hide-modules --display-entrypoints=false
  508. @touch $(WEBPACK_DEST)
  509. .PHONY: svg
  510. svg: node-check | node_modules
  511. rm -rf $(SVG_DEST_DIR)
  512. node build/generate-svg.js
  513. .PHONY: svg-check
  514. svg-check: svg
  515. @git add $(SVG_DEST_DIR)
  516. @diff=$$(git diff --cached $(SVG_DEST_DIR)); \
  517. if [ -n "$$diff" ]; then \
  518. echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \
  519. echo "$${diff}"; \
  520. exit 1; \
  521. fi;
  522. .PHONY: update-translations
  523. update-translations:
  524. mkdir -p ./translations
  525. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  526. rm ./translations/gitea.zip
  527. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  528. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  529. mv ./translations/*.ini ./options/locale/
  530. rmdir ./translations
  531. .PHONY: generate-images
  532. generate-images:
  533. npm install --no-save --no-package-lock xmldom fabric imagemin-zopfli
  534. node build/generate-images.js
  535. .PHONY: pr\#%
  536. pr\#%: clean-all
  537. $(GO) run contrib/pr/checkout.go $*
  538. .PHONY: golangci-lint
  539. golangci-lint:
  540. @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  541. export BINARY="golangci-lint"; \
  542. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.24.0; \
  543. fi
  544. golangci-lint run --timeout 5m
  545. .PHONY: docker
  546. docker:
  547. docker build --disable-content-trust=false -t $(DOCKER_REF) .
  548. # support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .
  549. .PHONY: docker-build
  550. docker-build:
  551. 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)" LDFLAGS="$(LDFLAGS)" CGO_EXTRA_CFLAGS="$(CGO_EXTRA_CFLAGS)" webhippie/golang:edge make clean build
  552. # This endif closes the if at the top of the file
  553. endif