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.

629 lines
23 KiB

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