選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Makefile 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. DIST := dist
  2. IMPORT := code.gitea.io/gitea
  3. GO ?= go
  4. SED_INPLACE := sed -i
  5. export PATH := $($(GO) env GOPATH)/bin:$(PATH)
  6. ifeq ($(OS), Windows_NT)
  7. EXECUTABLE := gitea.exe
  8. else
  9. EXECUTABLE := gitea
  10. UNAME_S := $(shell uname -s)
  11. ifeq ($(UNAME_S),Darwin)
  12. SED_INPLACE := sed -i ''
  13. endif
  14. endif
  15. BINDATA := modules/{options,public,templates}/bindata.go
  16. GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
  17. GOFMT ?= gofmt -s
  18. GOFLAGS := -i -v
  19. EXTRA_GOFLAGS ?=
  20. ifneq ($(DRONE_TAG),)
  21. VERSION ?= $(subst v,,$(DRONE_TAG))
  22. GITEA_VERSION := $(VERSION)
  23. else
  24. ifneq ($(DRONE_BRANCH),)
  25. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  26. else
  27. VERSION ?= master
  28. endif
  29. GITEA_VERSION := $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  30. endif
  31. LDFLAGS := -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  32. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list ./... | grep -v /vendor/)))
  33. SOURCES ?= $(shell find . -name "*.go" -type f)
  34. TAGS ?=
  35. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
  36. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  37. SWAGGER_SPEC_S_TMPL := s|"basePath":\s*"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
  38. SWAGGER_SPEC_S_JSON := s|"basePath":\s*"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
  39. TEST_MYSQL_HOST ?= mysql:3306
  40. TEST_MYSQL_DBNAME ?= testgitea
  41. TEST_MYSQL_USERNAME ?= root
  42. TEST_MYSQL_PASSWORD ?=
  43. TEST_PGSQL_HOST ?= pgsql:5432
  44. TEST_PGSQL_DBNAME ?= testgitea
  45. TEST_PGSQL_USERNAME ?= postgres
  46. TEST_PGSQL_PASSWORD ?= postgres
  47. TEST_MSSQL_HOST ?= mssql:1433
  48. TEST_MSSQL_DBNAME ?= gitea
  49. TEST_MSSQL_USERNAME ?= sa
  50. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  51. ifeq ($(OS), Windows_NT)
  52. EXECUTABLE := gitea.exe
  53. else
  54. EXECUTABLE := gitea
  55. endif
  56. # $(call strip-suffix,filename)
  57. strip-suffix = $(firstword $(subst ., ,$(1)))
  58. .PHONY: all
  59. all: build
  60. include docker/Makefile
  61. .PHONY: clean
  62. clean:
  63. $(GO) clean -i ./...
  64. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) \
  65. integrations*.test \
  66. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-sqlite/ integrations/gitea-integration-mssql/ \
  67. integrations/indexers-mysql/ integrations/indexers-pgsql integrations/indexers-sqlite integrations/indexers-mssql \
  68. integrations/mysql.ini integrations/pgsql.ini integrations/mssql.ini
  69. .PHONY: fmt
  70. fmt:
  71. $(GOFMT) -w $(GOFILES)
  72. .PHONY: vet
  73. vet:
  74. $(GO) vet $(PACKAGES)
  75. .PHONY: generate
  76. generate:
  77. @hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  78. $(GO) get -u github.com/jteeuwen/go-bindata/go-bindata; \
  79. fi
  80. $(GO) generate $(PACKAGES)
  81. .PHONY: generate-swagger
  82. generate-swagger:
  83. @hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  84. $(GO) get -u github.com/go-swagger/go-swagger/cmd/swagger; \
  85. fi
  86. swagger generate spec -o './$(SWAGGER_SPEC)'
  87. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  88. .PHONY: swagger-check
  89. swagger-check: generate-swagger
  90. @diff=$$(git diff '$(SWAGGER_SPEC)'); \
  91. if [ -n "$$diff" ]; then \
  92. echo "Please run 'make generate-swagger' and commit the result:"; \
  93. echo "$${diff}"; \
  94. exit 1; \
  95. fi;
  96. .PHONY: swagger-validate
  97. swagger-validate:
  98. @hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  99. $(GO) get -u github.com/go-swagger/go-swagger/cmd/swagger; \
  100. fi
  101. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  102. swagger validate './$(SWAGGER_SPEC)'
  103. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  104. .PHONY: errcheck
  105. errcheck:
  106. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  107. $(GO) get -u github.com/kisielk/errcheck; \
  108. fi
  109. errcheck $(PACKAGES)
  110. .PHONY: lint
  111. lint:
  112. @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  113. $(GO) get -u github.com/mgechev/revive; \
  114. fi
  115. revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
  116. .PHONY: misspell-check
  117. misspell-check:
  118. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  119. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  120. fi
  121. misspell -error -i unknwon $(GOFILES)
  122. .PHONY: misspell
  123. misspell:
  124. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  125. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  126. fi
  127. misspell -w -i unknwon $(GOFILES)
  128. .PHONY: fmt-check
  129. fmt-check:
  130. # get all go files and run go fmt on them
  131. @diff=$$($(GOFMT) -d $(GOFILES)); \
  132. if [ -n "$$diff" ]; then \
  133. echo "Please run 'make fmt' and commit the result:"; \
  134. echo "$${diff}"; \
  135. exit 1; \
  136. fi;
  137. .PHONY: test
  138. test:
  139. $(GO) test -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
  140. .PHONY: coverage
  141. coverage:
  142. @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  143. $(GO) get -u github.com/wadey/gocovmerge; \
  144. fi
  145. gocovmerge integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all;\
  146. .PHONY: unit-test-coverage
  147. unit-test-coverage:
  148. $(GO) test -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  149. .PHONY: vendor
  150. vendor:
  151. @hash dep > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  152. $(GO) get -u github.com/golang/dep/cmd/dep; \
  153. fi
  154. dep ensure -vendor-only
  155. .PHONY: test-vendor
  156. test-vendor: vendor
  157. @diff=$$(git diff vendor/); \
  158. if [ -n "$$diff" ]; then \
  159. echo "Please run 'make vendor' and commit the result:"; \
  160. echo "$${diff}"; \
  161. exit 1; \
  162. fi;
  163. #TODO add dep status -missing when implemented
  164. .PHONY: test-sqlite
  165. test-sqlite: integrations.sqlite.test
  166. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  167. .PHONY: test-sqlite-migration
  168. test-sqlite-migration: migrations.sqlite.test
  169. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  170. generate-ini:
  171. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  172. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  173. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  174. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  175. integrations/mysql.ini.tmpl > integrations/mysql.ini
  176. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  177. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  178. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  179. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  180. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  181. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  182. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  183. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  184. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  185. integrations/mssql.ini.tmpl > integrations/mssql.ini
  186. .PHONY: test-mysql
  187. test-mysql: integrations.test generate-ini
  188. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test
  189. .PHONY: test-mysql-migration
  190. test-mysql-migration: migrations.test generate-ini
  191. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.test
  192. .PHONY: test-pgsql
  193. test-pgsql: integrations.test generate-ini
  194. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
  195. .PHONY: test-pgsql-migration
  196. test-pgsql-migration: migrations.test generate-ini
  197. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.test
  198. .PHONY: test-mssql
  199. test-mssql: integrations.test generate-ini
  200. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.test
  201. .PHONY: test-mssql-migration
  202. test-mssql-migration: migrations.test generate-ini
  203. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.test
  204. .PHONY: bench-sqlite
  205. bench-sqlite: integrations.sqlite.test
  206. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  207. .PHONY: bench-mysql
  208. bench-mysql: integrations.test generate-ini
  209. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  210. .PHONY: bench-mssql
  211. bench-mssql: integrations.test generate-ini
  212. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  213. .PHONY: bench-pgsql
  214. bench-pgsql: integrations.test generate-ini
  215. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  216. .PHONY: integration-test-coverage
  217. integration-test-coverage: integrations.cover.test generate-ini
  218. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  219. integrations.test: $(SOURCES)
  220. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.test
  221. integrations.sqlite.test: $(SOURCES)
  222. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  223. integrations.cover.test: $(SOURCES)
  224. $(GO) test -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  225. .PHONY: migrations.test
  226. migrations.test: $(SOURCES)
  227. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.test
  228. .PHONY: migrations.sqlite.test
  229. migrations.sqlite.test: $(SOURCES)
  230. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  231. .PHONY: check
  232. check: test
  233. .PHONY: install
  234. install: $(wildcard *.go)
  235. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  236. .PHONY: build
  237. build: $(EXECUTABLE)
  238. $(EXECUTABLE): $(SOURCES)
  239. $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  240. .PHONY: release
  241. release: release-dirs release-windows release-linux release-darwin release-copy release-compress release-check
  242. .PHONY: release-dirs
  243. release-dirs:
  244. mkdir -p $(DIST)/binaries $(DIST)/release
  245. .PHONY: release-windows
  246. release-windows:
  247. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  248. $(GO) get -u github.com/karalabe/xgo; \
  249. fi
  250. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  251. ifeq ($(CI),drone)
  252. mv /build/* $(DIST)/binaries
  253. endif
  254. .PHONY: release-linux
  255. release-linux:
  256. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  257. $(GO) get -u github.com/karalabe/xgo; \
  258. fi
  259. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  260. ifeq ($(CI),drone)
  261. mv /build/* $(DIST)/binaries
  262. endif
  263. .PHONY: release-darwin
  264. release-darwin:
  265. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  266. $(GO) get -u github.com/karalabe/xgo; \
  267. fi
  268. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  269. ifeq ($(CI),drone)
  270. mv /build/* $(DIST)/binaries
  271. endif
  272. .PHONY: release-copy
  273. release-copy:
  274. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  275. .PHONY: release-check
  276. release-check:
  277. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  278. .PHONY: release-compress
  279. release-compress:
  280. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  281. $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  282. fi
  283. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),gxz -k -9 $(notdir $(file));)
  284. .PHONY: javascripts
  285. javascripts: public/js/index.js
  286. .IGNORE: public/js/index.js
  287. public/js/index.js: $(JAVASCRIPTS)
  288. cat $< >| $@
  289. .PHONY: stylesheets-check
  290. stylesheets-check: generate-stylesheets
  291. @diff=$$(git diff public/css/*); \
  292. if [ -n "$$diff" ]; then \
  293. echo "Please run 'make generate-stylesheets' and commit the result:"; \
  294. echo "$${diff}"; \
  295. exit 1; \
  296. fi;
  297. .PHONY: generate-stylesheets
  298. generate-stylesheets:
  299. @hash npx > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  300. echo "Please install npm version 5.2+"; \
  301. exit 1; \
  302. fi;
  303. $(eval BROWSERS := "> 1%, last 2 firefox versions, last 2 safari versions, ie 11")
  304. npx lessc --clean-css public/less/index.less public/css/index.css
  305. $(foreach file, $(filter-out public/less/themes/_base.less, $(wildcard public/less/themes/*)),npx lessc --clean-css public/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)
  306. $(foreach file, $(wildcard public/css/*),npx postcss --use autoprefixer --autoprefixer.browsers $(BROWSERS) -o $(file) $(file);)
  307. .PHONY: swagger-ui
  308. swagger-ui:
  309. rm -Rf public/vendor/assets/swagger-ui
  310. git clone --depth=10 -b v3.13.4 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
  311. mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
  312. rm -Rf $(TMPDIR)/swagger-ui
  313. $(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../../swagger.v1.json;g" public/vendor/assets/swagger-ui/index.html
  314. .PHONY: update-translations
  315. update-translations:
  316. mkdir -p ./translations
  317. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  318. rm ./translations/gitea.zip
  319. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  320. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  321. mv ./translations/*.ini ./options/locale/
  322. rmdir ./translations
  323. .PHONY: generate-images
  324. generate-images:
  325. mkdir -p $(TMPDIR)/images
  326. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  327. inkscape -f $(PWD)/assets/logo.svg -w 512 -h 512 -e $(PWD)/public/img/gitea-512.png
  328. inkscape -f $(PWD)/assets/logo.svg -w 192 -h 192 -e $(PWD)/public/img/gitea-192.png
  329. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  330. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  331. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  332. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  333. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  334. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  335. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  336. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  337. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  338. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  339. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  340. zopflipng $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  341. zopflipng $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  342. zopflipng $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  343. zopflipng $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  344. rm -f $(TMPDIR)/images/*-*.png
  345. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  346. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  347. $(PWD)/public/img/favicon.ico
  348. rm -rf $(TMPDIR)/images
  349. .PHONY: pr
  350. pr:
  351. $(GO) run contrib/pr/checkout.go $(PR)