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

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