A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
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.

619 lines
23 KiB

7 years ago
7 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
3 years ago
7 years ago
7 years ago
  1. DIST := dist
  2. DIST_DIRS := $(DIST)/binaries $(DIST)/release
  3. IMPORT := code.gitea.io/gitea
  4. export GO111MODULE=off
  5. GO ?= go
  6. SED_INPLACE := sed -i
  7. SHASUM ?= shasum -a 256
  8. HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
  9. COMMA := ,
  10. ifeq ($(HAS_GO), GO)
  11. GOPATH ?= $(shell $(GO) env GOPATH)
  12. export PATH := $(GOPATH)/bin:$(PATH)
  13. endif
  14. ifeq ($(OS), Windows_NT)
  15. EXECUTABLE ?= gitea.exe
  16. else
  17. EXECUTABLE ?= gitea
  18. UNAME_S := $(shell uname -s)
  19. ifeq ($(UNAME_S),Darwin)
  20. SED_INPLACE := sed -i ''
  21. endif
  22. ifeq ($(UNAME_S),FreeBSD)
  23. SED_INPLACE := sed -i ''
  24. endif
  25. endif
  26. GOFMT ?= gofmt -s
  27. GOFLAGS := -v
  28. EXTRA_GOFLAGS ?=
  29. MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
  30. MAKE_EVIDENCE_DIR := .make_evidence
  31. ifneq ($(RACE_ENABLED),)
  32. GOTESTFLAGS ?= -race
  33. endif
  34. STORED_VERSION_FILE := VERSION
  35. ifneq ($(DRONE_TAG),)
  36. VERSION ?= $(subst v,,$(DRONE_TAG))
  37. GITEA_VERSION ?= $(VERSION)
  38. else
  39. ifneq ($(DRONE_BRANCH),)
  40. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  41. else
  42. VERSION ?= master
  43. endif
  44. STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
  45. ifneq ($(STORED_VERSION),)
  46. GITEA_VERSION ?= $(STORED_VERSION)
  47. else
  48. GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  49. endif
  50. endif
  51. LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  52. 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/)))
  53. WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f)
  54. WEBPACK_CONFIGS := webpack.config.js .eslintrc .stylelintrc
  55. WEBPACK_DEST := public/js/index.js public/css/index.css
  56. WEBPACK_DEST_DIRS := public/js public/css
  57. BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
  58. BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
  59. TAGS ?=
  60. TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
  61. TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
  62. GO_DIRS := cmd integrations models modules routers scripts services vendor
  63. GO_SOURCES := $(wildcard *.go)
  64. 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)
  65. ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
  66. GO_SOURCES += $(BINDATA_DEST)
  67. endif
  68. GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
  69. FOMANTIC_CONFIGS := semantic.json web_src/fomantic/theme.config.less web_src/fomantic/_site/globals/site.variables
  70. FOMANTIC_DEST := public/fomantic/semantic.min.js public/fomantic/semantic.min.css
  71. FOMANTIC_DEST_DIR := public/fomantic
  72. #To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
  73. SWAGGER := GO111MODULE=on $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
  74. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  75. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
  76. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
  77. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  78. TEST_MYSQL_HOST ?= mysql:3306
  79. TEST_MYSQL_DBNAME ?= testgitea
  80. TEST_MYSQL_USERNAME ?= root
  81. TEST_MYSQL_PASSWORD ?=
  82. TEST_MYSQL8_HOST ?= mysql8:3306
  83. TEST_MYSQL8_DBNAME ?= testgitea
  84. TEST_MYSQL8_USERNAME ?= root
  85. TEST_MYSQL8_PASSWORD ?=
  86. TEST_PGSQL_HOST ?= pgsql:5432
  87. TEST_PGSQL_DBNAME ?= testgitea
  88. TEST_PGSQL_USERNAME ?= postgres
  89. TEST_PGSQL_PASSWORD ?= postgres
  90. TEST_PGSQL_SCHEMA ?= gtestschema
  91. TEST_MSSQL_HOST ?= mssql:1433
  92. TEST_MSSQL_DBNAME ?= gitea
  93. TEST_MSSQL_USERNAME ?= sa
  94. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  95. .PHONY: all
  96. all: build
  97. include docker/Makefile
  98. .PHONY: help
  99. help:
  100. @echo "Make Routines:"
  101. @echo " - \"\" equivalent to \"build\""
  102. @echo " - build build everything"
  103. @echo " - frontend build frontend files"
  104. @echo " - backend build backend files"
  105. @echo " - clean delete backend and integration files"
  106. @echo " - clean-all delete backend, frontend and integration files"
  107. @echo " - webpack build webpack files"
  108. @echo " - fomantic build fomantic files"
  109. @echo " - generate run \"go generate\""
  110. @echo " - fmt format the Go code"
  111. @echo " - generate-swagger generate the swagger spec from code comments"
  112. @echo " - swagger-validate check if the swagger spec is valid"
  113. @echo " - revive run code linter revive"
  114. @echo " - misspell check if a word is written wrong"
  115. @echo " - vet examines Go source code and reports suspicious constructs"
  116. @echo " - test run unit test"
  117. @echo " - test-sqlite run integration test for sqlite"
  118. @echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
  119. .PHONY: go-check
  120. go-check:
  121. $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?[[:space:]]' | tr '.' ' ');))
  122. @if [ "$(GO_VERSION)" -lt "001011000" ]; then \
  123. echo "Gitea requires Go 1.11 or greater to build. You can get it at https://golang.org/dl/"; \
  124. exit 1; \
  125. fi
  126. .PHONY: git-check
  127. git-check:
  128. @if git lfs >/dev/null 2>&1 ; then : ; else \
  129. echo "Gitea requires git with lfs support to run tests." ; \
  130. exit 1; \
  131. fi
  132. .PHONY: node-check
  133. node-check:
  134. $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?' | tr '.' ' ');))
  135. $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
  136. @if [ "$(NODE_VERSION)" -lt "010000000" -o "$(NPM_MISSING)" = "1" ]; then \
  137. echo "Gitea requires Node.js 10 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
  138. exit 1; \
  139. fi
  140. .PHONY: clean-all
  141. clean-all: clean
  142. rm -rf $(WEBPACK_DEST_DIRS) $(FOMANTIC_DEST_DIR)
  143. .PHONY: clean
  144. clean:
  145. $(GO) clean -i ./...
  146. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
  147. integrations*.test \
  148. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
  149. integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
  150. integrations/indexers-mssql integrations/mysql.ini integrations/mysql8.ini integrations/pgsql.ini integrations/mssql.ini
  151. .PHONY: fmt
  152. fmt:
  153. $(GOFMT) -w $(GO_SOURCES_OWN)
  154. .PHONY: vet
  155. vet:
  156. $(GO) vet $(PACKAGES)
  157. .PHONY: $(TAGS_EVIDENCE)
  158. $(TAGS_EVIDENCE):
  159. @mkdir -p $(MAKE_EVIDENCE_DIR)
  160. @echo "$(TAGS)" > $(TAGS_EVIDENCE)
  161. ifneq "$(TAGS)" "$(shell cat $(TAGS_EVIDENCE) 2>/dev/null)"
  162. TAGS_PREREQ := $(TAGS_EVIDENCE)
  163. endif
  164. .PHONY: generate-swagger
  165. generate-swagger:
  166. $(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
  167. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  168. $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
  169. .PHONY: swagger-check
  170. swagger-check: generate-swagger
  171. @diff=$$(git diff '$(SWAGGER_SPEC)'); \
  172. if [ -n "$$diff" ]; then \
  173. echo "Please run 'make generate-swagger' and commit the result:"; \
  174. echo "$${diff}"; \
  175. exit 1; \
  176. fi;
  177. .PHONY: swagger-validate
  178. swagger-validate:
  179. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  180. $(SWAGGER) validate './$(SWAGGER_SPEC)'
  181. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  182. .PHONY: errcheck
  183. errcheck:
  184. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  185. $(GO) get -u github.com/kisielk/errcheck; \
  186. fi
  187. errcheck $(PACKAGES)
  188. .PHONY: revive
  189. revive:
  190. @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  191. $(GO) get -u github.com/mgechev/revive; \
  192. fi
  193. revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
  194. .PHONY: misspell-check
  195. misspell-check:
  196. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  197. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  198. fi
  199. misspell -error -i unknwon,destory $(GO_SOURCES_OWN)
  200. .PHONY: misspell
  201. misspell:
  202. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  203. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  204. fi
  205. misspell -w -i unknwon $(GO_SOURCES_OWN)
  206. .PHONY: fmt-check
  207. fmt-check:
  208. # get all go files and run go fmt on them
  209. @diff=$$($(GOFMT) -d $(GO_SOURCES_OWN)); \
  210. if [ -n "$$diff" ]; then \
  211. echo "Please run 'make fmt' and commit the result:"; \
  212. echo "$${diff}"; \
  213. exit 1; \
  214. fi;
  215. .PHONY: test
  216. test:
  217. GO111MODULE=on $(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
  218. .PHONY: test-check
  219. test-check:
  220. @echo "Checking if tests have changed the source tree...";
  221. @diff=$$(git status -s); \
  222. if [ -n "$$diff" ]; then \
  223. echo "make test has changed files in the source tree:"; \
  224. echo "$${diff}"; \
  225. echo "You should change the tests to create these files in a temporary directory."; \
  226. echo "Do not simply add these files to .gitignore"; \
  227. exit 1; \
  228. fi;
  229. .PHONY: test\#%
  230. test\#%:
  231. GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -run $* $(PACKAGES)
  232. .PHONY: coverage
  233. coverage:
  234. @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  235. $(GO) get -u github.com/wadey/gocovmerge; \
  236. fi
  237. gocovmerge integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all;\
  238. .PHONY: unit-test-coverage
  239. unit-test-coverage:
  240. GO111MODULE=on $(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  241. .PHONY: vendor
  242. vendor:
  243. GO111MODULE=on $(GO) mod tidy && GO111MODULE=on $(GO) mod vendor
  244. .PHONY: test-vendor
  245. test-vendor: vendor
  246. @diff=$$(git diff vendor/); \
  247. if [ -n "$$diff" ]; then \
  248. echo "Please run 'make vendor' and commit the result:"; \
  249. echo "$${diff}"; \
  250. exit 1; \
  251. fi;
  252. .PHONY: test-sqlite
  253. test-sqlite: integrations.sqlite.test
  254. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  255. .PHONY: test-sqlite\#%
  256. test-sqlite\#%: integrations.sqlite.test
  257. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $*
  258. .PHONY: test-sqlite-migration
  259. test-sqlite-migration: migrations.sqlite.test
  260. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  261. generate-ini-mysql:
  262. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  263. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  264. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  265. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  266. integrations/mysql.ini.tmpl > integrations/mysql.ini
  267. .PHONY: test-mysql
  268. test-mysql: integrations.mysql.test generate-ini-mysql
  269. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  270. .PHONY: test-mysql\#%
  271. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  272. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.run $*
  273. .PHONY: test-mysql-migration
  274. test-mysql-migration: migrations.mysql.test generate-ini-mysql
  275. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.mysql.test
  276. generate-ini-mysql8:
  277. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  278. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  279. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  280. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  281. integrations/mysql8.ini.tmpl > integrations/mysql8.ini
  282. .PHONY: test-mysql8
  283. test-mysql8: integrations.mysql8.test generate-ini-mysql8
  284. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test
  285. .PHONY: test-mysql8\#%
  286. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  287. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test -test.run $*
  288. .PHONY: test-mysql8-migration
  289. test-mysql8-migration: migrations.mysql8.test generate-ini-mysql8
  290. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./migrations.mysql8.test
  291. generate-ini-pgsql:
  292. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  293. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  294. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  295. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  296. -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
  297. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  298. .PHONY: test-pgsql
  299. test-pgsql: integrations.pgsql.test generate-ini-pgsql
  300. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
  301. .PHONY: test-pgsql\#%
  302. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  303. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.run $*
  304. .PHONY: test-pgsql-migration
  305. test-pgsql-migration: migrations.pgsql.test generate-ini-pgsql
  306. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.pgsql.test
  307. generate-ini-mssql:
  308. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  309. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  310. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  311. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  312. integrations/mssql.ini.tmpl > integrations/mssql.ini
  313. .PHONY: test-mssql
  314. test-mssql: integrations.mssql.test generate-ini-mssql
  315. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test
  316. .PHONY: test-mssql\#%
  317. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  318. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.run $*
  319. .PHONY: test-mssql-migration
  320. test-mssql-migration: migrations.mssql.test generate-ini-mssql
  321. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test
  322. .PHONY: bench-sqlite
  323. bench-sqlite: integrations.sqlite.test
  324. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  325. .PHONY: bench-mysql
  326. bench-mysql: integrations.mysql.test generate-ini-mysql
  327. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  328. .PHONY: bench-mssql
  329. bench-mssql: integrations.mssql.test generate-ini-mssql
  330. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  331. .PHONY: bench-pgsql
  332. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  333. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  334. .PHONY: integration-test-coverage
  335. integration-test-coverage: integrations.cover.test generate-ini-mysql
  336. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  337. integrations.mysql.test: git-check $(GO_SOURCES)
  338. GO111MODULE=on $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  339. integrations.mysql8.test: git-check $(GO_SOURCES)
  340. GO111MODULE=on $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
  341. integrations.pgsql.test: git-check $(GO_SOURCES)
  342. GO111MODULE=on $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  343. integrations.mssql.test: git-check $(GO_SOURCES)
  344. GO111MODULE=on $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
  345. integrations.sqlite.test: git-check $(GO_SOURCES)
  346. GO111MODULE=on $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  347. integrations.cover.test: git-check $(GO_SOURCES)
  348. GO111MODULE=on $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  349. .PHONY: migrations.mysql.test
  350. migrations.mysql.test: $(GO_SOURCES)
  351. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
  352. .PHONY: migrations.mysql8.test
  353. migrations.mysql8.test: $(GO_SOURCES)
  354. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
  355. .PHONY: migrations.pgsql.test
  356. migrations.pgsql.test: $(GO_SOURCES)
  357. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
  358. .PHONY: migrations.mssql.test
  359. migrations.mssql.test: $(GO_SOURCES)
  360. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
  361. .PHONY: migrations.sqlite.test
  362. migrations.sqlite.test: $(GO_SOURCES)
  363. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  364. .PHONY: check
  365. check: test
  366. .PHONY: install $(TAGS_PREREQ)
  367. install: $(wildcard *.go)
  368. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  369. .PHONY: build
  370. build: frontend backend
  371. .PHONY: frontend
  372. frontend: node-check $(FOMANTIC_DEST) $(WEBPACK_DEST)
  373. .PHONY: backend
  374. backend: go-check generate $(EXECUTABLE)
  375. .PHONY: generate
  376. generate: $(TAGS_PREREQ)
  377. GO111MODULE=on $(GO) generate -mod=vendor -tags '$(TAGS)' $(PACKAGES)
  378. $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
  379. GO111MODULE=on $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  380. .PHONY: release
  381. release: frontend generate release-windows release-linux release-darwin release-copy release-compress release-sources release-check
  382. $(DIST_DIRS):
  383. mkdir -p $(DIST_DIRS)
  384. .PHONY: release-windows
  385. release-windows: | $(DIST_DIRS)
  386. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  387. $(GO) get -u src.techknowlogick.com/xgo; \
  388. fi
  389. xgo -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  390. ifeq ($(CI),drone)
  391. cp /build/* $(DIST)/binaries
  392. endif
  393. .PHONY: release-linux
  394. release-linux: | $(DIST_DIRS)
  395. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  396. $(GO) get -u src.techknowlogick.com/xgo; \
  397. fi
  398. 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) .
  399. ifeq ($(CI),drone)
  400. cp /build/* $(DIST)/binaries
  401. endif
  402. .PHONY: release-darwin
  403. release-darwin: | $(DIST_DIRS)
  404. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  405. $(GO) get -u src.techknowlogick.com/xgo; \
  406. fi
  407. xgo -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  408. ifeq ($(CI),drone)
  409. cp /build/* $(DIST)/binaries
  410. endif
  411. .PHONY: release-copy
  412. release-copy: | $(DIST_DIRS)
  413. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  414. .PHONY: release-check
  415. release-check: | $(DIST_DIRS)
  416. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  417. .PHONY: release-compress
  418. release-compress: | $(DIST_DIRS)
  419. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  420. $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  421. fi
  422. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  423. .PHONY: release-sources
  424. release-sources: | $(DIST_DIRS) node_modules
  425. echo $(VERSION) > $(STORED_VERSION_FILE)
  426. tar --exclude=./$(DIST) --exclude=./.git --exclude=./$(MAKE_EVIDENCE_DIR) --exclude=./node_modules/.cache -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
  427. rm -f $(STORED_VERSION_FILE)
  428. node_modules: package-lock.json
  429. npm install --no-save
  430. @touch node_modules
  431. .PHONY: npm-update
  432. npm-update: node-check | node_modules
  433. npx updates -cu
  434. rm -rf node_modules package-lock.json
  435. npm install --package-lock
  436. .PHONY: js
  437. js:
  438. @echo "'make js' is deprecated, please use 'make webpack'"
  439. $(MAKE) webpack
  440. .PHONY: css
  441. css:
  442. @echo "'make css' is deprecated, please use 'make webpack'"
  443. $(MAKE) webpack
  444. .PHONY: fomantic
  445. fomantic: $(FOMANTIC_DEST)
  446. $(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) package-lock.json | node_modules
  447. rm -rf $(FOMANTIC_DEST_DIR)
  448. cp web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
  449. cp web_src/fomantic/_site/globals/* node_modules/fomantic-ui/src/_site/globals/
  450. npx gulp -f node_modules/fomantic-ui/gulpfile.js build
  451. @touch $(FOMANTIC_DEST)
  452. .PHONY: webpack
  453. webpack: $(WEBPACK_DEST)
  454. $(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json | node_modules
  455. npx eslint web_src/js webpack.config.js
  456. npx stylelint web_src/less
  457. npx webpack --hide-modules --display-entrypoints=false
  458. @touch $(WEBPACK_DEST)
  459. .PHONY: update-translations
  460. update-translations:
  461. mkdir -p ./translations
  462. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  463. rm ./translations/gitea.zip
  464. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  465. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  466. mv ./translations/*.ini ./options/locale/
  467. rmdir ./translations
  468. .PHONY: generate-images
  469. generate-images:
  470. $(eval TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp'))
  471. mkdir -p $(TMPDIR)/images
  472. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  473. inkscape -f $(PWD)/assets/logo.svg -w 512 -h 512 -e $(PWD)/public/img/gitea-512.png
  474. inkscape -f $(PWD)/assets/logo.svg -w 192 -h 192 -e $(PWD)/public/img/gitea-192.png
  475. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  476. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  477. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  478. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  479. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  480. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  481. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  482. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  483. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  484. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  485. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  486. zopflipng -m -y $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  487. zopflipng -m -y $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  488. zopflipng -m -y $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  489. zopflipng -m -y $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  490. rm -f $(TMPDIR)/images/*-*.png
  491. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  492. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  493. $(PWD)/public/img/favicon.ico
  494. convert -flatten $(PWD)/public/img/favicon.png $(PWD)/public/img/apple-touch-icon.png
  495. rm -rf $(TMPDIR)/images
  496. $(foreach file, $(shell find public/img -type f -name '*.png' ! -name 'loading.png'),zopflipng -m -y $(file) $(file);)
  497. .PHONY: pr\#%
  498. pr\#%: clean-all
  499. $(GO) run contrib/pr/checkout.go $*
  500. .PHONY: golangci-lint
  501. golangci-lint:
  502. @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  503. export BINARY="golangci-lint"; \
  504. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.20.0; \
  505. fi
  506. golangci-lint run --timeout 5m