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 26KB

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