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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. DIST := dist
  2. IMPORT := code.gitea.io/gitea
  3. export GO111MODULE=off
  4. GO ?= go
  5. SED_INPLACE := sed -i
  6. SHASUM ?= shasum -a 256
  7. export PATH := $($(GO) env GOPATH)/bin:$(PATH)
  8. ifeq ($(OS), Windows_NT)
  9. EXECUTABLE ?= gitea.exe
  10. else
  11. EXECUTABLE ?= gitea
  12. UNAME_S := $(shell uname -s)
  13. ifeq ($(UNAME_S),Darwin)
  14. SED_INPLACE := sed -i ''
  15. endif
  16. ifeq ($(UNAME_S),FreeBSD)
  17. SED_INPLACE := sed -i ''
  18. endif
  19. endif
  20. GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
  21. GOFMT ?= gofmt -s
  22. GOFLAGS := -v
  23. EXTRA_GOFLAGS ?=
  24. MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
  25. STORED_VERSION_FILE := VERSION
  26. ifneq ($(DRONE_TAG),)
  27. VERSION ?= $(subst v,,$(DRONE_TAG))
  28. GITEA_VERSION ?= $(VERSION)
  29. else
  30. ifneq ($(DRONE_BRANCH),)
  31. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  32. else
  33. VERSION ?= master
  34. endif
  35. STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
  36. ifneq ($(STORED_VERSION),)
  37. GITEA_VERSION ?= $(STORED_VERSION)
  38. else
  39. GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  40. endif
  41. endif
  42. LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  43. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell GO111MODULE=on $(GO) list -mod=vendor ./... | grep -v /vendor/)))
  44. GO_SOURCES ?= $(shell find . -name "*.go" -type f)
  45. JS_SOURCES ?= $(shell find web_src/js web_src/css -type f)
  46. CSS_SOURCES ?= $(shell find web_src/less -type f)
  47. JS_DEST := public/js/index.js
  48. CSS_DEST := public/css/index.css
  49. BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
  50. JS_DEST_DIR := public/js
  51. CSS_DEST_DIR := public/css
  52. TAGS ?=
  53. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
  54. #To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
  55. SWAGGER := GO111MODULE=on $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
  56. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  57. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
  58. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
  59. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  60. TEST_MYSQL_HOST ?= mysql:3306
  61. TEST_MYSQL_DBNAME ?= testgitea
  62. TEST_MYSQL_USERNAME ?= root
  63. TEST_MYSQL_PASSWORD ?=
  64. TEST_MYSQL8_HOST ?= mysql8:3306
  65. TEST_MYSQL8_DBNAME ?= testgitea
  66. TEST_MYSQL8_USERNAME ?= root
  67. TEST_MYSQL8_PASSWORD ?=
  68. TEST_PGSQL_HOST ?= pgsql:5432
  69. TEST_PGSQL_DBNAME ?= testgitea
  70. TEST_PGSQL_USERNAME ?= postgres
  71. TEST_PGSQL_PASSWORD ?= postgres
  72. TEST_MSSQL_HOST ?= mssql:1433
  73. TEST_MSSQL_DBNAME ?= gitea
  74. TEST_MSSQL_USERNAME ?= sa
  75. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  76. # $(call strip-suffix,filename)
  77. strip-suffix = $(firstword $(subst ., ,$(1)))
  78. .PHONY: all
  79. all: build
  80. include docker/Makefile
  81. .PHONY: help
  82. help:
  83. @echo "Make Routines:"
  84. @echo " - \"\" equivalent to \"build\""
  85. @echo " - build build everything"
  86. @echo " - frontend build frontend files"
  87. @echo " - backend build backend files"
  88. @echo " - clean delete backend and integration files"
  89. @echo " - clean-all delete backend, frontend and integration files"
  90. @echo " - css rebuild only css files"
  91. @echo " - js rebuild only js files"
  92. @echo " - generate run \"go generate\""
  93. @echo " - fmt format the Go code"
  94. @echo " - generate-swagger generate the swagger spec from code comments"
  95. @echo " - swagger-validate check if the swagger spec is valide"
  96. @echo " - revive run code linter revive"
  97. @echo " - misspell check if a word is written wrong"
  98. @echo " - vet examines Go source code and reports suspicious constructs"
  99. @echo " - test run unit test"
  100. @echo " - test-sqlite run integration test for sqlite"
  101. .PHONY: go-check
  102. go-check:
  103. $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?[[:space:]]' | tr '.' ' ');))
  104. @if [ "$(GO_VERSION)" -lt "001011000" ]; then \
  105. echo "Gitea requires Go 1.11.0 or greater to build. You can get it at https://golang.org/dl/"; \
  106. exit 1; \
  107. fi
  108. .PHONY: git-check
  109. git-check:
  110. @if git lfs >/dev/null 2>&1 ; then : ; else \
  111. echo "Gitea requires git with lfs support to run tests." ; \
  112. exit 1; \
  113. fi
  114. .PHONY: node-check
  115. node-check:
  116. $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?' | tr '.' ' ');))
  117. $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
  118. @if [ "$(NODE_VERSION)" -lt "010000000" -o "$(NPM_MISSING)" = "1" ]; then \
  119. echo "Gitea requires Node.js 10.0.0 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
  120. exit 1; \
  121. fi
  122. .PHONY: clean-all
  123. clean-all: clean
  124. rm -rf $(JS_DEST_DIR) $(CSS_DEST_DIR)
  125. .PHONY: clean
  126. clean:
  127. $(GO) clean -i ./...
  128. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) \
  129. integrations*.test \
  130. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
  131. integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
  132. integrations/indexers-mssql integrations/mysql.ini integrations/mysql8.ini integrations/pgsql.ini integrations/mssql.ini
  133. .PHONY: fmt
  134. fmt:
  135. $(GOFMT) -w $(GOFILES)
  136. .PHONY: vet
  137. vet:
  138. $(GO) vet $(PACKAGES)
  139. .PHONY: generate-swagger
  140. generate-swagger:
  141. $(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
  142. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  143. $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
  144. .PHONY: swagger-check
  145. swagger-check: generate-swagger
  146. @diff=$$(git diff '$(SWAGGER_SPEC)'); \
  147. if [ -n "$$diff" ]; then \
  148. echo "Please run 'make generate-swagger' and commit the result:"; \
  149. echo "$${diff}"; \
  150. exit 1; \
  151. fi;
  152. .PHONY: swagger-validate
  153. swagger-validate:
  154. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  155. $(SWAGGER) validate './$(SWAGGER_SPEC)'
  156. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  157. .PHONY: errcheck
  158. errcheck:
  159. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  160. $(GO) get -u github.com/kisielk/errcheck; \
  161. fi
  162. errcheck $(PACKAGES)
  163. .PHONY: lint
  164. lint:
  165. @echo 'make lint is depricated. Use "make revive" if you want to use the old lint tool, or "make golangci-lint" to run a complete code check.'
  166. .PHONY: revive
  167. revive:
  168. @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  169. $(GO) get -u github.com/mgechev/revive; \
  170. fi
  171. revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
  172. .PHONY: misspell-check
  173. misspell-check:
  174. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  175. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  176. fi
  177. misspell -error -i unknwon,destory $(GOFILES)
  178. .PHONY: misspell
  179. misspell:
  180. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  181. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  182. fi
  183. misspell -w -i unknwon $(GOFILES)
  184. .PHONY: fmt-check
  185. fmt-check:
  186. # get all go files and run go fmt on them
  187. @diff=$$($(GOFMT) -d $(GOFILES)); \
  188. if [ -n "$$diff" ]; then \
  189. echo "Please run 'make fmt' and commit the result:"; \
  190. echo "$${diff}"; \
  191. exit 1; \
  192. fi;
  193. .PHONY: test
  194. test:
  195. GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
  196. .PHONY: test\#%
  197. test\#%:
  198. GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -run $* $(PACKAGES)
  199. .PHONY: coverage
  200. coverage:
  201. @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  202. $(GO) get -u github.com/wadey/gocovmerge; \
  203. fi
  204. gocovmerge integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all;\
  205. .PHONY: unit-test-coverage
  206. unit-test-coverage:
  207. GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  208. .PHONY: vendor
  209. vendor:
  210. GO111MODULE=on $(GO) mod tidy && GO111MODULE=on $(GO) mod vendor
  211. .PHONY: test-vendor
  212. test-vendor: vendor
  213. @diff=$$(git diff vendor/); \
  214. if [ -n "$$diff" ]; then \
  215. echo "Please run 'make vendor' and commit the result:"; \
  216. echo "$${diff}"; \
  217. exit 1; \
  218. fi;
  219. .PHONY: test-sqlite
  220. test-sqlite: integrations.sqlite.test
  221. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  222. .PHONY: test-sqlite\#%
  223. test-sqlite\#%: integrations.sqlite.test
  224. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $*
  225. .PHONY: test-sqlite-migration
  226. test-sqlite-migration: migrations.sqlite.test
  227. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  228. generate-ini-mysql:
  229. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  230. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  231. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  232. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  233. integrations/mysql.ini.tmpl > integrations/mysql.ini
  234. .PHONY: test-mysql
  235. test-mysql: integrations.mysql.test generate-ini-mysql
  236. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  237. .PHONY: test-mysql\#%
  238. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  239. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.run $*
  240. .PHONY: test-mysql-migration
  241. test-mysql-migration: migrations.mysql.test generate-ini-mysql
  242. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.mysql.test
  243. generate-ini-mysql8:
  244. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  245. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  246. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  247. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  248. integrations/mysql8.ini.tmpl > integrations/mysql8.ini
  249. .PHONY: test-mysql8
  250. test-mysql8: integrations.mysql8.test generate-ini-mysql8
  251. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test
  252. .PHONY: test-mysql8\#%
  253. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  254. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test -test.run $*
  255. .PHONY: test-mysql8-migration
  256. test-mysql8-migration: migrations.mysql8.test generate-ini-mysql8
  257. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./migrations.mysql8.test
  258. generate-ini-pgsql:
  259. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  260. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  261. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  262. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  263. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  264. .PHONY: test-pgsql
  265. test-pgsql: integrations.pgsql.test generate-ini-pgsql
  266. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
  267. .PHONY: test-pgsql\#%
  268. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  269. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.run $*
  270. .PHONY: test-pgsql-migration
  271. test-pgsql-migration: migrations.pgsql.test generate-ini-pgsql
  272. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.pgsql.test
  273. generate-ini-mssql:
  274. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  275. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  276. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  277. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  278. integrations/mssql.ini.tmpl > integrations/mssql.ini
  279. .PHONY: test-mssql
  280. test-mssql: integrations.mssql.test generate-ini-mssql
  281. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test
  282. .PHONY: test-mssql\#%
  283. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  284. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.run $*
  285. .PHONY: test-mssql-migration
  286. test-mssql-migration: migrations.mssql.test generate-ini-mssql
  287. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test
  288. .PHONY: bench-sqlite
  289. bench-sqlite: integrations.sqlite.test
  290. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  291. .PHONY: bench-mysql
  292. bench-mysql: integrations.mysql.test generate-ini-mysql
  293. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  294. .PHONY: bench-mssql
  295. bench-mssql: integrations.mssql.test generate-ini-mssql
  296. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  297. .PHONY: bench-pgsql
  298. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  299. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  300. .PHONY: integration-test-coverage
  301. integration-test-coverage: integrations.cover.test generate-ini-mysql
  302. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  303. integrations.mysql.test: $(GO_SOURCES)
  304. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  305. integrations.mysql8.test: $(GO_SOURCES)
  306. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
  307. integrations.pgsql.test: $(GO_SOURCES)
  308. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  309. integrations.mssql.test: $(GO_SOURCES)
  310. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
  311. integrations.sqlite.test: $(GO_SOURCES)
  312. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  313. integrations.cover.test: git-check $(GO_SOURCES)
  314. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  315. .PHONY: migrations.mysql.test
  316. migrations.mysql.test: $(GO_SOURCES)
  317. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
  318. .PHONY: migrations.mysql8.test
  319. migrations.mysql8.test: $(GO_SOURCES)
  320. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
  321. .PHONY: migrations.pgsql.test
  322. migrations.pgsql.test: $(GO_SOURCES)
  323. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
  324. .PHONY: migrations.mssql.test
  325. migrations.mssql.test: $(GO_SOURCES)
  326. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
  327. .PHONY: migrations.sqlite.test
  328. migrations.sqlite.test: $(GO_SOURCES)
  329. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  330. .PHONY: check
  331. check: test
  332. .PHONY: install
  333. install: $(wildcard *.go)
  334. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  335. .PHONY: build
  336. build: frontend backend
  337. .PHONY: frontend
  338. frontend: node-check js css
  339. .PHONY: backend
  340. backend: go-check generate $(EXECUTABLE)
  341. .PHONY: generate
  342. generate:
  343. GO111MODULE=on $(GO) generate -mod=vendor $(PACKAGES)
  344. $(EXECUTABLE): $(GO_SOURCES)
  345. GO111MODULE=on $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  346. .PHONY: release
  347. release: frontend generate release-dirs release-windows release-linux release-darwin release-copy release-compress release-sources release-check
  348. .PHONY: release-dirs
  349. release-dirs:
  350. mkdir -p $(DIST)/binaries $(DIST)/release
  351. .PHONY: release-windows
  352. release-windows:
  353. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  354. $(GO) get -u src.techknowlogick.com/xgo; \
  355. fi
  356. xgo -go go-1.13 -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  357. ifeq ($(CI),drone)
  358. cp /build/* $(DIST)/binaries
  359. endif
  360. .PHONY: release-linux
  361. release-linux:
  362. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  363. $(GO) get -u src.techknowlogick.com/xgo; \
  364. fi
  365. xgo -go go-1.13 -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) .
  366. ifeq ($(CI),drone)
  367. cp /build/* $(DIST)/binaries
  368. endif
  369. .PHONY: release-darwin
  370. release-darwin:
  371. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  372. $(GO) get -u src.techknowlogick.com/xgo; \
  373. fi
  374. xgo -go go-1.13 -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  375. ifeq ($(CI),drone)
  376. cp /build/* $(DIST)/binaries
  377. endif
  378. .PHONY: release-copy
  379. release-copy:
  380. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  381. .PHONY: release-check
  382. release-check:
  383. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  384. .PHONY: release-compress
  385. release-compress:
  386. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  387. $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  388. fi
  389. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  390. .PHONY: release-sources
  391. release-sources: | node_modules
  392. echo $(VERSION) > $(STORED_VERSION_FILE)
  393. tar --exclude=./$(DIST) --exclude=./.git --exclude=./node_modules/.cache -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
  394. rm -f $(STORED_VERSION_FILE)
  395. node_modules: package-lock.json
  396. npm install --no-save
  397. .PHONY: npm-update
  398. npm-update: node-check node_modules
  399. npx updates -cu
  400. rm -rf node_modules package-lock.json
  401. npm install --package-lock
  402. .PHONY: js
  403. js: node-check $(JS_DEST)
  404. $(JS_DEST): node_modules $(JS_SOURCES)
  405. npx eslint web_src/js webpack.config.js
  406. npx webpack
  407. .PHONY: css
  408. css: node-check $(CSS_DEST)
  409. $(CSS_DEST): node_modules $(CSS_SOURCES)
  410. npx stylelint web_src/less
  411. npx lessc web_src/less/index.less public/css/index.css
  412. $(foreach file, $(filter-out web_src/less/themes/_base.less, $(wildcard web_src/less/themes/*)),npx lessc web_src/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)
  413. npx postcss --use autoprefixer --use cssnano --no-map --replace public/css/*
  414. .PHONY: javascripts
  415. javascripts:
  416. echo "'make javascripts' is deprecated, please use 'make js'"
  417. $(MAKE) js
  418. .PHONY: stylesheets-check
  419. stylesheets-check:
  420. echo "'make stylesheets-check' is deprecated, please use 'make css'"
  421. $(MAKE) css
  422. .PHONY: generate-stylesheets
  423. generate-stylesheets:
  424. echo "'make generate-stylesheets' is deprecated, please use 'make css'"
  425. $(MAKE) css
  426. .PHONY: swagger-ui
  427. swagger-ui:
  428. rm -Rf public/vendor/assets/swagger-ui
  429. git clone --depth=10 -b v3.13.4 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
  430. mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
  431. rm -Rf $(TMPDIR)/swagger-ui
  432. $(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../../swagger.v1.json;g" public/vendor/assets/swagger-ui/index.html
  433. .PHONY: update-translations
  434. update-translations:
  435. mkdir -p ./translations
  436. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  437. rm ./translations/gitea.zip
  438. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  439. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  440. mv ./translations/*.ini ./options/locale/
  441. rmdir ./translations
  442. .PHONY: generate-images
  443. generate-images:
  444. mkdir -p $(TMPDIR)/images
  445. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  446. inkscape -f $(PWD)/assets/logo.svg -w 512 -h 512 -e $(PWD)/public/img/gitea-512.png
  447. inkscape -f $(PWD)/assets/logo.svg -w 192 -h 192 -e $(PWD)/public/img/gitea-192.png
  448. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  449. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  450. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  451. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  452. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  453. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  454. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  455. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  456. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  457. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  458. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  459. zopflipng -m -y $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  460. zopflipng -m -y $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  461. zopflipng -m -y $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  462. zopflipng -m -y $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  463. rm -f $(TMPDIR)/images/*-*.png
  464. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  465. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  466. $(PWD)/public/img/favicon.ico
  467. rm -rf $(TMPDIR)/images
  468. $(foreach file, $(shell find public/img -type f -name '*.png'),zopflipng -m -y $(file) $(file);)
  469. .PHONY: pr
  470. pr:
  471. $(GO) run contrib/pr/checkout.go $(PR)
  472. .PHONY: golangci-lint
  473. golangci-lint:
  474. @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  475. export BINARY="golangci-lint"; \
  476. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.20.0; \
  477. fi
  478. golangci-lint run --timeout 5m